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? :)

CommentFileSizeAuthor
#1 entity_view_node.patch587 bytesfago
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fago’s picture

Status: Needs work » Needs review
FileSize
587 bytes

Why 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.

Status: Needs review » Needs work

The last submitted patch, entity_view_node.patch, failed testing.

das-peter’s picture

Well 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().

fago’s picture

Status: Needs work » Needs review

#1: entity_view_node.patch queued for re-testing.

fago’s picture

Might 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.

Damien Tournoud’s picture

#1 looks good to me. Consistency is indeed paramount here.

fago’s picture

Status: Needs review » Fixed

Committed.

Status: Fixed » Closed (fixed)

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