As of the git log there were already modifications to reach this goal: http://drupalcode.org/project/entity.git/commit/3165b2f
Unfortunately there's still at least one case where the returned array doesn't match the documentation. The case known to me happens when the call is handed over to entity_metadata_view_node()
and from there to node_view_multiple()
. The last function returns the array keyed by "nodes" instead "node".
For me it's very difficult to decide where this could/should be fixed.
I guess entity_metadata_view_node()
should be as compatible as possible with node_view_multiple()
- on the other hand fixing this in entity_view()
itself is far more complex because we've less control over with what kind of return we've to deal.
A change like the following in entity_view()
would be doable but looks to me like evil guessing:
if (isset($info['view callback'])) {
$entities = entity_key_array_by_property($entities, $info['entity keys']['id']);
$result = $info['view callback']($entities, $view_mode, $langcode, $entity_type);
return array($entity_type => reset($result));
Ideas, suggestions or even solutions? :)
Comment | File | Size | Author |
---|---|---|---|
#1 | entity_view_node.patch | 587 bytes | fago |
Comments
Comment #1
fagoWhy not just something like that?
I don't see a problem with changing the key as it doesn't run through an alter or so.
Comment #3
das-peter CreditAttribution: das-peter commentedWell if you say that's ok I'm absolutely fine with :)
I was simply worried that somewhat somewhere expects exactly the same output as returned by
node_view_multiple()
.Comment #4
fago#1: entity_view_node.patch queued for re-testing.
Comment #5
fagoMight be, still you can build your own-render array using single node-view calls and put it in whatever you want. Moreover, when using entity_view() one probably expects a consistently built render array, so I think it's fine.
Comment #6
Damien Tournoud CreditAttribution: Damien Tournoud commented#1 looks good to me. Consistency is indeed paramount here.
Comment #7
fagoCommitted.