1 entity.module | entity_get_info($entity_type = NULL) |
Gets the entity info array of an entity type.
Parameters
$entity_type: The entity type, e.g. node, for which the info shall be returned, or NULL to return an array with info about all types.
See also
File
- core/
modules/ entity/ entity.module, line 316 - Entity API for handling entities like nodes or users.
Code
function entity_get_info($entity_type = NULL) {
global $language;
// Use the advanced backdrop_static() pattern, since this is called very often.
static $backdrop_static_fast;
if (!isset($backdrop_static_fast)) {
$backdrop_static_fast['entity_info'] = &backdrop_static(__FUNCTION__);
}
$entity_info = &$backdrop_static_fast['entity_info'];
// hook_entity_info() includes translated strings, so each language is cached
// separately.
$langcode = $language->langcode;
if (empty($entity_info)) {
if ($cache = cache()->get("entity_info:$langcode")) {
$entity_info = $cache->data;
}
else {
$entity_info = module_invoke_all('entity_info');
// Merge in default values.
foreach ($entity_info as $name => $data) {
$entity_info[$name] += array(
'fieldable' => FALSE,
'controller class' => 'DefaultEntityController',
'static cache' => TRUE,
'field cache' => TRUE,
'load hook' => $name . '_load',
'bundles' => array(),
'view modes' => array(),
'token type' => $name,
'entity keys' => array(),
'translation' => array(),
);
$entity_info[$name]['entity keys'] += array(
'revision' => '',
'bundle' => '',
);
// If no bundle key is provided, assume a single bundle, named after
// the entity type.
if (empty($entity_info[$name]['entity keys']['bundle']) && empty($entity_info[$name]['bundles'])) {
$entity_info[$name]['bundles'] = array($name => array('label' => $entity_info[$name]['label']));
}
// Prepare entity schema fields SQL info for
// EntityControllerInterface::buildQuery().
if (isset($entity_info[$name]['base table'])) {
$entity_info[$name]['schema_fields_sql']['base table'] = backdrop_schema_fields_sql($entity_info[$name]['base table']);
if (isset($entity_info[$name]['revision table'])) {
$entity_info[$name]['schema_fields_sql']['revision table'] = backdrop_schema_fields_sql($entity_info[$name]['revision table']);
}
}
$view_mode_info = module_invoke_all('entity_view_mode_info');
backdrop_alter('entity_view_mode_info', $view_mode_info);
// Add in the variable entity display modes which override the
// hook-provided display modes.
$config = config_get('entity.view_modes', 'view_modes');
if ($config) {
$view_mode_info = backdrop_array_merge_deep($view_mode_info, $config);
}
// Add in the combined custom entity display modes which override the
// existing display modes in the entity information.
foreach ($view_mode_info as $type => $view_modes) {
if (isset($entity_info[$type])) {
if (!isset($entity_info[$type]['view modes'])) {
$entity_info[$type]['view modes'] = array();
}
$entity_info[$type]['view modes'] = $entity_info[$type]['view modes'] + $view_modes;
}
}
// Add a token view mode if it does not already exist. Only work with
// fieldable entities.
if (!empty($entity_info[$name]['fieldable'])) {
if (!isset($entity_info[$name]['view modes']['token'])) {
$entity_info[$name]['view modes']['token'] = array(
'label' => t('Tokens'),
'custom settings' => FALSE,
);
}
}
foreach ($entity_info[$name]['view modes'] as $view_mode => $view_mode_info) {
$entity_info[$name]['view modes'][$view_mode] += array(
'custom settings' => FALSE,
);
}
}
// Let other modules alter the entity info.
backdrop_alter('entity_info', $entity_info);
cache()->set("entity_info:$langcode", $entity_info);
}
}
if (empty($entity_type)) {
return $entity_info;
}
elseif (isset($entity_info[$entity_type])) {
return $entity_info[$entity_type];
}
}