Perhaps I'm missing something but it looks like this example is missing an implementation of the custom view. In the example code I can see that this new custom view "type" is registered but I cannot see how the call to node_view($node, 'example_node_list'); utilizes this as I cannot find any implementation of hook_view in the code or anything else that uses it.

As part of the function node_example_page() the code comments indicate that the statements instruct node_view to use the custom "example_node_list" view... but there appears to nothing in the code that actally uses that view...

/ Loop through each of our node_example nodes and instruct node_view
// to use our custom "example_node_list" view.
// http://api.drupal.org/api/function/node_load/7
// http://api.drupal.org/api/function/node_view/7
foreach ($result as $row) {
$node = node_load($row->nid);
$build['node_list'][]= node_view($node, 'example_node_list');
}

I think the code is not complete and is missing and implementation of hook_view or hook_node_view that could actually use the new custom view. I am an experienced developer with some familiarity with D6 but new to D7... so I could be horribly wrong but I think at best this is confusing and leaves people ferreting around for something that isn't there!

Comments

indigoblue’s picture

Version: 6.x-dev » 7.0-alpha7
jhodgdon’s picture

Project: Drupal core » Examples for Developers
Version: 7.0-alpha7 »
Component: documentation » Node Example

Moving to correct project for review

rfay’s picture

Category: bug » support

It seems to me like this is handled in the .install file:

  // Add our example_node_list view mode to the body instance display by
  // instructing the body to display as a summary
  $body_instance['display']['example_node_list'] = array(
    'label' => 'hidden',
    'type' => 'text_summary_or_trimmed',
  );

Is that what you were looking for? If not, please continue the conversation. Best practices on these things are still being worked out.

indigoblue’s picture

Thanks @rfay that clears it up for me. I think it is one of the big changes in D7 that so much functionality is now often in the install file. I wonder whether the example might at least reference in a comment, the usage of the view in the install file from the code where it is created to assist others who are trying to follow the codes logic. This would have the additional benefit of directing them to the install file with it's interesting code bits.

ilo’s picture

Status: Active » Needs review
StatusFileSize
new1.14 KB

I've included a paragraph in the node_example.module about content type init location. Please, indigoblue, do you thing something like that would have helped you?

cliffp’s picture

@rfay, does #3 *define* the 'example_node_list'? Is that all there is to it, a label and a type? Is the type related to the formatter of the same name as defined in the field text module?

Is there any documentation of custom node views? I'm sure there is but I am struggling with the fields thing. It's a steep learning curve!

rfay’s picture

@cliffp, sorry - I'm no great expert on this. Like most people, I just use the example and run with it. You might check in IRC.

cliffp’s picture

@rfay, thanks anyway. The trouble with IRC is that when others are awake and online I'm in bed and asleep due to timezones! However, on your advice I might try it again.

mile23’s picture

StatusFileSize
new6.61 KB

The view mode defined in the module gets used in node_example_field_formatter_view(), to display the color fields differently.

The view mode gets passed to node_view() and subsequently hook_view(), hook_node_view(), and of course the field system as in hook_field_formatter_view(). So at any of these points your code can figure out what that view mode means and output the right stuff. This example could be better at illustrating that.

Also, the view mode doesn't exist in the .install file. It's just kinda there, when you call node_view(). I might be wrong, because everything else in the Drupalverse is defined in a cached array, but I can't find anywhere to define which nodes have which view modes. You can give an entity a list of view modes, so hook_entity_info_alter() might be helpful.

All that aside, however, here's a patch.

mile23’s picture

Status: Needs review » Needs work
mile23’s picture

Status: Needs work » Needs review
rfay’s picture

I apologize. I was testing on git-dev and accidentally messed with this live issue.

mile23’s picture

I figured it was something like that. :-)

cliffp’s picture

@Mile23, it's ages since I've done a patch! Nevertheless I patched my Drupal7 successfully (recent dev version, not sure of the date) and it looks good. Thanks.

dave reid’s picture

Version: » 7.x-1.x-dev
rfay’s picture

Do we have a consensus on this? If so, let's not waste our effort... get it done.

rfay’s picture

Things should never sit so long. Here's #9 git-ified, merged and rerolled for use with current code. I hope I did it right. It was a bit complicated. If you can confirm the intent, let's get it in soon.

Status: Needs review » Needs work

The last submitted patch, examples.node_example_documentation_932182_09_merged_to_17.patch, failed testing.

mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new4.66 KB

I couldn't get that patch to apply, so I did this...

rfay’s picture

Status: Needs review » Fixed

Committed
7.x-1.x: e852647
8.x-1.x: 2b6a2a6

Thanks so much!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.