Manages entity type plugin definitions.
Each entity type definition array is set in the entity type plugin's annotation and altered by hook_entity_info_alter(). The definition includes the following keys:
The defaults for the plugin definition are provided in \Drupal\Core\Entity\EntityManager::defaults.
Expanded class hierarchy of EntityManager
class EntityManager extends PluginManagerBase {
/**
* The cache bin used for entity plugin definitions.
*
* @var string
*/
protected $cacheBin = 'cache';
/**
* The cache key used for entity plugin definitions.
*
* @var string
*/
protected $cacheKey = 'entity_info';
/**
* The cache expiration for entity plugin definitions.
*
* @var int
*/
protected $cacheExpire = CacheBackendInterface::CACHE_PERMANENT;
/**
* The cache tags used for entity plugin definitions.
*
* @var array
*/
protected $cacheTags = array(
'entity_info' => TRUE,
);
/**
* The default values for optional keys of the entity plugin definition.
*
* @var array
*/
protected $defaults = array(
'class' => 'Drupal\\Core\\Entity\\Entity',
'controller_class' => 'Drupal\\Core\\Entity\\DatabaseStorageController',
'entity_keys' => array(
'revision' => '',
'bundle' => '',
),
'fieldable' => FALSE,
'field_cache' => TRUE,
'form_controller_class' => array(
'default' => 'Drupal\\Core\\Entity\\EntityFormController',
),
'list_controller_class' => 'Drupal\\Core\\Entity\\EntityListController',
'render_controller_class' => 'Drupal\\Core\\Entity\\EntityRenderController',
'access_controller_class' => 'Drupal\\Core\\Entity\\EntityAccessController',
'static_cache' => TRUE,
'translation' => array(),
'bundles' => array(),
'view_modes' => array(),
);
/**
* Constructs a new Entity plugin manager.
*/
public function __construct() {
// Allow the plugin definition to be altered by hook_entity_info_alter().
$this->discovery = new AnnotatedClassDiscovery('Core', 'Entity');
$this->discovery = new InfoHookDecorator($this->discovery, 'entity_info');
$this->discovery = new AlterDecorator($this->discovery, 'entity_info');
// @todo Run process before altering, see http://drupal.org/node/1848964.
$this->discovery = new ProcessDecorator($this->discovery, array(
$this,
'processDefinition',
));
$this->factory = new DefaultFactory($this);
// Entity type plugins includes translated strings, so each language is
// cached separately.
$this->cacheKey .= ':' . language(LANGUAGE_TYPE_INTERFACE)->langcode;
}
/**
* Overrides Drupal\Component\Plugin\PluginManagerBase::getDefinition().
*/
public function getDefinition($plugin_id) {
$definitions = $this
->getDefinitions();
return isset($definitions[$plugin_id]) ? $definitions[$plugin_id] : NULL;
}
/**
* Overrides Drupal\Component\Plugin\PluginManagerBase::getDefinitions().
*/
public function getDefinitions() {
// Because \Drupal\Core\Plugin\Discovery\CacheDecorator runs before
// definitions are processed and does not support cache tags, we perform our
// own caching.
if ($cache = cache($this->cacheBin)
->get($this->cacheKey)) {
return $cache->data;
}
else {
// @todo Remove array_filter() once http://drupal.org/node/1780396 is
// resolved.
$definitions = array_filter(parent::getDefinitions());
cache($this->cacheBin)
->set($this->cacheKey, $definitions, $this->cacheExpire, $this->cacheTags);
return $definitions;
}
}
/**
* Overrides Drupal\Component\Plugin\PluginManagerBase::processDefinition().
*/
public function processDefinition(&$definition, $plugin_id) {
parent::processDefinition($definition, $plugin_id);
// @todo Remove this check once http://drupal.org/node/1780396 is resolved.
if (!module_exists($definition['module'])) {
$definition = NULL;
return;
}
foreach ($definition['view_modes'] as $view_mode => $view_mode_info) {
$definition['view_modes'][$view_mode] += array(
'custom_settings' => FALSE,
);
}
// If no bundle key is provided, assume a single bundle, named after
// the entity type.
if (empty($definition['entity_keys']['bundle']) && empty($definition['bundles'])) {
$definition['bundles'] = array(
$plugin_id => array(
'label' => $definition['label'],
),
);
}
// Prepare entity schema fields SQL info for
// Drupal\Core\Entity\DatabaseStorageControllerInterface::buildQuery().
if (isset($definition['base_table'])) {
$definition['schema_fields_sql']['base_table'] = drupal_schema_fields_sql($definition['base_table']);
if (isset($definition['revision_table'])) {
$definition['schema_fields_sql']['revision_table'] = drupal_schema_fields_sql($definition['revision_table']);
}
}
}
}