Views Dependencies

I found an interesting "gotcha" the other day. I created a View with the Views module, exported it to code and was in the process of trying to make it appear on my website. Something it was resolutely refusing to do. I couldn't understand it. Clearly there was the View in my code. I'd cleared caches, run the update, uninstalled and reinstalled my module, even restarted Apache. Nothing!

Then I noticed this line:

<?php
  $view
->requires = array(node, node_data_field_media_embedded_video, image, node_data_field_mp3);
?>

When you create a View which uses fields, for example a Table or List View instead of Full Node or Teaser, then those fields become dependencies on your View working properly. In this instance, node_data_field_mp3 did not exist because on the website I hadn't imported the content type yet. I expected the View to work anyway, but it did not. It simply did nothing until all the dependent fields were available.

Post new Comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.