function entity_example_basic_list_entities in Examples for Developers 7
Returns a render array with all entity_example_basic entities.
In this basic example we know that there won't be many entities, so we'll just load them all for display. See pager_example.module to implement a pager. Most implementations would probably do this with the contrib Entity API module, or a view using views module, but we avoid using non-core features in the Examples project.
See also
Related topics
1 call to entity_example_basic_list_entities()
- entity_example_info_page in entity_example/
entity_example.module - Basic information for the page.
1 string reference to 'entity_example_basic_list_entities'
- entity_example_menu in entity_example/
entity_example.module - Implements hook_menu().
File
- entity_example/
entity_example.module, line 266 - Implements the basic functionality required to create and display an entity.
Code
function entity_example_basic_list_entities() {
$content = array();
// Load all of our entities.
$entities = entity_example_basic_load_multiple();
if (!empty($entities)) {
foreach ($entities as $entity) {
// Create tabular rows for our entities.
$rows[] = array(
'data' => array(
'id' => $entity->basic_id,
'item_description' => l($entity->item_description, 'examples/entity_example/basic/' . $entity->basic_id),
'bundle' => $entity->bundle_type,
),
);
}
// Put our entities into a themed table. See theme_table() for details.
$content['entity_table'] = array(
'#theme' => 'table',
'#rows' => $rows,
'#header' => array(
t('ID'),
t('Item Description'),
t('Bundle'),
),
);
}
else {
// There were no entities. Tell the user.
$content[] = array(
'#type' => 'item',
'#markup' => t('No entity_example_basic entities currently exist.'),
);
}
return $content;
}