Currently printing files with a view using Rendered Entity (from Entity API) row style plugin fails with error:
Notice: Undefined index: ... in entity_views_plugin_row_entity_view->render() (line ... of ... /modules/entity/views/plugins/entity_views_plugin_row_entity_view.inc)
.
The reason is that file_view_multiple()
returns not what is expected by entity_views_plugin_row_entity_view->pre_render()
. It returns sorted files array without wrapping files into 'files' sub-array. I.e. expected result:
array(
'files' => array(
1 => array( file_view data ),
2 => array( file_view data ),
... => array( file_view data ),
),
'#sorted' => TRUE)
Current behavior:
array(
1 => array( file_view data ),
2 => array( file_view data ),
... => array( file_view data ),
'#sorted' => TRUE)
As the result, entity_views_plugin_row_entity_view->pre_render()
after executing code:
$render = entity_view($this->entity_type, $this->entities, $this->options['view_mode']);
$this->rendered_content = reset($render);
assigns rendered_content
the value of the first file, stripping entity_id, and the subsequent call to entity_views_plugin_row_entity_view->render()
is unable to render an entity as it tries to get entity_view data by id (which is now missed):
$render = $this->rendered_content[entity_id($this->entity_type, $entity)];
Why I think this is file_view_multiple()
problem? Because the equivalent function from node.module called node_view_multiple()
also wraps node entities into 'nodes' sub-array:
http://drupalcode.org/project/drupal.git/blob/3a24da1b40f5e05876ad777504...
Comment | File | Size | Author |
---|---|---|---|
#5 | file_entity-1954186-5.patch | 1.61 KB | OnkelTem |
#1 | file_entity-1954186-1.patch | 1.61 KB | OnkelTem |
Comments
Comment #1
OnkelTem CreditAttribution: OnkelTem commentedProviding the patch.
Comment #2
Dave ReidI'm a little torn about changing this API. On the one hand, yes that seems the proper thing. But also core is inconsistent. node_view_multiple() and taxonomy_term_view_multiple() use a first-level key, and the second level as the entity IDs. But comment_view_multiple() does what we're doing. How does entity API handle that comment_view_multiple() returns the unexpected syntax?
This change seems to be unrelated and not sure what its purpose is?
Comment #3
OnkelTem CreditAttribution: OnkelTem commentedSo it forces 'comment' injecting.
Thanks for finding this, it is definitely mistypo and should read as:
$files_built = reset(file_view_multiple($files_display, $view_mode));
which just strips that first-level key and allows to leave the rest of code untouched.
Comment #4
OnkelTem CreditAttribution: OnkelTem commentedActually, another approach to fix this — is to create Entity API wrapper like this:
and this was my first fix. But then I realized that Entity API should check for presence of 'file_entity' module which I didn't consider as good idea. Maybe I'm wrong...
p.s. In the above code "#sorted" gets under first-level 'file' key too. This is no good of course, it should be processed correctly.
Comment #5
OnkelTem CreditAttribution: OnkelTem commentedUpdated patch (with 'reset' changes from #3)
Comment #6
Cale Bierman CreditAttribution: Cale Bierman commentedI've used the updated patch from #5 and created a view using Rendered Entity row style that has a list of files and I've had no errors.
Comment #7
Cale Bierman CreditAttribution: Cale Bierman commentedComment #8
Dave ReidCommitted #5 to 7.x-2.x! Thanks Cale and OnkelTem! http://drupalcode.org/project/file_entity.git/commit/2bd1b4c
After reviewing the list of functions that call file_view_multiple(), I also made a small commit to the mediafield sub-module in Media as well: http://drupalcode.org/project/media.git/commit/e5d43ab