I have a view that accepts a node id as argument and displays several fields of that node, one of them being a node reference. When displaying this view on a node page I get the following errors:
Notice: Undefined index: node in node_reference_field_formatter_view() (rule 490 of references/node_reference/node_reference.module).
EntityMalformedException in entity_extract_ids()
The node page display is handled by display suite. As soon as I remove the node reference field from being displayed with display suite the error occurs.
After debugging I found out that the following issue occurs:
- in views_handler_field_field field_view_field is called for all fields attached to the display
- the $entity object passed to field_view_field is the same $entity object used for rendering the node on the node page (via the static entity load cache)
- this $entity object already has the $entity->_field_view_prepared flag set to TRUE (node_view was already called). This means it won't call hook_field_formatter_prepare_view anymore when displaying fields of that particular entity
- any hook_field_formatter_view that is called (through field_view_field) has to rely on the data attached to the $entity object that was originally used for rendering the node for the node page.
- if the field is not displayed on the node page (by removing it from the view mode) and relies on data set in hook_field_formatter_prepare_view (like node references) an error will occur
You can replicate it using these steps:
- create a content type with a node reference field
- create a view accepting a node id as argument, using fields for display and showing the node reference field
- using display suite, add the view as a dynamic field to the node for its full view mode
- remove the node reference field from display for the full view mode
- create a node of this type with a populated node reference field
- go to the node page
This should result in a similar bug as above.
|PASSED: [[SimpleTest]]: [MySQL] 1,658 pass(es). |
[ View ]