function entity_test_entity_info in Entity API 7
Implements hook_entity_info().
File
- tests/
entity_test.module, line 11 - Test module for the entity API.
Code
function entity_test_entity_info() {
$return = array(
'entity_test' => array(
'label' => t('Test Entity'),
'plural label' => t('Test Entities'),
'description' => t('An entity type used by the entity API tests.'),
'entity class' => 'EntityClass',
'controller class' => 'EntityAPIController',
'base table' => 'entity_test',
'fieldable' => TRUE,
'entity keys' => array(
'id' => 'pid',
'bundle' => 'name',
),
// Make use the class' label() and uri() implementation by default.
'label callback' => 'entity_class_label',
'uri callback' => 'entity_class_uri',
'bundles' => array(),
'bundle keys' => array(
'bundle' => 'name',
),
'module' => 'entity_test',
),
'entity_test_type' => array(
'label' => t('Test entity type'),
'entity class' => 'Entity',
'controller class' => 'EntityAPIControllerExportable',
'base table' => 'entity_test_type',
'fieldable' => FALSE,
'bundle of' => 'entity_test',
'exportable' => TRUE,
'entity keys' => array(
'id' => 'id',
'name' => 'name',
),
'module' => 'entity_test',
),
'entity_test2' => array(
'label' => t('Test Entity (revision support)'),
'entity class' => 'EntityClassRevision',
'controller class' => 'EntityAPIController',
'base table' => 'entity_test2',
'revision table' => 'entity_test2_revision',
'fieldable' => TRUE,
'entity keys' => array(
'id' => 'pid',
'revision' => 'revision_id',
),
// Make use of the class label() and uri() implementation by default.
'label callback' => 'entity_class_label',
'uri callback' => 'entity_class_uri',
'bundles' => array(),
'bundle keys' => array(
'bundle' => 'name',
),
),
);
// Add bundle info but bypass entity_load() as we cannot use it here.
$types = db_select('entity_test_type', 'et')
->fields('et')
->execute()
->fetchAllAssoc('name');
foreach ($types as $name => $type) {
$return['entity_test']['bundles'][$name] = array(
'label' => $type->label,
);
}
// Support entity cache module.
if (module_exists('entitycache')) {
$return['entity_test']['field cache'] = FALSE;
$return['entity_test']['entity cache'] = TRUE;
}
return $return;
}