I am trying to write a module that displays several entities in one page, but I don't see how I should theme them.
I've found (an mostly followed) this: https://drupal.org/node/1238606.
But the point where I get stuck is the return value of the page callback. The link above suggests:
function my_entity_page_view($entity, $view_mode='full') {
$entity_type = $entity->entityType();
$entity_id = entity_id($entity_type, $entity);
$entity->content = array();
$entity->title = filter_xss($entity->title);
field_attach_prepare_view($entity_type, array($entity_id => $entity), $view_mode);
entity_prepare_view($entity_type, array($entity_id => $entity));
$entity->content += field_attach_view($entity_type, $entity, $view_mode);
$entity->content += array(
'#theme' => $entity_type,
'#element' => $entity,
'#view_mode' => $view_mode,
'#language' => LANGUAGE_NONE,
);
return $entity->content;
}
I however try to load several entities at once and have no fields, so I tried this:
$entities = // Array of entities keyed by id;
entity_prepare_view('entity_type', $entities);
$return = array(
'#theme' => 'entity_type',
'#element' => $entities,
'#view_mode' => 'full',
'#language' => LANGUAGE_NONE,
);
return $return;
Since entity_prepare_view()
accepts an array of entities, I'd suppose there should be a way to theme several entities at once as well. Or am I wrong?