function units_entity_info in Units of Measurement 7.2
Same name and namespace in other branches
- 7 units.module \units_entity_info()
Implements hook_entity_info().
File
- ./
units.module, line 37 - Provide API for managing and converting units of measurement.
Code
function units_entity_info() {
$entity_info = array();
$entity_info['units_unit'] = array(
'label' => t('Unit measurement'),
'entity class' => 'UnitsEntity',
'controller class' => 'EntityAPIControllerExportable',
'base table' => 'units_unit',
'fieldable' => TRUE,
'exportable' => TRUE,
'entity keys' => array(
'id' => 'umid',
'bundle' => 'measure',
'label' => 'label',
'name' => 'machine_name',
),
'bundles' => array(),
'bundle keys' => array(
'bundle' => 'measure',
),
'module' => 'units',
'access callback' => 'units_entity_access',
);
// We can't use here entity_load functions, nor EntityFieldQuery because
// entity info is not exposed to core yet.
$measures = db_select('units_measure', 'u_m')
->fields('u_m', array(
'measure',
'label',
))
->execute()
->fetchAllAssoc('measure');
foreach ($measures as $measure) {
$entity_info['units_unit']['bundles'][$measure->measure] = array(
'label' => $measure->label,
);
}
$entity_info['units_measure'] = array(
'label' => t('Measure'),
'entity class' => 'Entity',
'controller class' => 'EntityAPIControllerExportable',
'base table' => 'units_measure',
'fieldable' => FALSE,
'exportable' => TRUE,
'bundle of' => 'units_unit',
'entity keys' => array(
'id' => 'mid',
'label' => 'label',
'name' => 'measure',
),
'module' => 'units',
'access callback' => 'units_entity_access',
);
return $entity_info;
}