Issue #1763974 by tim.plunkett, EclipseGC, berdir, xjm, neclimdul, FabianX: Convert entity type info into plugins.

8.0.x
webchick 2012-10-30 13:37:18 -07:00
parent a61f62b4c6
commit 76a157fe32
122 changed files with 1347 additions and 1207 deletions

View File

@ -11,232 +11,27 @@
*/ */
/** /**
* Inform the base system and the Field API about one or more entity types. * Alter the entity type definition.
*
* Inform the system about one or more entity types (i.e., object types that
* can be loaded via entity_load() and, optionally, to which fields can be
* attached).
*
* @return
* An array whose keys are entity type names and whose values identify
* properties of those types that the system needs to know about:
* - label: The human-readable name of the type.
* - entity class: The name of the entity class, defaults to
* Drupal\Core\Entity\Entity. The entity class must implement EntityInterface.
* - controller class: The name of the class that is used to load the objects.
* The class has to implement the
* Drupal\Core\Entity\EntityStorageControllerInterface interface. Leave blank
* to use the Drupal\Core\Entity\DatabaseStorageController implementation.
* - render controller class: The name of the class that is used to render
* the entities. Deafaults to Drupal\Core\Entity\EntityRenderController.
* - form controller class: An associative array where the keys are the names
* of the different form operations (such as creation, editing or deletion)
* and the values are the names of the controller classes. To facilitate
* supporting the case where an entity form varies only slightly between
* different operations, the name of the operation is passed also to the
* constructor of the form controller class. This way, one class can be used
* for multiple entity forms.
* - list controller class: The name of the class that is used to provide
* listings of the entity. The class must implement
* Drupal\Core\Entity\EntityListControllerInterface. Defaults to
* Drupal\Core\Entity\EntityListController.
* - base table: (used by Drupal\Core\Entity\DatabaseStorageController) The
* name of the entity type's base table.
* - static cache: (used by Drupal\Core\Entity\DatabaseStorageController)
* FALSE to disable static caching of entities during a page request.
* Defaults to TRUE.
* - field cache: (used by Field API loading and saving of field data) FALSE
* to disable Field API's persistent cache of field data. Only recommended
* if a higher level persistent cache is available for the entity type.
* Defaults to TRUE.
* - uri callback: A function taking an entity as argument and returning the
* URI elements of the entity, e.g. 'path' and 'options'. The actual entity
* URI can be constructed by passing these elements to url().
* - label callback: (optional) A function taking an entity and optional langcode
* argument, and returning the label of the entity. If langcode is omitted, the
* entity's default language is used.
*
* The entity label is the main string associated with an entity; for
* example, the title of a node or the subject of a comment. If there is an
* entity object property that defines the label, use the 'label' element
* of the 'entity keys' return value component to provide this information
* (see below). If more complex logic is needed to determine the label of
* an entity, you can instead specify a callback function here, which will
* be called to determine the entity label. See also the
* Drupal\Core\Entity\Entity::label() method, which implements this logic.
* - fieldable: Set to TRUE if you want your entity type to be fieldable.
* - translation: An associative array of modules registered as field
* translation handlers. Array keys are the module names, array values
* can be any data structure the module uses to provide field translation.
* Any empty value disallows the module to appear as a translation handler.
* - entity keys: An array describing how the Field API can extract the
* information it needs from the objects of the type. Elements:
* - id: The name of the property that contains the primary id of the
* entity. Every entity object passed to the Field API must have this
* property and its value must be numeric.
* - revision: The name of the property that contains the revision id of
* the entity. The Field API assumes that all revision ids are unique
* across all entities of a type. This entry can be omitted if the
* entities of this type are not versionable.
* - bundle: The name of the property that contains the bundle name for the
* entity. The bundle name defines which set of fields are attached to
* the entity (e.g. what nodes call "content type"). This entry can be
* omitted if this entity type exposes a single bundle (all entities have
* the same collection of fields). The name of this single bundle will be
* the same as the entity type.
* - label: The name of the property that contains the entity label. For
* example, if the entity's label is located in $entity->subject, then
* 'subject' should be specified here. If complex logic is required to
* build the label, a 'label callback' should be defined instead (see
* the 'label callback' section above for details).
* - uuid (optional): The name of the property that contains the universally
* unique identifier of the entity, which is used to distinctly identify
* an entity across different systems.
* - bundle keys: An array describing how the Field API can extract the
* information it needs from the bundle objects for this type (e.g
* $vocabulary objects for terms; not applicable for nodes). This entry can
* be omitted if this type's bundles do not exist as standalone objects.
* Elements:
* - bundle: The name of the property that contains the name of the bundle
* object.
* - bundles: An array describing all bundles for this object type. Keys are
* bundles machine names, as found in the objects' 'bundle' property
* (defined in the 'entity keys' entry above). Elements:
* - label: The human-readable name of the bundle.
* - uri callback: Same as the 'uri callback' key documented above for the
* entity type, but for the bundle only. When determining the URI of an
* entity, if a 'uri callback' is defined for both the entity type and
* the bundle, the one for the bundle is used.
* - admin: An array of information that allows Field UI pages to attach
* themselves to the existing administration pages for the bundle.
* Elements:
* - path: the path of the bundle's main administration page, as defined
* in hook_menu(). If the path includes a placeholder for the bundle,
* the 'bundle argument', 'bundle helper' and 'real path' keys below
* are required.
* - bundle argument: The position of the placeholder in 'path', if any.
* - real path: The actual path (no placeholder) of the bundle's main
* administration page. This will be used to generate links.
* - access callback: As in hook_menu(). 'user_access' will be assumed if
* no value is provided.
* - access arguments: As in hook_menu().
* - view modes: An array describing the view modes for the entity type. View
* modes let entities be displayed differently depending on the context.
* For instance, a node can be displayed differently on its own page
* ('full' mode), on the home page or taxonomy listings ('teaser' mode), or
* in an RSS feed ('rss' mode). Modules taking part in the display of the
* entity (notably the Field API) can adjust their behavior depending on
* the requested view mode. An additional 'default' view mode is available
* for all entity types. This view mode is not intended for actual entity
* display, but holds default display settings. For each available view
* mode, administrators can configure whether it should use its own set of
* field display settings, or just replicate the settings of the 'default'
* view mode, thus reducing the amount of display configurations to keep
* track of. Keys of the array are view mode names. Each view mode is
* described by an array with the following key/value pairs:
* - label: The human-readable name of the view mode
* - custom settings: A boolean specifying whether the view mode should by
* default use its own custom field display settings. If FALSE, entities
* displayed in this view mode will reuse the 'default' display settings
* by default (e.g. right after the module exposing the view mode is
* enabled), but administrators can later use the Field UI to apply custom
* display settings specific to the view mode.
*
* @see entity_load()
* @see entity_load_multiple()
* @see hook_entity_info_alter()
*/
function hook_entity_info() {
$return = array(
'node' => array(
'label' => t('Node'),
'entity class' => 'Drupal\node\Node',
'controller class' => 'Drupal\node\NodeStorageController',
'form controller class' => array(
'default' => 'Drupal\node\NodeFormController',
),
'base table' => 'node',
'revision table' => 'node_revision',
'uri callback' => 'node_uri',
'fieldable' => TRUE,
'translation' => array(
'locale' => TRUE,
),
'entity keys' => array(
'id' => 'nid',
'revision' => 'vid',
'bundle' => 'type',
'uuid' => 'uuid',
),
'bundle keys' => array(
'bundle' => 'type',
),
'bundles' => array(),
'view modes' => array(
'full' => array(
'label' => t('Full content'),
'custom settings' => FALSE,
),
'teaser' => array(
'label' => t('Teaser'),
'custom settings' => TRUE,
),
'rss' => array(
'label' => t('RSS'),
'custom settings' => FALSE,
),
),
),
);
// Search integration is provided by node.module, so search-related
// view modes for nodes are defined here and not in search.module.
if (module_exists('search')) {
$return['node']['view modes'] += array(
'search_index' => array(
'label' => t('Search index'),
'custom settings' => FALSE,
),
'search_result' => array(
'label' => t('Search result'),
'custom settings' => FALSE,
),
);
}
// Bundles must provide a human readable name so we can create help and error
// messages, and the path to attach Field admin pages to.
foreach (node_type_get_names() as $type => $name) {
$return['node']['bundles'][$type] = array(
'label' => $name,
'admin' => array(
'path' => 'admin/structure/types/manage/%node_type',
'real path' => 'admin/structure/types/manage/' . $type,
'bundle argument' => 4,
'access arguments' => array('administer content types'),
),
);
}
return $return;
}
/**
* Alter the entity info.
* *
* Modules may implement this hook to alter the information that defines an * Modules may implement this hook to alter the information that defines an
* entity. All properties that are available in hook_entity_info() can be * entity. All properties that are available in
* altered here. * \Drupal\Core\Entity\EntityManager can be altered here.
* *
* @param $entity_info * @param array $entity_info
* The entity info array, keyed by entity name. * An associative array of all entity type definitions, keyed by the entity
* type name.
* *
* @see hook_entity_info() * @see \Drupal\Core\Entity\Entity
* @see \Drupal\Core\Entity\EntityManager
* @see entity_get_info()
*
* @todo Allow a module to add its bundles and view modes before other modules
* alter the definition.
*/ */
function hook_entity_info_alter(&$entity_info) { function hook_entity_info_alter(&$entity_info) {
// Set the controller class for nodes to an alternate implementation of the // Set the controller class for nodes to an alternate implementation of the
// Drupal\Core\Entity\EntityStorageControllerInterface interface. // Drupal\Core\Entity\EntityStorageControllerInterface interface.
$entity_info['node']['controller class'] = 'Drupal\mymodule\MyCustomNodeStorageController'; $entity_info['node']['controller_class'] = 'Drupal\mymodule\MyCustomNodeStorageController';
} }
/** /**

View File

@ -10,18 +10,21 @@ use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
/** /**
* Gets the entity info array of an entity type. * Gets the entity definition for an entity type.
* *
* @param $entity_type * @param string|null $entity_type
* The entity type, e.g. node, for which the info shall be returned, or NULL * (optional) The entity type (e.g. 'node'). Leave NULL to retrieve
* to return an array with info about all types. * information for all entity types.
* *
* @see hook_entity_info() * @return array
* An array containing the entity type's definition, as retrieved with
* \Drupal\Core\Entity\EntityManager. If $entity_type is NULL, an associative
* array of all entity type definitions keyed by entity type is returned.
*
* @see \Drupal\Core\Entity\EntityManager
* @see hook_entity_info_alter() * @see hook_entity_info_alter()
*/ */
function entity_get_info($entity_type = NULL) { function entity_get_info($entity_type = NULL) {
$language_interface = language(LANGUAGE_TYPE_INTERFACE);
// Use the advanced drupal_static() pattern, since this is called very often. // Use the advanced drupal_static() pattern, since this is called very often.
static $drupal_static_fast; static $drupal_static_fast;
if (!isset($drupal_static_fast)) { if (!isset($drupal_static_fast)) {
@ -29,61 +32,8 @@ function entity_get_info($entity_type = NULL) {
} }
$entity_info = &$drupal_static_fast['entity_info']; $entity_info = &$drupal_static_fast['entity_info'];
// hook_entity_info() includes translated strings, so each language is cached
// separately.
$langcode = $language_interface->langcode;
if (empty($entity_info)) { if (empty($entity_info)) {
if ($cache = cache()->get("entity_info:$langcode")) { $entity_info = drupal_container()->get('plugin.manager.entity')->getDefinitions();
$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,
'entity class' => 'Drupal\Core\Entity\Entity',
'controller class' => 'Drupal\Core\Entity\DatabaseStorageController',
'list controller class' => 'Drupal\Core\Entity\EntityListController',
'render controller class' => 'Drupal\Core\Entity\EntityRenderController',
'form controller class' => array(
'default' => 'Drupal\Core\Entity\EntityFormController',
),
'static cache' => TRUE,
'field cache' => TRUE,
'bundles' => array(),
'view modes' => array(),
'entity keys' => array(),
'translation' => array(),
);
$entity_info[$name]['entity keys'] += array(
'revision' => '',
'bundle' => '',
);
foreach ($entity_info[$name]['view modes'] as $view_mode => $view_mode_info) {
$entity_info[$name]['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($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
// Drupal\Core\Entity\DatabaseStorageControllerInterface::buildQuery().
if (isset($entity_info[$name]['base table'])) {
$entity_info[$name]['schema_fields_sql']['base table'] = drupal_schema_fields_sql($entity_info[$name]['base table']);
if (isset($entity_info[$name]['revision table'])) {
$entity_info[$name]['schema_fields_sql']['revision table'] = drupal_schema_fields_sql($entity_info[$name]['revision table']);
}
}
}
// Let other modules alter the entity info.
drupal_alter('entity_info', $entity_info);
cache()->set("entity_info:$langcode", $entity_info, CacheBackendInterface::CACHE_PERMANENT, array('entity_info' => TRUE));
}
} }
if (empty($entity_type)) { if (empty($entity_type)) {
@ -116,7 +66,7 @@ function entity_info_cache_clear() {
* @return Drupal\Core\Entity\EntityInterface * @return Drupal\Core\Entity\EntityInterface
* The entity object, or FALSE if there is no entity with the given id. * The entity object, or FALSE if there is no entity with the given id.
* *
* @see hook_entity_info() * @see \Drupal\Core\Entity\EntityManager
* @see entity_load_multiple() * @see entity_load_multiple()
* @see Drupal\Core\Entity\EntityStorageControllerInterface * @see Drupal\Core\Entity\EntityStorageControllerInterface
* @see Drupal\Core\Entity\DatabaseStorageController * @see Drupal\Core\Entity\DatabaseStorageController
@ -139,7 +89,7 @@ function entity_load($entity_type, $id, $reset = FALSE) {
* The entity object, or FALSE if there is no entity with the given revision * The entity object, or FALSE if there is no entity with the given revision
* id. * id.
* *
* @see hook_entity_info() * @see \Drupal\Core\Entity\EntityManager
* @see Drupal\Core\Entity\EntityStorageControllerInterface * @see Drupal\Core\Entity\EntityStorageControllerInterface
* @see Drupal\Core\Entity\DatabaseStorageController * @see Drupal\Core\Entity\DatabaseStorageController
*/ */
@ -177,14 +127,14 @@ function entity_revision_delete($entity_type, $revision_id) {
* @throws Drupal\Core\Entity\EntityStorageException * @throws Drupal\Core\Entity\EntityStorageException
* Thrown in case the requested entity type does not support UUIDs. * Thrown in case the requested entity type does not support UUIDs.
* *
* @see hook_entity_info() * @see \Drupal\Core\Entity\EntityManager
*/ */
function entity_load_by_uuid($entity_type, $uuid, $reset = FALSE) { function entity_load_by_uuid($entity_type, $uuid, $reset = FALSE) {
$entity_info = entity_get_info($entity_type); $entity_info = entity_get_info($entity_type);
if (empty($entity_info['entity keys']['uuid'])) { if (empty($entity_info['entity_keys']['uuid'])) {
throw new EntityStorageException("Entity type $entity_type does not support UUIDs."); throw new EntityStorageException("Entity type $entity_type does not support UUIDs.");
} }
$uuid_key = $entity_info['entity keys']['uuid']; $uuid_key = $entity_info['entity_keys']['uuid'];
$controller = entity_get_controller($entity_type); $controller = entity_get_controller($entity_type);
if ($reset) { if ($reset) {
@ -205,11 +155,12 @@ function entity_load_by_uuid($entity_type, $uuid, $reset = FALSE) {
* Drupal\Core\Entity\EntityStorageControllerInterface interface. By default, * Drupal\Core\Entity\EntityStorageControllerInterface interface. By default,
* Drupal\Core\Entity\DatabaseStorageController is used. Entity types can * Drupal\Core\Entity\DatabaseStorageController is used. Entity types can
* specify that a different class should be used by setting the * specify that a different class should be used by setting the
* 'controller class' key in hook_entity_info(). These classes can either * 'controller_class' key in the entity plugin annotation. These classes can
* implement the Drupal\Core\Entity\EntityStorageControllerInterface interface, or, * either implement the Drupal\Core\Entity\EntityStorageControllerInterface
* most commonly, extend the Drupal\Core\Entity\DatabaseStorageController * interface, or, most commonly, extend the
* class. See node_entity_info() and the NodeStorageController in node.module as * Drupal\Core\Entity\DatabaseStorageController class.
* an example. * See Drupal\node\Plugin\Core\Entity\Node and Drupal\node\NodeStorageController
* for an example.
* *
* @param string $entity_type * @param string $entity_type
* The entity type to load, e.g. node or user. * The entity type to load, e.g. node or user.
@ -221,7 +172,7 @@ function entity_load_by_uuid($entity_type, $uuid, $reset = FALSE) {
* @return array * @return array
* An array of entity objects indexed by their ids. * An array of entity objects indexed by their ids.
* *
* @see hook_entity_info() * @see \Drupal\Core\Entity\EntityManager
* @see Drupal\Core\Entity\EntityStorageControllerInterface * @see Drupal\Core\Entity\EntityStorageControllerInterface
* @see Drupal\Core\Entity\DatabaseStorageController * @see Drupal\Core\Entity\DatabaseStorageController
* @see Drupal\Core\Entity\Query\QueryInterface * @see Drupal\Core\Entity\Query\QueryInterface
@ -308,7 +259,7 @@ function entity_get_controller($entity_type) {
$controllers = &drupal_static(__FUNCTION__, array()); $controllers = &drupal_static(__FUNCTION__, array());
if (!isset($controllers[$entity_type])) { if (!isset($controllers[$entity_type])) {
$type_info = entity_get_info($entity_type); $type_info = entity_get_info($entity_type);
$class = $type_info['controller class']; $class = $type_info['controller_class'];
$controllers[$entity_type] = new $class($entity_type); $controllers[$entity_type] = new $class($entity_type);
} }
return $controllers[$entity_type]; return $controllers[$entity_type];
@ -345,7 +296,7 @@ function entity_page_label(EntityInterface $entity, $langcode = NULL) {
* used. If a non-existing non-default operation is specified an exception will * used. If a non-existing non-default operation is specified an exception will
* be thrown. * be thrown.
* *
* @see hook_entity_info() * @see \Drupal\Core\Entity\EntityManager
* *
* @param $entity_type * @param $entity_type
* The type of the entity. * The type of the entity.
@ -361,11 +312,11 @@ function entity_form_controller($entity_type, $operation = 'default') {
$info = entity_get_info($entity_type); $info = entity_get_info($entity_type);
// Check whether there is a form controller class for the specified operation. // Check whether there is a form controller class for the specified operation.
if (!empty($info['form controller class'][$operation])) { if (!empty($info['form_controller_class'][$operation])) {
$class = $info['form controller class'][$operation]; $class = $info['form_controller_class'][$operation];
} }
// If no controller is specified default to the base implementation. // If no controller is specified default to the base implementation.
elseif (empty($info['form controller class']) && $operation == 'default') { elseif (empty($info['form_controller_class']) && $operation == 'default') {
$class = 'Drupal\Core\Entity\EntityFormController'; $class = 'Drupal\Core\Entity\EntityFormController';
} }
// If a non-existing operation has been specified stop. // If a non-existing operation has been specified stop.
@ -511,12 +462,12 @@ function entity_form_submit_build_entity($entity_type, $entity, $form, &$form_st
* @return Drupal\Core\Entity\EntityListControllerInterface * @return Drupal\Core\Entity\EntityListControllerInterface
* An entity list controller. * An entity list controller.
* *
* @see hook_entity_info() * @see \Drupal\Core\Entity\EntityManager
*/ */
function entity_list_controller($entity_type) { function entity_list_controller($entity_type) {
$storage = entity_get_controller($entity_type); $storage = entity_get_controller($entity_type);
$entity_info = entity_get_info($entity_type); $entity_info = entity_get_info($entity_type);
$class = $entity_info['list controller class']; $class = $entity_info['list_controller_class'];
return new $class($entity_type, $storage); return new $class($entity_type, $storage);
} }
@ -529,11 +480,11 @@ function entity_list_controller($entity_type) {
* @return Drupal\Core\Entity\EntityRenderControllerInterface * @return Drupal\Core\Entity\EntityRenderControllerInterface
* An entity render controller. * An entity render controller.
* *
* @see hook_entity_info() * @see \Drupal\Core\Entity\EntityManager
*/ */
function entity_render_controller($entity_type) { function entity_render_controller($entity_type) {
$info = entity_get_info($entity_type); $info = entity_get_info($entity_type);
$class = $info['render controller class']; $class = $info['render_controller_class'];
return new $class($entity_type); return new $class($entity_type);
} }

View File

@ -65,7 +65,7 @@ class ConfigStorageController implements EntityStorageControllerInterface {
$this->entityType = $entityType; $this->entityType = $entityType;
$this->entityInfo = entity_get_info($entityType); $this->entityInfo = entity_get_info($entityType);
$this->hookLoadArguments = array(); $this->hookLoadArguments = array();
$this->idKey = $this->entityInfo['entity keys']['id']; $this->idKey = $this->entityInfo['entity_keys']['id'];
} }
/** /**
@ -158,8 +158,8 @@ class ConfigStorageController implements EntityStorageControllerInterface {
* A SelectQuery object for loading the entity. * A SelectQuery object for loading the entity.
*/ */
protected function buildQuery($ids, $revision_id = FALSE) { protected function buildQuery($ids, $revision_id = FALSE) {
$config_class = $this->entityInfo['entity class']; $config_class = $this->entityInfo['class'];
$prefix = $this->entityInfo['config prefix'] . '.'; $prefix = $this->entityInfo['config_prefix'] . '.';
// Load all of the configuration entities. // Load all of the configuration entities.
if ($ids === NULL) { if ($ids === NULL) {
@ -220,7 +220,7 @@ class ConfigStorageController implements EntityStorageControllerInterface {
* Implements Drupal\Core\Entity\EntityStorageControllerInterface::create(). * Implements Drupal\Core\Entity\EntityStorageControllerInterface::create().
*/ */
public function create(array $values) { public function create(array $values) {
$class = isset($this->entityInfo['entity class']) ? $this->entityInfo['entity class'] : 'Drupal\Core\Entity\Entity'; $class = $this->entityInfo['class'];
$entity = new $class($values, $this->entityType); $entity = new $class($values, $this->entityType);
// Mark this entity as new, so isNew() returns TRUE. This does not check // Mark this entity as new, so isNew() returns TRUE. This does not check
@ -252,7 +252,7 @@ class ConfigStorageController implements EntityStorageControllerInterface {
} }
foreach ($entities as $id => $entity) { foreach ($entities as $id => $entity) {
$config = config($this->entityInfo['config prefix'] . '.' . $entity->id()); $config = config($this->entityInfo['config_prefix'] . '.' . $entity->id());
$config->delete(); $config->delete();
} }
@ -269,7 +269,7 @@ class ConfigStorageController implements EntityStorageControllerInterface {
* When attempting to save a configuration entity that has no ID. * When attempting to save a configuration entity that has no ID.
*/ */
public function save(EntityInterface $entity) { public function save(EntityInterface $entity) {
$prefix = $this->entityInfo['config prefix'] . '.'; $prefix = $this->entityInfo['config_prefix'] . '.';
// Configuration entity IDs are strings, and '0' is a valid ID. // Configuration entity IDs are strings, and '0' is a valid ID.
$id = $entity->id(); $id = $entity->id();

View File

@ -70,6 +70,8 @@ class CoreBundle extends Bundle
->addArgument(new Reference('router.dumper')) ->addArgument(new Reference('router.dumper'))
->addArgument(new Reference('lock')); ->addArgument(new Reference('lock'));
$container->register('plugin.manager.entity', 'Drupal\Core\Entity\EntityManager');
$container->register('matcher', 'Drupal\Core\Routing\ChainMatcher'); $container->register('matcher', 'Drupal\Core\Routing\ChainMatcher');
$container->register('legacy_url_matcher', 'Drupal\Core\LegacyUrlMatcher') $container->register('legacy_url_matcher', 'Drupal\Core\LegacyUrlMatcher')
->addTag('chained_matcher'); ->addTag('chained_matcher');

View File

@ -117,27 +117,27 @@ class DatabaseStorageController implements EntityStorageControllerInterface {
$this->entityInfo = entity_get_info($entityType); $this->entityInfo = entity_get_info($entityType);
$this->entityCache = array(); $this->entityCache = array();
$this->hookLoadArguments = array(); $this->hookLoadArguments = array();
$this->idKey = $this->entityInfo['entity keys']['id']; $this->idKey = $this->entityInfo['entity_keys']['id'];
// Check if the entity type supports UUIDs. // Check if the entity type supports UUIDs.
if (!empty($this->entityInfo['entity keys']['uuid'])) { if (!empty($this->entityInfo['entity_keys']['uuid'])) {
$this->uuidKey = $this->entityInfo['entity keys']['uuid']; $this->uuidKey = $this->entityInfo['entity_keys']['uuid'];
} }
else { else {
$this->uuidKey = FALSE; $this->uuidKey = FALSE;
} }
// Check if the entity type supports revisions. // Check if the entity type supports revisions.
if (!empty($this->entityInfo['entity keys']['revision'])) { if (!empty($this->entityInfo['entity_keys']['revision'])) {
$this->revisionKey = $this->entityInfo['entity keys']['revision']; $this->revisionKey = $this->entityInfo['entity_keys']['revision'];
$this->revisionTable = $this->entityInfo['revision table']; $this->revisionTable = $this->entityInfo['revision_table'];
} }
else { else {
$this->revisionKey = FALSE; $this->revisionKey = FALSE;
} }
// Check if the entity type supports static caching of loaded entities. // Check if the entity type supports static caching of loaded entities.
$this->cache = !empty($this->entityInfo['static cache']); $this->cache = !empty($this->entityInfo['static_cache']);
} }
/** /**
@ -183,11 +183,11 @@ class DatabaseStorageController implements EntityStorageControllerInterface {
// Build and execute the query. // Build and execute the query.
$query_result = $this->buildQuery($ids)->execute(); $query_result = $this->buildQuery($ids)->execute();
if (!empty($this->entityInfo['entity class'])) { if (!empty($this->entityInfo['class'])) {
// We provide the necessary arguments for PDO to create objects of the // We provide the necessary arguments for PDO to create objects of the
// specified entity class. // specified entity class.
// @see Drupal\Core\Entity\EntityInterface::__construct() // @see Drupal\Core\Entity\EntityInterface::__construct()
$query_result->setFetchMode(PDO::FETCH_CLASS, $this->entityInfo['entity class'], array(array(), $this->entityType)); $query_result->setFetchMode(PDO::FETCH_CLASS, $this->entityInfo['class'], array(array(), $this->entityType));
} }
$queried_entities = $query_result->fetchAllAssoc($this->idKey); $queried_entities = $query_result->fetchAllAssoc($this->idKey);
} }
@ -228,11 +228,11 @@ class DatabaseStorageController implements EntityStorageControllerInterface {
// Build and execute the query. // Build and execute the query.
$query_result = $this->buildQuery(array(), $revision_id)->execute(); $query_result = $this->buildQuery(array(), $revision_id)->execute();
if (!empty($this->entityInfo['entity class'])) { if (!empty($this->entityInfo['class'])) {
// We provide the necessary arguments for PDO to create objects of the // We provide the necessary arguments for PDO to create objects of the
// specified entity class. // specified entity class.
// @see Drupal\Core\Entity\EntityInterface::__construct() // @see Drupal\Core\Entity\EntityInterface::__construct()
$query_result->setFetchMode(PDO::FETCH_CLASS, $this->entityInfo['entity class'], array(array(), $this->entityType)); $query_result->setFetchMode(PDO::FETCH_CLASS, $this->entityInfo['class'], array(array(), $this->entityType));
} }
$queried_entities = $query_result->fetchAllAssoc($this->idKey); $queried_entities = $query_result->fetchAllAssoc($this->idKey);
@ -310,7 +310,7 @@ class DatabaseStorageController implements EntityStorageControllerInterface {
* A SelectQuery object for loading the entity. * A SelectQuery object for loading the entity.
*/ */
protected function buildQuery($ids, $revision_id = FALSE) { protected function buildQuery($ids, $revision_id = FALSE) {
$query = db_select($this->entityInfo['base table'], 'base'); $query = db_select($this->entityInfo['base_table'], 'base');
$query->addTag($this->entityType . '_load_multiple'); $query->addTag($this->entityType . '_load_multiple');
@ -322,11 +322,11 @@ class DatabaseStorageController implements EntityStorageControllerInterface {
} }
// Add fields from the {entity} table. // Add fields from the {entity} table.
$entity_fields = $this->entityInfo['schema_fields_sql']['base table']; $entity_fields = $this->entityInfo['schema_fields_sql']['base_table'];
if ($this->revisionKey) { if ($this->revisionKey) {
// Add all fields from the {entity_revision} table. // Add all fields from the {entity_revision} table.
$entity_revision_fields = drupal_map_assoc($this->entityInfo['schema_fields_sql']['revision table']); $entity_revision_fields = drupal_map_assoc($this->entityInfo['schema_fields_sql']['revision_table']);
// The id field is provided by entity, so remove it. // The id field is provided by entity, so remove it.
unset($entity_revision_fields[$this->idKey]); unset($entity_revision_fields[$this->idKey]);
@ -427,7 +427,7 @@ class DatabaseStorageController implements EntityStorageControllerInterface {
* Implements Drupal\Core\Entity\EntityStorageControllerInterface::create(). * Implements Drupal\Core\Entity\EntityStorageControllerInterface::create().
*/ */
public function create(array $values) { public function create(array $values) {
$class = isset($this->entityInfo['entity class']) ? $this->entityInfo['entity class'] : 'Drupal\Core\Entity\Entity'; $class = $this->entityInfo['class'];
$entity = new $class($values, $this->entityType); $entity = new $class($values, $this->entityType);
@ -458,7 +458,7 @@ class DatabaseStorageController implements EntityStorageControllerInterface {
} }
$ids = array_keys($entities); $ids = array_keys($entities);
db_delete($this->entityInfo['base table']) db_delete($this->entityInfo['base_table'])
->condition($this->idKey, $ids, 'IN') ->condition($this->idKey, $ids, 'IN')
->execute(); ->execute();
@ -501,7 +501,7 @@ class DatabaseStorageController implements EntityStorageControllerInterface {
if (!$entity->isNew()) { if (!$entity->isNew()) {
if ($entity->isDefaultRevision()) { if ($entity->isDefaultRevision()) {
$return = drupal_write_record($this->entityInfo['base table'], $entity, $this->idKey); $return = drupal_write_record($this->entityInfo['base_table'], $entity, $this->idKey);
} }
else { else {
// @todo, should a different value be returned when saving an entity // @todo, should a different value be returned when saving an entity
@ -516,7 +516,7 @@ class DatabaseStorageController implements EntityStorageControllerInterface {
$this->invokeHook('update', $entity); $this->invokeHook('update', $entity);
} }
else { else {
$return = drupal_write_record($this->entityInfo['base table'], $entity); $return = drupal_write_record($this->entityInfo['base_table'], $entity);
if ($this->revisionKey) { if ($this->revisionKey) {
$this->saveRevision($entity); $this->saveRevision($entity);
} }
@ -564,7 +564,7 @@ class DatabaseStorageController implements EntityStorageControllerInterface {
if ($entity->isNewRevision()) { if ($entity->isNewRevision()) {
drupal_write_record($this->revisionTable, $record); drupal_write_record($this->revisionTable, $record);
if ($entity->isDefaultRevision()) { if ($entity->isDefaultRevision()) {
db_update($this->entityInfo['base table']) db_update($this->entityInfo['base_table'])
->fields(array($this->revisionKey => $record[$this->revisionKey])) ->fields(array($this->revisionKey => $record[$this->revisionKey]))
->condition($this->idKey, $entity->id()) ->condition($this->idKey, $entity->id())
->execute(); ->execute();

View File

@ -41,14 +41,14 @@ class DatabaseStorageControllerNG extends DatabaseStorageController {
*/ */
public function __construct($entityType) { public function __construct($entityType) {
parent::__construct($entityType); parent::__construct($entityType);
$this->bundleKey = !empty($this->entityInfo['entity keys']['bundle']) ? $this->entityInfo['entity keys']['bundle'] : FALSE; $this->bundleKey = !empty($this->entityInfo['entity_keys']['bundle']) ? $this->entityInfo['entity_keys']['bundle'] : FALSE;
$this->entityClass = $this->entityInfo['entity class']; $this->entityClass = $this->entityInfo['class'];
// Work-a-round to let load() get stdClass storage records without having to // Work-a-round to let load() get stdClass storage records without having to
// override it. We map storage records to entities in // override it. We map storage records to entities in
// DatabaseStorageControllerNG:: mapFromStorageRecords(). // DatabaseStorageControllerNG:: mapFromStorageRecords().
// @todo: Remove this once this is moved in the main controller. // @todo: Remove this once this is moved in the main controller.
unset($this->entityInfo['entity class']); unset($this->entityInfo['class']);
} }
/** /**
@ -181,13 +181,13 @@ class DatabaseStorageControllerNG extends DatabaseStorageController {
$entity->updateOriginalValues(); $entity->updateOriginalValues();
if (!$entity->isNew()) { if (!$entity->isNew()) {
$return = drupal_write_record($this->entityInfo['base table'], $record, $this->idKey); $return = drupal_write_record($this->entityInfo['base_table'], $record, $this->idKey);
$this->resetCache(array($entity->id())); $this->resetCache(array($entity->id()));
$this->postSave($entity, TRUE); $this->postSave($entity, TRUE);
$this->invokeHook('update', $entity); $this->invokeHook('update', $entity);
} }
else { else {
$return = drupal_write_record($this->entityInfo['base table'], $record); $return = drupal_write_record($this->entityInfo['base_table'], $record);
// Reset general caches, but keep caches specific to certain entities. // Reset general caches, but keep caches specific to certain entities.
$this->resetCache(array()); $this->resetCache(array());
@ -234,7 +234,7 @@ class DatabaseStorageControllerNG extends DatabaseStorageController {
*/ */
protected function mapToStorageRecord(EntityInterface $entity) { protected function mapToStorageRecord(EntityInterface $entity) {
$record = new \stdClass(); $record = new \stdClass();
foreach ($this->entityInfo['schema_fields_sql']['base table'] as $name) { foreach ($this->entityInfo['schema_fields_sql']['base_table'] as $name) {
$record->$name = $entity->$name->value; $record->$name = $entity->$name->value;
} }
return $record; return $record;

View File

@ -99,7 +99,7 @@ class Entity implements IteratorAggregate, EntityInterface {
*/ */
public function isNewRevision() { public function isNewRevision() {
$info = $this->entityInfo(); $info = $this->entityInfo();
return $this->newRevision || (!empty($info['entity keys']['revision']) && !$this->getRevisionId()); return $this->newRevision || (!empty($info['entity_keys']['revision']) && !$this->getRevisionId());
} }
/** /**
@ -136,11 +136,11 @@ class Entity implements IteratorAggregate, EntityInterface {
public function label($langcode = NULL) { public function label($langcode = NULL) {
$label = NULL; $label = NULL;
$entity_info = $this->entityInfo(); $entity_info = $this->entityInfo();
if (isset($entity_info['label callback']) && function_exists($entity_info['label callback'])) { if (isset($entity_info['label_callback']) && function_exists($entity_info['label_callback'])) {
$label = $entity_info['label callback']($this->entityType, $this, $langcode); $label = $entity_info['label_callback']($this->entityType, $this, $langcode);
} }
elseif (!empty($entity_info['entity keys']['label']) && isset($this->{$entity_info['entity keys']['label']})) { elseif (!empty($entity_info['entity_keys']['label']) && isset($this->{$entity_info['entity_keys']['label']})) {
$label = $this->{$entity_info['entity keys']['label']}; $label = $this->{$entity_info['entity_keys']['label']};
} }
return $label; return $label;
} }
@ -153,11 +153,11 @@ class Entity implements IteratorAggregate, EntityInterface {
// A bundle-specific callback takes precedence over the generic one for the // A bundle-specific callback takes precedence over the generic one for the
// entity type. // entity type.
$entity_info = $this->entityInfo(); $entity_info = $this->entityInfo();
if (isset($entity_info['bundles'][$bundle]['uri callback'])) { if (isset($entity_info['bundles'][$bundle]['uri_callback'])) {
$uri_callback = $entity_info['bundles'][$bundle]['uri callback']; $uri_callback = $entity_info['bundles'][$bundle]['uri_callback'];
} }
elseif (isset($entity_info['uri callback'])) { elseif (isset($entity_info['uri_callback'])) {
$uri_callback = $entity_info['uri callback']; $uri_callback = $entity_info['uri_callback'];
} }
else { else {
return NULL; return NULL;
@ -330,12 +330,12 @@ class Entity implements IteratorAggregate, EntityInterface {
public function createDuplicate() { public function createDuplicate() {
$duplicate = clone $this; $duplicate = clone $this;
$entity_info = $this->entityInfo(); $entity_info = $this->entityInfo();
$duplicate->{$entity_info['entity keys']['id']} = NULL; $duplicate->{$entity_info['entity_keys']['id']} = NULL;
// Check if the entity type supports UUIDs and generate a new one if so. // Check if the entity type supports UUIDs and generate a new one if so.
if (!empty($entity_info['entity keys']['uuid'])) { if (!empty($entity_info['entity_keys']['uuid'])) {
$uuid = new Uuid(); $uuid = new Uuid();
$duplicate->{$entity_info['entity keys']['uuid']} = $uuid->generate(); $duplicate->{$entity_info['entity_keys']['uuid']} = $uuid->generate();
} }
return $duplicate; return $duplicate;
} }

View File

@ -0,0 +1,279 @@
<?php
/**
* @file
* Contains \Drupal\Core\Entity\EntityManager.
*/
namespace Drupal\Core\Entity;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\Core\Plugin\Discovery\AlterDecorator;
use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery;
use Drupal\Core\Cache\CacheBackendInterface;
/**
* 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:
* - module: The name of the module providing the type.
* - class: The name of the entity type class. Defaults to
* Drupal\Core\Entity\Entity.
* - base_table: The name of the entity type's base table. Used by
* Drupal\Core\Entity\DatabaseStorageController.
* - controller_class: The name of the class that is used to load the objects.
* The class must implement
* Drupal\Core\Entity\EntityStorageControllerInterface. Defaults to
* Drupal\Core\Entity\DatabaseStorageController.
* - fieldable: (optional) Boolean indicating whether fields can be attached
* to entities of this type. Defaults to FALSE.
* - field_cache: (optional) Boolean indicating whether the Field API's
* Field API's persistent cache of field data should be used. The persistent
* cache should usually only be disabled if a higher level persistent cache
* is available for the entity type. Defaults to TRUE.
* - form_controller_class: (optional) An associative array where the keys
* are the names of the different form operations (such as 'create',
* 'edit', or 'delete') and the values are the names of the controller
* classes for those operations. The name of the operation is passed also
* to the form controller's constructor, so that one class can be used for
* multiple entity forms when the forms are similar. Defaults to
* Drupal\Core\Entity\EntityFormController.
* - label: The human-readable name of the type.
* - label_callback: (optional) A function taking an entity and optional
* langcode argument, and returning the label of the entity. If langcode is
* omitted, the entity's default language is used.
* The entity label is the main string associated with an entity; for
* example, the title of a node or the subject of a comment. If there is an
* entity object property that defines the label, use the 'label' element
* of the 'entity_keys' return value component to provide this information
* (see below). If more complex logic is needed to determine the label of
* an entity, you can instead specify a callback function here, which will
* be called to determine the entity label. See also the
* Drupal\Core\Entity\Entity::label() method, which implements this logic.
* - list_controller_class: (optional) The name of the class that provides
* listings of the The class must implement
* Drupal\Core\Entity\EntityListControllerInterface. Defaults to
* Drupal\Core\Entity\EntityListController.
* - render_controller_class: The name of the class that is used to render the
* entities. Defaults to Drupal\Core\Entity\EntityRenderController.
* - static_cache: (optional) Boolean indicating whether entities should be
* statically cached during a page request. Used by
* Drupal\Core\Entity\DatabaseStorageController. Defaults to TRUE.
* - translation: (optional) An associative array of modules registered as
* field translation handlers. Array keys are the module names, and array
* values can be any data structure the module uses to provide field
* translation. If the value is empty, the module will not be used as a
* translation handler.
* - entity_keys: An array describing how the Field API can extract certain
* information from objects of this entity type. Elements:
* - id: The name of the property that contains the primary ID of the
* entity. Every entity object passed to the Field API must have this
* property and its value must be numeric.
* - revision: (optional) The name of the property that contains the
* revision ID of the entity. The Field API assumes that all revision IDs
* are unique across all entities of a type. This entry can be omitted if
* the entities of this type are not versionable.
* - bundle: (optional) The name of the property that contains the bundle
* name for the entity. The bundle name defines which set of fields are
* attached to the entity (e.g. what nodes call "content type"). This
* entry can be omitted if this entity type exposes a single bundle (such
* that all entities have the same collection of fields). The name of
* this single bundle will be the same as the entity type.
* - label: The name of the property that contains the entity label. For
* example, if the entity's label is located in $entity->subject, then
* 'subject' should be specified here. If complex logic is required to
* build the label, a 'label_callback' should be defined instead (see
* the 'label_callback' section above for details).
* - uuid (optional): The name of the property that contains the universally
* unique identifier of the entity, which is used to distinctly identify
* an entity across different systems.
* - bundle_keys: An array describing how the Field API can extract the
* information it needs from the bundle objects for this type (e.g
* Vocabulary objects for terms; not applicable for nodes). This entry can
* be omitted if this type's bundles do not exist as standalone objects.
* Elements:
* - bundle: The name of the property that contains the name of the bundle
* object.
* - bundles: An array describing all bundles for this object type. Keys are
* bundle machine names, as found in the objects' 'bundle' property
* (defined in the 'entity_keys' entry for the entity type in the
* EntityManager). Elements:
* - label: The human-readable name of the bundle.
* - uri_callback: The same as the 'uri_callback' key defined for the entity
* type in the EntityManager, but for the bundle only. When determining
* the URI of an entity, if a 'uri_callback' is defined for both the
* entity type and the bundle, the one for the bundle is used.
* - admin: An array of information that allows Field UI pages to attach
* themselves to the existing administration pages for the bundle.
* Elements:
* - path: the path of the bundle's main administration page, as defined
* in hook_menu(). If the path includes a placeholder for the bundle,
* the 'bundle argument', 'bundle helper' and 'real path' keys below
* are required.
* - bundle argument: The position of the placeholder in 'path', if any.
* - real path: The actual path (no placeholder) of the bundle's main
* administration page. This will be used to generate links.
* - access callback: As in hook_menu(). 'user_access' will be assumed if
* no value is provided.
* - access arguments: As in hook_menu().
* - view_modes: An array describing the view modes for the entity type. View
* modes let entities be displayed differently depending on the context.
* For instance, a node can be displayed differently on its own page
* ('full' mode), on the home page or taxonomy listings ('teaser' mode), or
* in an RSS feed ('rss' mode). Modules taking part in the display of the
* entity (notably the Field API) can adjust their behavior depending on
* the requested view mode. An additional 'default' view mode is available
* for all entity types. This view mode is not intended for actual entity
* display, but holds default display settings. For each available view
* mode, administrators can configure whether it should use its own set of
* field display settings, or just replicate the settings of the 'default'
* view mode, thus reducing the amount of display configurations to keep
* track of. Keys of the array are view mode names. Each view mode is
* described by an array with the following key/value pairs:
* - label: The human-readable name of the view mode.
* - custom_settings: A boolean specifying whether the view mode should by
* default use its own custom field display settings. If FALSE, entities
* displayed in this view mode will reuse the 'default' display settings
* by default (e.g. right after the module exposing the view mode is
* enabled), but administrators can later use the Field UI to apply custom
* display settings specific to the view mode.
*
* The defaults for the plugin definition are provided in
* \Drupal\Core\Entity\EntityManager::defaults.
*
* @see \Drupal\Core\Entity\Entity
* @see entity_get_info()
* @see hook_entity_info_alter()
*/
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',
'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 AlterDecorator(new AnnotatedClassDiscovery('Core', 'Entity'), 'entity_info');
$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().
*/
protected 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']);
}
}
}
}

View File

@ -398,12 +398,12 @@ class EntityNG extends Entity {
public function createDuplicate() { public function createDuplicate() {
$duplicate = clone $this; $duplicate = clone $this;
$entity_info = $this->entityInfo(); $entity_info = $this->entityInfo();
$duplicate->{$entity_info['entity keys']['id']}->value = NULL; $duplicate->{$entity_info['entity_keys']['id']}->value = NULL;
// Check if the entity type supports UUIDs and generate a new one if so. // Check if the entity type supports UUIDs and generate a new one if so.
if (!empty($entity_info['entity keys']['uuid'])) { if (!empty($entity_info['entity_keys']['uuid'])) {
$uuid = new Uuid(); $uuid = new Uuid();
$duplicate->{$entity_info['entity keys']['uuid']}->value = $uuid->generate(); $duplicate->{$entity_info['entity_keys']['uuid']}->value = $uuid->generate();
} }
return $duplicate; return $duplicate;
} }

View File

@ -10,9 +10,9 @@ namespace Drupal\Core\Entity;
/** /**
* Defines a common interface for entity controller classes. * Defines a common interface for entity controller classes.
* *
* All entity controller classes specified via the 'controller class' key * All entity controller classes specified via the 'controller_class' key
* returned by hook_entity_info() or hook_entity_info_alter() have to implement * returned by \Drupal\Core\Entity\EntityManager or hook_entity_info_alter()
* this interface. * have to implement this interface.
* *
* Most simple, SQL-based entity controllers will do better by extending * Most simple, SQL-based entity controllers will do better by extending
* Drupal\Core\Entity\DatabaseStorageController instead of implementing this * Drupal\Core\Entity\DatabaseStorageController instead of implementing this

View File

@ -5,7 +5,7 @@
* Admin page callbacks for the book module. * Admin page callbacks for the book module.
*/ */
use Drupal\node\Node; use Drupal\node\Plugin\Core\Entity\Node;
/** /**
* Page callback: Returns an administrative overview of all books. * Page callback: Returns an administrative overview of all books.

View File

@ -5,7 +5,7 @@
* Allows users to create and organize related content in an outline. * Allows users to create and organize related content in an outline.
*/ */
use Drupal\node\Node; use Drupal\node\Plugin\Core\Entity\Node;
use Drupal\Core\Template\Attribute; use Drupal\Core\Template\Attribute;
/** /**
@ -253,11 +253,9 @@ function book_admin_paths() {
*/ */
function book_entity_info_alter(&$info) { function book_entity_info_alter(&$info) {
// Add the 'Print' view mode for nodes. // Add the 'Print' view mode for nodes.
$info['node']['view modes'] += array( $info['node']['view_modes']['print'] = array(
'print' => array( 'label' => t('Print'),
'label' => t('Print'), 'custom_settings' => FALSE,
'custom settings' => FALSE,
),
); );
} }

View File

@ -5,7 +5,7 @@
* User page callbacks for the book module. * User page callbacks for the book module.
*/ */
use Drupal\node\Node; use Drupal\node\Plugin\Core\Entity\Node;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

View File

@ -7,7 +7,7 @@
namespace Drupal\book\Tests; namespace Drupal\book\Tests;
use Drupal\node\Node; use Drupal\node\Plugin\Core\Entity\Node;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
class BookTest extends WebTestBase { class BookTest extends WebTestBase {

View File

@ -5,8 +5,8 @@
* Manage breakpoints and breakpoint groups for responsive designs. * Manage breakpoints and breakpoint groups for responsive designs.
*/ */
use Drupal\breakpoint\Breakpoint; use Drupal\breakpoint\Plugin\Core\Entity\Breakpoint;
use Drupal\breakpoint\BreakpointGroup; use Drupal\breakpoint\Plugin\Core\Entity\BreakpointGroup;
/** /**
* Implements hook_help(). * Implements hook_help().
@ -193,7 +193,7 @@ function _breakpoint_delete_breakpoints($list, $source_type) {
// Remove the breakpoint.breakpoint part of the breakpoint identifier. // Remove the breakpoint.breakpoint part of the breakpoint identifier.
foreach ($ids as &$id) { foreach ($ids as &$id) {
$id = drupal_substr($id, drupal_strlen($entity_info['config prefix']) + 1); $id = drupal_substr($id, drupal_strlen($entity_info['config_prefix']) + 1);
} }
$breakpoint_groups = entity_load_multiple('breakpoint_group', $ids); $breakpoint_groups = entity_load_multiple('breakpoint_group', $ids);
@ -208,7 +208,7 @@ function _breakpoint_delete_breakpoints($list, $source_type) {
// Remove the breakpoint.breakpoint part of the breakpoint identifier. // Remove the breakpoint.breakpoint part of the breakpoint identifier.
foreach ($breakpoint_ids as &$breakpoint_id) { foreach ($breakpoint_ids as &$breakpoint_id) {
$breakpoint_id = drupal_substr($breakpoint_id, drupal_strlen($entity_info['config prefix']) + 1); $breakpoint_id = drupal_substr($breakpoint_id, drupal_strlen($entity_info['config_prefix']) + 1);
} }
$breakpoints = entity_load_multiple('breakpoint', $breakpoint_ids); $breakpoints = entity_load_multiple('breakpoint', $breakpoint_ids);
@ -289,46 +289,13 @@ function breakpoint_get_module_media_queries($module) {
return array(); return array();
} }
/**
* Implements hook_entity_info().
*/
function breakpoint_entity_info() {
// Breakpoint.
$types['breakpoint'] = array(
'label' => 'Breakpoint',
'entity class' => 'Drupal\breakpoint\Breakpoint',
'controller class' => 'Drupal\Core\Config\Entity\ConfigStorageController',
'config prefix' => 'breakpoint.breakpoint',
'entity keys' => array(
'id' => 'id',
'label' => 'label',
'uuid' => 'uuid',
),
);
// Breakpoint group.
$types['breakpoint_group'] = array(
'label' => 'Breakpoint group',
'entity class' => 'Drupal\breakpoint\BreakpointGroup',
'controller class' => 'Drupal\Core\Config\Entity\ConfigStorageController',
'config prefix' => 'breakpoint.breakpoint_group',
'entity keys' => array(
'id' => 'id',
'label' => 'label',
'uuid' => 'uuid',
),
);
return $types;
}
/** /**
* Load one breakpoint group by its identifier. * Load one breakpoint group by its identifier.
* *
* @param string $id * @param string $id
* The id of the breakpoint group to load. * The id of the breakpoint group to load.
* *
* @return Drupal\breakpoint\BreakpointGroup|false * @return Drupal\breakpoint\Plugin\Core\Entity\BreakpointGroup|false
* The breakpoint group, or FALSE if there is no entity with the given id. * The breakpoint group, or FALSE if there is no entity with the given id.
* *
* @todo Remove this in a follow-up issue. * @todo Remove this in a follow-up issue.
@ -344,7 +311,7 @@ function breakpoint_group_load($id) {
* @param int $id * @param int $id
* The id of the breakpoint to load. * The id of the breakpoint to load.
* *
* @return Drupal\breakpoint\Breakpoint * @return Drupal\breakpoint\Plugin\Core\Entity\Breakpoint
* The entity object, or FALSE if there is no entity with the given id. * The entity object, or FALSE if there is no entity with the given id.
* *
* @todo Remove this in a follow-up issue. * @todo Remove this in a follow-up issue.
@ -398,7 +365,7 @@ function breakpoint_select_options() {
* @param string $source_type * @param string $source_type
* Either Breakpoint::SOURCE_TYPE_THEME or Breakpoint::SOURCE_TYPE_MODULE. * Either Breakpoint::SOURCE_TYPE_THEME or Breakpoint::SOURCE_TYPE_MODULE.
* *
* @return Drupal\breakpoint\BreakpointGroup * @return Drupal\breakpoint\Plugin\Core\Entity\BreakpointGroup
* *
* @see _breakpoint_import_media_queries() * @see _breakpoint_import_media_queries()
* @see _breakpoint_import_breakpoint_groups() * @see _breakpoint_import_breakpoint_groups()

View File

@ -2,10 +2,10 @@
/** /**
* @file * @file
* Definition of Drupal\breakpoint\Breakpoint. * Definition of Drupal\breakpoint\Plugin\Core\Entity\Breakpoint.
*/ */
namespace Drupal\breakpoint; namespace Drupal\breakpoint\Plugin\Core\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\breakpoint\InvalidBreakpointException; use Drupal\breakpoint\InvalidBreakpointException;
@ -13,9 +13,24 @@ use Drupal\breakpoint\InvalidBreakpointNameException;
use Drupal\breakpoint\InvalidBreakpointSourceException; use Drupal\breakpoint\InvalidBreakpointSourceException;
use Drupal\breakpoint\InvalidBreakpointSourceTypeException; use Drupal\breakpoint\InvalidBreakpointSourceTypeException;
use Drupal\breakpoint\InvalidBreakpointMediaQueryException; use Drupal\breakpoint\InvalidBreakpointMediaQueryException;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/** /**
* Defines the Breakpoint entity. * Defines the Breakpoint entity.
*
* @Plugin(
* id = "breakpoint",
* label = @Translation("Breakpoint"),
* module = "breakpoint",
* controller_class = "Drupal\Core\Config\Entity\ConfigStorageController",
* config_prefix = "breakpoint.breakpoint",
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "uuid" = "uuid"
* }
* )
*/ */
class Breakpoint extends ConfigEntityBase { class Breakpoint extends ConfigEntityBase {

View File

@ -2,17 +2,32 @@
/** /**
* @file * @file
* Definition of Drupal\breakpoint\BreakpointGroup. * Definition of Drupal\breakpoint\Plugin\Core\Entity\BreakpointGroup.
*/ */
namespace Drupal\breakpoint; namespace Drupal\breakpoint\Plugin\Core\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\breakpoint\InvalidBreakpointSourceException; use Drupal\breakpoint\InvalidBreakpointSourceException;
use Drupal\breakpoint\InvalidBreakpointSourceTypeException; use Drupal\breakpoint\InvalidBreakpointSourceTypeException;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/** /**
* Defines the BreakpointGroup entity. * Defines the BreakpointGroup entity.
*
* @Plugin(
* id = "breakpoint_group",
* label = @Translation("Breakpoint group"),
* module = "breakpoint",
* controller_class = "Drupal\Core\Config\Entity\ConfigStorageController",
* config_prefix = "breakpoint.breakpoint_group",
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "uuid" = "uuid"
* }
* )
*/ */
class BreakpointGroup extends ConfigEntityBase { class BreakpointGroup extends ConfigEntityBase {
@ -50,7 +65,7 @@ class BreakpointGroup extends ConfigEntityBase {
* @var array * @var array
* Array containing all breakpoints of this group. * Array containing all breakpoints of this group.
* *
* @see Drupal\breakpoints\Breakpoint * @see Drupal\breakpoint\Plugin\Core\Entity\Breakpoint
*/ */
public $breakpoints = array(); public $breakpoints = array();
@ -71,7 +86,7 @@ class BreakpointGroup extends ConfigEntityBase {
* Breakpoint::SOURCE_TYPE_MODULE * Breakpoint::SOURCE_TYPE_MODULE
* Breakpoint::SOURCE_TYPE_USER_DEFINED * Breakpoint::SOURCE_TYPE_USER_DEFINED
* *
* @see Drupal\breakpoint\Breakpoint * @see Drupal\breakpoint\Plugin\Core\Entity\Breakpoint
*/ */
public $sourceType = Breakpoint::SOURCE_TYPE_USER_DEFINED; public $sourceType = Breakpoint::SOURCE_TYPE_USER_DEFINED;

View File

@ -7,7 +7,7 @@
namespace Drupal\breakpoint\Tests; namespace Drupal\breakpoint\Tests;
use Drupal\breakpoint\Tests\BreakpointsTestBase; use Drupal\breakpoint\Tests\BreakpointsTestBase;
use Drupal\breakpoint\Breakpoint; use Drupal\breakpoint\Plugin\Core\Entity\Breakpoint;
use Drupal\breakpoint\InvalidBreakpointNameException; use Drupal\breakpoint\InvalidBreakpointNameException;
use Drupal\breakpoint\InvalidBreakpointSourceException; use Drupal\breakpoint\InvalidBreakpointSourceException;
use Drupal\breakpoint\InvalidBreakpointSourceTypeException; use Drupal\breakpoint\InvalidBreakpointSourceTypeException;

View File

@ -7,7 +7,7 @@
namespace Drupal\breakpoint\Tests; namespace Drupal\breakpoint\Tests;
use Drupal\breakpoint\Tests\BreakpointTestBase; use Drupal\breakpoint\Tests\BreakpointTestBase;
use Drupal\breakpoint\Breakpoint; use Drupal\breakpoint\Plugin\Core\Entity\Breakpoint;
/** /**
* Tests for breakpoint CRUD operations. * Tests for breakpoint CRUD operations.

View File

@ -7,8 +7,8 @@
namespace Drupal\breakpoint\Tests; namespace Drupal\breakpoint\Tests;
use Drupal\breakpoint\Tests\BreakpointsTestBase; use Drupal\breakpoint\Tests\BreakpointsTestBase;
use Drupal\breakpoint\BreakpointGroup; use Drupal\breakpoint\Plugin\Core\Entity\BreakpointGroup;
use Drupal\breakpoint\Breakpoint; use Drupal\breakpoint\Plugin\Core\Entity\Breakpoint;
use Drupal\breakpoint\InvalidBreakpointNameException; use Drupal\breakpoint\InvalidBreakpointNameException;
use Drupal\breakpoint\InvalidBreakpointSourceException; use Drupal\breakpoint\InvalidBreakpointSourceException;
use Drupal\breakpoint\InvalidBreakpointSourceTypeException; use Drupal\breakpoint\InvalidBreakpointSourceTypeException;

View File

@ -7,8 +7,8 @@
namespace Drupal\breakpoint\Tests; namespace Drupal\breakpoint\Tests;
use Drupal\breakpoint\Tests\BreakpointGroupTestBase; use Drupal\breakpoint\Tests\BreakpointGroupTestBase;
use Drupal\breakpoint\BreakpointGroup; use Drupal\breakpoint\Plugin\Core\Entity\BreakpointGroup;
use Drupal\breakpoint\Breakpoint; use Drupal\breakpoint\Plugin\Core\Entity\Breakpoint;
/** /**
* Tests for breakpoint group CRUD operations. * Tests for breakpoint group CRUD operations.

View File

@ -7,7 +7,7 @@
namespace Drupal\breakpoint\Tests; namespace Drupal\breakpoint\Tests;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
use Drupal\breakpoint\BreakpointGroup; use Drupal\breakpoint\Plugin\Core\Entity\BreakpointGroup;
/** /**
* Base class for Breakpoint group tests. * Base class for Breakpoint group tests.

View File

@ -7,7 +7,7 @@
namespace Drupal\breakpoint\Tests; namespace Drupal\breakpoint\Tests;
use Drupal\simpletest\UnitTestBase; use Drupal\simpletest\UnitTestBase;
use Drupal\breakpoint\Breakpoint; use Drupal\breakpoint\Plugin\Core\Entity\Breakpoint;
use Drupal\breakpoint\InvalidBreakpointMediaQueryException; use Drupal\breakpoint\InvalidBreakpointMediaQueryException;
/** /**

View File

@ -7,7 +7,7 @@
namespace Drupal\breakpoint\Tests; namespace Drupal\breakpoint\Tests;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
use Drupal\breakpoint\Breakpoint; use Drupal\breakpoint\Plugin\Core\Entity\Breakpoint;
/** /**
* Base class for Breakpoint tests. * Base class for Breakpoint tests.

View File

@ -7,8 +7,8 @@
namespace Drupal\breakpoint\Tests; namespace Drupal\breakpoint\Tests;
use Drupal\breakpoint\Tests\BreakpointGroupTestBase; use Drupal\breakpoint\Tests\BreakpointGroupTestBase;
use Drupal\breakpoint\BreakpointGroup; use Drupal\breakpoint\Plugin\Core\Entity\BreakpointGroup;
use Drupal\breakpoint\Breakpoint; use Drupal\breakpoint\Plugin\Core\Entity\Breakpoint;
/** /**
* Test breakpoints provided by themes. * Test breakpoints provided by themes.

View File

@ -5,7 +5,7 @@
* Admin page callbacks for the Comment module. * Admin page callbacks for the Comment module.
*/ */
use Drupal\comment\Comment; use Drupal\comment\Plugin\Core\Entity\Comment;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**

View File

@ -9,8 +9,8 @@
* book page, etc. * book page, etc.
*/ */
use Drupal\node\Node; use Drupal\node\Plugin\Core\Entity\Node;
use Drupal\file\File; use Drupal\file\Plugin\Core\Entity\File;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@ -76,7 +76,7 @@ const COMMENT_NODE_CLOSED = 1;
*/ */
const COMMENT_NODE_OPEN = 2; const COMMENT_NODE_OPEN = 2;
use Drupal\comment\Comment; use Drupal\comment\Plugin\Core\Entity\Comment;
/** /**
* Implements hook_help(). * Implements hook_help().
@ -98,40 +98,11 @@ function comment_help($path, $arg) {
} }
/** /**
* Implements hook_entity_info(). * Implements hook_entity_info_alter().
*/ */
function comment_entity_info() { function comment_entity_info_alter(&$info) {
$return = array(
'comment' => array(
'label' => t('Comment'),
'base table' => 'comment',
'uri callback' => 'comment_uri',
'fieldable' => TRUE,
'controller class' => 'Drupal\comment\CommentStorageController',
'form controller class' => array(
'default' => 'Drupal\comment\CommentFormController',
),
'entity class' => 'Drupal\comment\Comment',
'entity keys' => array(
'id' => 'cid',
'bundle' => 'node_type',
'label' => 'subject',
'uuid' => 'uuid',
),
'bundles' => array(),
'render controller class' => 'Drupal\comment\CommentRenderController',
'view modes' => array(
'full' => array(
'label' => t('Full comment'),
'custom settings' => FALSE,
),
),
'static cache' => FALSE,
),
);
foreach (node_type_get_names() as $type => $name) { foreach (node_type_get_names() as $type => $name) {
$return['comment']['bundles']['comment_node_' . $type] = array( $info['comment']['bundles']['comment_node_' . $type] = array(
'label' => t('@node_type comment', array('@node_type' => $name)), 'label' => t('@node_type comment', array('@node_type' => $name)),
// Provide the node type/bundle name for other modules, so it does not // Provide the node type/bundle name for other modules, so it does not
// have to be extracted manually from the bundle name. // have to be extracted manually from the bundle name.
@ -150,8 +121,6 @@ function comment_entity_info() {
), ),
); );
} }
return $return;
} }
/** /**

View File

@ -5,7 +5,7 @@
* User page callbacks for the Comment module. * User page callbacks for the Comment module.
*/ */
use Drupal\node\Node; use Drupal\node\Plugin\Core\Entity\Node;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

View File

@ -2,16 +2,45 @@
/** /**
* @file * @file
* Definition of Drupal\comment\Comment. * Definition of Drupal\comment\Plugin\Core\Entity\Comment.
*/ */
namespace Drupal\comment; namespace Drupal\comment\Plugin\Core\Entity;
use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\Entity; use Drupal\Core\Entity\Entity;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/** /**
* Defines the comment entity class. * Defines the comment entity class.
*
* @Plugin(
* id = "comment",
* label = @Translation("Comment"),
* module = "comment",
* controller_class = "Drupal\comment\CommentStorageController",
* render_controller_class = "Drupal\comment\CommentRenderController",
* form_controller_class = {
* "default" = "Drupal\comment\CommentFormController"
* },
* base_table = "comment",
* uri_callback = "comment_uri",
* fieldable = TRUE,
* static_cache = FALSE,
* entity_keys = {
* "id" = "cid",
* "bundle" = "node_type",
* "label" = "subject",
* "uuid" = "uuid"
* },
* view_modes = {
* "full" = {
* "label" = "Full comment",
* "custom_settings" = FALSE
* }
* }
* )
*/ */
class Comment extends Entity implements ContentEntityInterface { class Comment extends Entity implements ContentEntityInterface {

View File

@ -81,8 +81,8 @@ class Rss extends RowPluginBase {
function options_form_summary_options() { function options_form_summary_options() {
$entity_info = entity_get_info('node'); $entity_info = entity_get_info('node');
$options = array(); $options = array();
if (!empty($entity_info['view modes'])) { if (!empty($entity_info['view_modes'])) {
foreach ($entity_info['view modes'] as $mode => $settings) { foreach ($entity_info['view_modes'] as $mode => $settings) {
$options[$mode] = $settings['label']; $options[$mode] = $settings['label'];
} }
} }

View File

@ -7,7 +7,7 @@
namespace Drupal\comment\Tests; namespace Drupal\comment\Tests;
use Drupal\comment\Comment; use Drupal\comment\Plugin\Core\Entity\Comment;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
/** /**

View File

@ -69,7 +69,7 @@ function hook_config_import_change($name, $new_config, $old_config) {
// @todo Make this less ugly. // @todo Make this less ugly.
list($entity_type) = explode('.', $name); list($entity_type) = explode('.', $name);
$entity_info = entity_get_info($entity_type); $entity_info = entity_get_info($entity_type);
$id = substr($name, strlen($entity_info['config prefix']) + 1); $id = substr($name, strlen($entity_info['config_prefix']) + 1);
$config_test = entity_load('config_test', $id); $config_test = entity_load('config_test', $id);
// Store the original config, and iterate through each property to store it. // Store the original config, and iterate through each property to store it.
@ -119,7 +119,7 @@ function hook_config_import_delete($name, $new_config, $old_config) {
// config objects as a standard? // config objects as a standard?
list($entity_type) = explode('.', $name); list($entity_type) = explode('.', $name);
$entity_info = entity_get_info($entity_type); $entity_info = entity_get_info($entity_type);
$id = substr($name, strlen($entity_info['config prefix']) + 1); $id = substr($name, strlen($entity_info['config_prefix']) + 1);
config_test_delete($id); config_test_delete($id);
return TRUE; return TRUE;
} }

View File

@ -8,7 +8,7 @@
namespace Drupal\config\Tests; namespace Drupal\config\Tests;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
use Drupal\config_test\ConfigTest; use Drupal\config_test\Plugin\Core\Entity\ConfigTest;
use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\Core\Entity\EntityStorageControllerInterface;
/** /**

View File

@ -5,7 +5,7 @@
* Provides Config module hook implementations for testing purposes. * Provides Config module hook implementations for testing purposes.
*/ */
use Drupal\config_test\ConfigTest; use Drupal\config_test\Plugin\Core\Entity\ConfigTest;
require_once dirname(__FILE__) . '/config_test.hooks.inc'; require_once dirname(__FILE__) . '/config_test.hooks.inc';
@ -71,33 +71,10 @@ function config_test_config_import_delete($name, $new_config, $old_config) {
return TRUE; return TRUE;
} }
/**
* Implements hook_entity_info().
*/
function config_test_entity_info() {
$types['config_test'] = array(
'label' => 'Test configuration',
'controller class' => 'Drupal\Core\Config\Entity\ConfigStorageController',
'entity class' => 'Drupal\config_test\ConfigTest',
'list controller class' => 'Drupal\Core\Config\Entity\ConfigEntityListController',
'form controller class' => array(
'default' => 'Drupal\config_test\ConfigTestFormController',
),
'uri callback' => 'config_test_uri',
'config prefix' => 'config_test.dynamic',
'entity keys' => array(
'id' => 'id',
'label' => 'label',
'uuid' => 'uuid',
),
);
return $types;
}
/** /**
* Entity URI callback. * Entity URI callback.
* *
* @param Drupal\config_test\ConfigTest $config_test * @param Drupal\config_test\Plugin\Core\Entity\ConfigTest $config_test
* A ConfigTest entity. * A ConfigTest entity.
*/ */
function config_test_uri(ConfigTest $config_test) { function config_test_uri(ConfigTest $config_test) {
@ -174,7 +151,7 @@ function config_test_add_page() {
/** /**
* Page callback: Presents the ConfigTest edit form. * Page callback: Presents the ConfigTest edit form.
* *
* @param Drupal\config_test\ConfigTest $config_test * @param Drupal\config_test\Plugin\Core\Entity\ConfigTest $config_test
* The ConfigTest object to edit. * The ConfigTest object to edit.
* *
* @return array * @return array
@ -188,7 +165,7 @@ function config_test_edit_page(ConfigTest $config_test) {
/** /**
* Form constructor to delete a ConfigTest object. * Form constructor to delete a ConfigTest object.
* *
* @param Drupal\config_test\ConfigTest $config_test * @param Drupal\config_test\Plugin\Core\Entity\ConfigTest $config_test
* The ConfigTest object to delete. * The ConfigTest object to delete.
*/ */
function config_test_delete_form($form, &$form_state, ConfigTest $config_test) { function config_test_delete_form($form, &$form_state, ConfigTest $config_test) {

View File

@ -1,45 +0,0 @@
<?php
/**
* @file
* Definition of Drupal\config_test\ConfigTest.
*/
namespace Drupal\config_test;
use Drupal\Core\Config\Entity\ConfigEntityBase;
/**
* Defines the ConfigTest configuration entity.
*/
class ConfigTest extends ConfigEntityBase {
/**
* The machine name for the configuration entity.
*
* @var string
*/
public $id;
/**
* The UUID for the configuration entity.
*
* @var string
*/
public $uuid;
/**
* The human-readable name of the configuration entity.
*
* @var string
*/
public $label;
/**
* The image style to use.
*
* @var string
*/
public $style;
}

View File

@ -0,0 +1,65 @@
<?php
/**
* @file
* Definition of Drupal\config_test\Plugin\Core\Entity\ConfigTest.
*/
namespace Drupal\config_test\Plugin\Core\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/**
* Defines the ConfigTest configuration entity.
*
* @Plugin(
* id = "config_test",
* label = @Translation("Test configuration"),
* module = "config_test",
* controller_class = "Drupal\Core\Config\Entity\ConfigStorageController",
* list_controller_class = "Drupal\Core\Config\Entity\ConfigEntityListController",
* form_controller_class = {
* "default" = "Drupal\config_test\ConfigTestFormController"
* },
* uri_callback = "config_test_uri",
* config_prefix = "config_test.dynamic",
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "uuid" = "uuid"
* }
* )
*/
class ConfigTest extends ConfigEntityBase {
/**
* The machine name for the configuration entity.
*
* @var string
*/
public $id;
/**
* The UUID for the configuration entity.
*
* @var string
*/
public $uuid;
/**
* The human-readable name of the configuration entity.
*
* @var string
*/
public $label;
/**
* The image style to use.
*
* @var string
*/
public $style;
}

View File

@ -5,7 +5,7 @@
* Admin page callbacks for the Contact module. * Admin page callbacks for the Contact module.
*/ */
use Drupal\contact\Category; use Drupal\contact\Plugin\Core\Entity\Category;
/** /**
* Page callback: Lists contact categories. * Page callback: Lists contact categories.
@ -35,7 +35,7 @@ function contact_category_add() {
/** /**
* Page callback: Form constructor for the contact category deletion form. * Page callback: Form constructor for the contact category deletion form.
* *
* @param Drupal\contact\Category $category * @param Drupal\contact\Plugin\Core\Entity\Category $category
* The contact category to be deleted. * The contact category to be deleted.
* *
* @see contact_menu() * @see contact_menu()

View File

@ -5,7 +5,7 @@
* Enables the use of personal and site-wide contact forms. * Enables the use of personal and site-wide contact forms.
*/ */
use Drupal\contact\Category; use Drupal\contact\Plugin\Core\Entity\Category;
/** /**
* Implements hook_help(). * Implements hook_help().
@ -201,36 +201,13 @@ function contact_config_import_delete($name, $new_config, $old_config) {
return TRUE; return TRUE;
} }
/**
* Implements hook_entity_info().
*/
function contact_entity_info() {
$types['contact_category'] = array(
'label' => 'Category',
'entity class' => 'Drupal\contact\Category',
'controller class' => 'Drupal\Core\Config\Entity\ConfigStorageController',
'list controller class' => 'Drupal\contact\CategoryListController',
'form controller class' => array(
'default' => 'Drupal\contact\CategoryFormController',
),
'uri callback' => 'contact_category_uri',
'config prefix' => 'contact.category',
'entity keys' => array(
'id' => 'id',
'label' => 'label',
'uuid' => 'uuid',
),
);
return $types;
}
/** /**
* Loads a contact category. * Loads a contact category.
* *
* @param $id * @param $id
* The ID of the contact category to load. * The ID of the contact category to load.
* *
* @return Drupal\contact\Category|false * @return Drupal\contact\Plugin\Core\Entity\Category|false
* A Category object or FALSE if the requested $id does not exist. * A Category object or FALSE if the requested $id does not exist.
*/ */
function contact_category_load($id) { function contact_category_load($id) {

View File

@ -1,59 +0,0 @@
<?php
/**
* @file
* Definition of Drupal\contact\Category.
*/
namespace Drupal\contact;
use Drupal\Core\Config\Entity\ConfigEntityBase;
/**
* Defines the contact category entity.
*/
class Category extends ConfigEntityBase {
/**
* The category ID.
*
* @var string
*/
public $id;
/**
* The category UUID.
*
* @var string
*/
public $uuid;
/**
* The category label.
*
* @var string
*/
public $label;
/**
* List of recipient e-mail addresses.
*
* @var array
*/
public $recipients = array();
/**
* An auto-reply message to send to the message author.
*
* @var string
*/
public $reply = '';
/**
* Weight of this category (used for sorting).
*
* @var int
*/
public $weight = 0;
}

View File

@ -0,0 +1,79 @@
<?php
/**
* @file
* Definition of Drupal\contact\Plugin\Core\Entity\Category.
*/
namespace Drupal\contact\Plugin\Core\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/**
* Defines the contact category entity.
*
* @Plugin(
* id = "contact_category",
* label = @Translation("Category"),
* module = "contact",
* controller_class = "Drupal\Core\Config\Entity\ConfigStorageController",
* list_controller_class = "Drupal\contact\CategoryListController",
* form_controller_class = {
* "default" = "Drupal\contact\CategoryFormController"
* },
* uri_callback = "contact_category_uri",
* config_prefix = "contact.category",
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "uuid" = "uuid"
* }
* )
*/
class Category extends ConfigEntityBase {
/**
* The category ID.
*
* @var string
*/
public $id;
/**
* The category UUID.
*
* @var string
*/
public $uuid;
/**
* The category label.
*
* @var string
*/
public $label;
/**
* List of recipient e-mail addresses.
*
* @var array
*/
public $recipients = array();
/**
* An auto-reply message to send to the message author.
*
* @var string
*/
public $reply = '';
/**
* Weight of this category (used for sorting).
*
* @var int
*/
public $weight = 0;
}

View File

@ -60,19 +60,23 @@ const FIELD_STORAGE_INSERT = 'insert';
* of the fieldable entity, such as 'node' or 'user', and $entity is the entity * of the fieldable entity, such as 'node' or 'user', and $entity is the entity
* itself. * itself.
* *
* hook_entity_info() is the central place for entity types to define if and how * An entity plugin's annotation is how entity types define if and how
* Field API should operate on their entity objects. Notably, the 'fieldable' * Field API should operate on their entity objects. Notably, the 'fieldable'
* property needs to be set to TRUE. * property needs to be set to TRUE.
* *
* The Field Attach API uses the concept of bundles: the set of fields for a * The Field Attach API uses the concept of bundles: the set of fields for a
* given entity is defined on a per-bundle basis. The collection of bundles for * given entity is defined on a per-bundle basis. The collection of bundles for
* an entity type is defined its hook_entity_info() implementation. For * an entity type is added to the entity definition with
* instance, node_entity_info() exposes each node type as its own bundle. This * hook_entity_info_alter(). For instance, node_entity_info_alter() exposes
* means that the set of fields of a node is determined by the node type. The * each node type as its own bundle. This means that the set of fields of a
* Field API reads the bundle name for a given entity from a particular property * node is determined by the node type.
* of the entity object, and hook_entity_info() defines which property to use. *
* For instance, node_entity_info() specifies: * The Field API reads the bundle name for a given entity from a particular
* @code $info['entity keys']['bundle'] = 'type'@endcode * property of the entity object, and hook_entity_info_alter() defines which
* property to use. For instance, node_entity_info_alter() specifies:
* @code
* $info['entity_keys']['bundle'] = 'type'
* @endcode
* This indicates that for a particular node object, the bundle name can be * This indicates that for a particular node object, the bundle name can be
* found in $node->type. This property can be omitted if the entity type only * found in $node->type. This property can be omitted if the entity type only
* exposes a single bundle (all entities of this type have the same collection * exposes a single bundle (all entities of this type have the same collection
@ -903,7 +907,7 @@ function field_attach_load($entity_type, $entities, $age = FIELD_LOAD_CURRENT, $
$info = entity_get_info($entity_type); $info = entity_get_info($entity_type);
// Only the most current revision of non-deleted fields for cacheable entity // Only the most current revision of non-deleted fields for cacheable entity
// types can be cached. // types can be cached.
$cache_read = $load_current && $info['field cache'] && empty($options['deleted']); $cache_read = $load_current && $info['field_cache'] && empty($options['deleted']);
// In addition, do not write to the cache when loading a single field. // In addition, do not write to the cache when loading a single field.
$cache_write = $cache_read && !isset($options['field_id']); $cache_write = $cache_read && !isset($options['field_id']);
@ -1271,7 +1275,7 @@ function field_attach_update($entity_type, EntityInterface $entity) {
module_invoke_all('field_attach_update', $entity_type, $entity); module_invoke_all('field_attach_update', $entity_type, $entity);
$entity_info = entity_get_info($entity_type); $entity_info = entity_get_info($entity_type);
if ($entity_info['field cache']) { if ($entity_info['field_cache']) {
cache('field')->delete("field:$entity_type:" . $entity->id()); cache('field')->delete("field:$entity_type:" . $entity->id());
} }
} }
@ -1306,7 +1310,7 @@ function field_attach_delete($entity_type, $entity) {
module_invoke_all('field_attach_delete', $entity_type, $entity); module_invoke_all('field_attach_delete', $entity_type, $entity);
$entity_info = entity_get_info($entity_type); $entity_info = entity_get_info($entity_type);
if ($entity_info['field cache']) { if ($entity_info['field_cache']) {
cache('field')->delete("field:$entity_type:" . $entity->id()); cache('field')->delete("field:$entity_type:" . $entity->id());
} }
} }

View File

@ -90,7 +90,7 @@ function field_create_field($field) {
// collisions with existing entity properties, but some is better // collisions with existing entity properties, but some is better
// than none. // than none.
foreach (entity_get_info() as $type => $info) { foreach (entity_get_info() as $type => $info) {
if (in_array($field['field_name'], $info['entity keys'])) { if (in_array($field['field_name'], $info['entity_keys'])) {
throw new FieldException(t('Attempt to create field name %name which is reserved by entity type %type.', array('%name' => $field['field_name'], '%type' => $type))); throw new FieldException(t('Attempt to create field name %name which is reserved by entity type %type.', array('%name' => $field['field_name'], '%type' => $type)));
} }
} }
@ -888,7 +888,7 @@ function field_purge_batch($batch_size) {
// Retrieve some entities. // Retrieve some entities.
$results = $factory->get($entity_type) $results = $factory->get($entity_type)
->condition('id:' . $field['id'] . '.deleted', 1) ->condition('id:' . $field['id'] . '.deleted', 1)
->condition($info[$entity_type]['entity keys']['bundle'], $ids->bundle) ->condition($info[$entity_type]['entity_keys']['bundle'], $ids->bundle)
->range(0, $batch_size) ->range(0, $batch_size)
->execute(); ->execute();

View File

@ -740,11 +740,11 @@ function field_view_mode_settings($entity_type, $bundle) {
$bundle_settings = field_bundle_settings($entity_type, $bundle); $bundle_settings = field_bundle_settings($entity_type, $bundle);
$settings = $bundle_settings['view_modes']; $settings = $bundle_settings['view_modes'];
// Include view modes for which nothing has been stored yet, but whose // Include view modes for which nothing has been stored yet, but whose
// definition in hook_entity_info() specify they should use custom settings // definition in hook_entity_info_alter() specify they should use custom
// by default. // settings by default.
$entity_info = entity_get_info($entity_type); $entity_info = entity_get_info($entity_type);
foreach ($entity_info['view modes'] as $view_mode => $view_mode_info) { foreach ($entity_info['view_modes'] as $view_mode => $view_mode_info) {
if (!isset($settings[$view_mode]['custom_settings']) && $view_mode_info['custom settings']) { if (!isset($settings[$view_mode]['custom_settings']) && $view_mode_info['custom_settings']) {
$settings[$view_mode]['custom_settings'] = TRUE; $settings[$view_mode]['custom_settings'] = TRUE;
} }
} }
@ -1123,8 +1123,8 @@ function field_extract_bundle($entity_type, $bundle) {
} }
$info = entity_get_info($entity_type); $info = entity_get_info($entity_type);
if (is_object($bundle) && isset($info['bundle keys']['bundle']) && isset($bundle->{$info['bundle keys']['bundle']})) { if (is_object($bundle) && isset($info['bundle_keys']['bundle']) && isset($bundle->{$info['bundle_keys']['bundle']})) {
return $bundle->{$info['bundle keys']['bundle']}; return $bundle->{$info['bundle_keys']['bundle']};
} }
} }
@ -1308,12 +1308,12 @@ function theme_field($variables) {
function _field_create_entity_from_ids($ids) { function _field_create_entity_from_ids($ids) {
$id_properties = array(); $id_properties = array();
$info = entity_get_info($ids->entity_type); $info = entity_get_info($ids->entity_type);
$id_properties[$info['entity keys']['id']] = $ids->entity_id; $id_properties[$info['entity_keys']['id']] = $ids->entity_id;
if (!empty($info['entity keys']['revision']) && isset($ids->revision_id)) { if (!empty($info['entity_keys']['revision']) && isset($ids->revision_id)) {
$id_properties[$info['entity keys']['revision']] = $ids->revision_id; $id_properties[$info['entity_keys']['revision']] = $ids->revision_id;
} }
if (!empty($info['entity keys']['bundle']) && isset($ids->bundle)) { if (!empty($info['entity_keys']['bundle']) && isset($ids->bundle)) {
$id_properties[$info['entity keys']['bundle']] = $ids->bundle; $id_properties[$info['entity_keys']['bundle']] = $ids->bundle;
} }
return entity_create($ids->entity_type, $id_properties); return entity_create($ids->entity_type, $id_properties);
} }

View File

@ -29,7 +29,7 @@
* calling field_is_translatable(), which checks the $field['translatable'] * calling field_is_translatable(), which checks the $field['translatable']
* property returned by field_info_field(), and whether there is at least one * property returned by field_info_field(), and whether there is at least one
* translation handler available for the field. A translation handler is a * translation handler available for the field. A translation handler is a
* module registering itself via hook_entity_info() to handle field * module registering itself via hook_entity_info_alter() to handle field
* translations. * translations.
* *

View File

@ -125,15 +125,15 @@ function field_views_field_default_views_data($field) {
$group_name = $groups[$entity]; $group_name = $groups[$entity];
} }
$entity_tables[$entity_info['base table']] = $entity; $entity_tables[$entity_info['base_table']] = $entity;
$current_tables[$entity] = $entity_info['base table']; $current_tables[$entity] = $entity_info['base_table'];
if (isset($entity_info['revision table'])) { if (isset($entity_info['revision_table'])) {
$entity_tables[$entity_info['revision table']] = $entity; $entity_tables[$entity_info['revision_table']] = $entity;
$revision_tables[$entity] = $entity_info['revision table']; $revision_tables[$entity] = $entity_info['revision_table'];
} }
$data[$current_table]['table']['join'][$entity_info['base table']] = array( $data[$current_table]['table']['join'][$entity_info['base_table']] = array(
'left_field' => $entity_info['entity keys']['id'], 'left_field' => $entity_info['entity_keys']['id'],
'field' => 'entity_id', 'field' => 'entity_id',
'extra' => array( 'extra' => array(
array('field' => 'entity_type', 'value' => $entity), array('field' => 'entity_type', 'value' => $entity),
@ -141,9 +141,9 @@ function field_views_field_default_views_data($field) {
), ),
); );
if (!empty($entity_info['entity keys']['revision']) && !empty($entity_info['revision table'])) { if (!empty($entity_info['entity_keys']['revision']) && !empty($entity_info['revision_table'])) {
$data[$revision_table]['table']['join'][$entity_info['revision table']] = array( $data[$revision_table]['table']['join'][$entity_info['revision_table']] = array(
'left_field' => $entity_info['entity keys']['revision'], 'left_field' => $entity_info['entity_keys']['revision'],
'field' => 'revision_id', 'field' => 'revision_id',
'extra' => array( 'extra' => array(
array('field' => 'entity_type', 'value' => $entity), array('field' => 'entity_type', 'value' => $entity),

View File

@ -549,7 +549,7 @@ class FieldInfo {
$data = $extra_fields['display']; $data = $extra_fields['display'];
foreach ($extra_fields['display'] as $name => $field_data) { foreach ($extra_fields['display'] as $name => $field_data) {
$settings = isset($bundle_settings['extra_fields']['display'][$name]) ? $bundle_settings['extra_fields']['display'][$name] : array(); $settings = isset($bundle_settings['extra_fields']['display'][$name]) ? $bundle_settings['extra_fields']['display'][$name] : array();
$view_modes = array_merge(array('default'), array_keys($entity_type_info['view modes'])); $view_modes = array_merge(array('default'), array_keys($entity_type_info['view_modes']));
foreach ($view_modes as $view_mode) { foreach ($view_modes as $view_mode) {
if (isset($settings[$view_mode])) { if (isset($settings[$view_mode])) {
$field_data['display'][$view_mode] = $settings[$view_mode]; $field_data['display'][$view_mode] = $settings[$view_mode];

View File

@ -423,8 +423,7 @@ class FieldAttachStorageTest extends FieldAttachTestBase {
* Test field_attach_create_bundle() and field_attach_rename_bundle(). * Test field_attach_create_bundle() and field_attach_rename_bundle().
*/ */
function testFieldAttachCreateRenameBundle() { function testFieldAttachCreateRenameBundle() {
// Create a new bundle. This has to be initiated by the module so that its // Create a new bundle.
// hook_entity_info() is consistent.
$new_bundle = 'test_bundle_' . drupal_strtolower($this->randomName()); $new_bundle = 'test_bundle_' . drupal_strtolower($this->randomName());
field_test_create_bundle($new_bundle); field_test_create_bundle($new_bundle);
@ -445,8 +444,7 @@ class FieldAttachStorageTest extends FieldAttachTestBase {
field_attach_load($entity_type, array(0 => $entity)); field_attach_load($entity_type, array(0 => $entity));
$this->assertEqual(count($entity->{$this->field_name}[$langcode]), $this->field['cardinality'], "Data is retrieved for the new bundle"); $this->assertEqual(count($entity->{$this->field_name}[$langcode]), $this->field['cardinality'], "Data is retrieved for the new bundle");
// Rename the bundle. This has to be initiated by the module so that its // Rename the bundle.
// hook_entity_info() is consistent.
$new_bundle = 'test_bundle_' . drupal_strtolower($this->randomName()); $new_bundle = 'test_bundle_' . drupal_strtolower($this->randomName());
field_test_rename_bundle($this->instance['bundle'], $new_bundle); field_test_rename_bundle($this->instance['bundle'], $new_bundle);
@ -464,8 +462,7 @@ class FieldAttachStorageTest extends FieldAttachTestBase {
* Test field_attach_delete_bundle(). * Test field_attach_delete_bundle().
*/ */
function testFieldAttachDeleteBundle() { function testFieldAttachDeleteBundle() {
// Create a new bundle. This has to be initiated by the module so that its // Create a new bundle.
// hook_entity_info() is consistent.
$new_bundle = 'test_bundle_' . drupal_strtolower($this->randomName()); $new_bundle = 'test_bundle_' . drupal_strtolower($this->randomName());
field_test_create_bundle($new_bundle); field_test_create_bundle($new_bundle);
@ -505,8 +502,7 @@ class FieldAttachStorageTest extends FieldAttachTestBase {
$this->assertEqual(count($entity->{$this->field_name}[$langcode]), 4, 'First field got loaded'); $this->assertEqual(count($entity->{$this->field_name}[$langcode]), 4, 'First field got loaded');
$this->assertEqual(count($entity->{$field_name}[$langcode]), 1, 'Second field got loaded'); $this->assertEqual(count($entity->{$field_name}[$langcode]), 1, 'Second field got loaded');
// Delete the bundle. This has to be initiated by the module so that its // Delete the bundle.
// hook_entity_info() is consistent.
field_test_delete_bundle($this->instance['bundle']); field_test_delete_bundle($this->instance['bundle']);
// Verify no data gets loaded // Verify no data gets loaded

View File

@ -47,13 +47,13 @@ class Query extends QueryBase {
public function execute() { public function execute() {
$entity_type = $this->entityType; $entity_type = $this->entityType;
$entity_info = entity_get_info($entity_type); $entity_info = entity_get_info($entity_type);
if (!isset($entity_info['base table'])) { if (!isset($entity_info['base_table'])) {
throw new QueryException("No base table, nothing to query."); throw new QueryException("No base table, nothing to query.");
} }
$configurable_fields = array_map(function ($data) use ($entity_type) { $configurable_fields = array_map(function ($data) use ($entity_type) {
return isset($data['bundles'][$entity_type]); return isset($data['bundles'][$entity_type]);
}, field_info_field_map()); }, field_info_field_map());
$base_table = $entity_info['base table']; $base_table = $entity_info['base_table'];
// Assemble a list of entity tables, primarily for use in // Assemble a list of entity tables, primarily for use in
// \Drupal\field_sql_storage\Entity\Tables::ensureEntityTable(). // \Drupal\field_sql_storage\Entity\Tables::ensureEntityTable().
$entity_tables = array(); $entity_tables = array();
@ -62,8 +62,8 @@ class Query extends QueryBase {
// from the data table or the base table based on where it finds the // from the data table or the base table based on where it finds the
// property first. The data table is prefered, which is why it gets added // property first. The data table is prefered, which is why it gets added
// before the base table. // before the base table.
if (isset($entity_info['data table'])) { if (isset($entity_info['data_table'])) {
$entity_tables[$entity_info['data table']] = drupal_get_schema($entity_info['data table']); $entity_tables[$entity_info['data_table']] = drupal_get_schema($entity_info['data_table']);
$simple_query = FALSE; $simple_query = FALSE;
} }
$entity_tables[$base_table] = drupal_get_schema($base_table); $entity_tables[$base_table] = drupal_get_schema($base_table);
@ -73,17 +73,17 @@ class Query extends QueryBase {
// id key or the revision id key, depending on whether the entity type // id key or the revision id key, depending on whether the entity type
// supports revisions. // supports revisions.
$id_key = 'id'; $id_key = 'id';
$id_field = $entity_info['entity keys']['id']; $id_field = $entity_info['entity_keys']['id'];
$fields[$id_field] = TRUE; $fields[$id_field] = TRUE;
if (empty($entity_info['entity keys']['revision'])) { if (empty($entity_info['entity_keys']['revision'])) {
// Add the key field for fetchAllKeyed(). When there is no revision // Add the key field for fetchAllKeyed(). When there is no revision
// support, this is the entity key. // support, this is the entity key.
$sqlQuery->addField('base_table', $entity_info['entity keys']['id']); $sqlQuery->addField('base_table', $entity_info['entity_keys']['id']);
} }
else { else {
// Add the key field for fetchAllKeyed(). When there is revision // Add the key field for fetchAllKeyed(). When there is revision
// support, this is the revision key. // support, this is the revision key.
$revision_field = $entity_info['entity keys']['revision']; $revision_field = $entity_info['entity_keys']['revision'];
$fields[$revision_field] = TRUE; $fields[$revision_field] = TRUE;
$sqlQuery->addField('base_table', $revision_field); $sqlQuery->addField('base_table', $revision_field);
// Now revision id is column 0 and the value column is 1. // Now revision id is column 0 and the value column is 1.
@ -105,7 +105,7 @@ class Query extends QueryBase {
$sqlQuery->addMetaData('age', $this->age); $sqlQuery->addMetaData('age', $this->age);
// This contains the relevant SQL field to be used when joining entity // This contains the relevant SQL field to be used when joining entity
// tables. // tables.
$sqlQuery->addMetaData('entity_id_field', $entity_info['entity keys'][$id_key]); $sqlQuery->addMetaData('entity_id_field', $entity_info['entity_keys'][$id_key]);
// This contains the relevant SQL field to be used when joining field // This contains the relevant SQL field to be used when joining field
// tables. // tables.
$sqlQuery->addMetaData('field_id_field', $id_key == 'id' ? 'entity_id' : 'revision_id'); $sqlQuery->addMetaData('field_id_field', $id_key == 'id' ? 'entity_id' : 'revision_id');

View File

@ -6,141 +6,7 @@
*/ */
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\field_test\TestEntity; use Drupal\field_test\Plugin\Core\Entity\TestEntity;
/**
* Implements hook_entity_info().
*/
function field_test_entity_info() {
$bundles = variable_get('field_test_bundles', array('test_bundle' => array('label' => 'Test Bundle')));
$test_entity_modes = array(
'full' => array(
'label' => t('Full object'),
'custom settings' => TRUE,
),
'teaser' => array(
'label' => t('Teaser'),
'custom settings' => TRUE,
),
);
return array(
'test_entity' => array(
'label' => t('Test Entity'),
'entity class' => 'Drupal\field_test\TestEntity',
'controller class' => 'Drupal\field_test\TestEntityController',
'form controller class' => array(
'default' => 'Drupal\field_test\TestEntityFormController',
),
'fieldable' => TRUE,
'field cache' => FALSE,
'base table' => 'test_entity',
'revision table' => 'test_entity_revision',
'entity keys' => array(
'id' => 'ftid',
'revision' => 'ftvid',
'bundle' => 'fttype',
),
'bundles' => $bundles,
'view modes' => $test_entity_modes,
),
// This entity type doesn't get form handling for now...
'test_cacheable_entity' => array(
'label' => t('Test Entity, cacheable'),
'entity class' => 'Drupal\field_test\TestEntity',
'controller class' => 'Drupal\field_test\TestEntityController',
'fieldable' => TRUE,
'field cache' => TRUE,
'entity keys' => array(
'id' => 'ftid',
'revision' => 'ftvid',
'bundle' => 'fttype',
),
'bundles' => $bundles,
'view modes' => $test_entity_modes,
),
'test_entity_bundle_key' => array(
'entity class' => 'Drupal\field_test\TestEntity',
'controller class' => 'Drupal\field_test\TestEntityController',
'label' => t('Test Entity with a bundle key.'),
'base table' => 'test_entity_bundle_key',
'fieldable' => TRUE,
'field cache' => FALSE,
'entity keys' => array(
'id' => 'ftid',
'bundle' => 'fttype',
),
'bundles' => array('bundle1' => array('label' => 'Bundle1'), 'bundle2' => array('label' => 'Bundle2')) + $bundles,
'view modes' => $test_entity_modes,
),
// In this case, the bundle key is not stored in the database.
'test_entity_bundle' => array(
'label' => t('Test Entity with a specified bundle.'),
'entity class' => 'Drupal\field_test\TestEntity',
'controller class' => 'Drupal\field_test\TestEntityController',
'base table' => 'test_entity_bundle',
'fieldable' => TRUE,
'field cache' => FALSE,
'entity keys' => array(
'id' => 'ftid',
'bundle' => 'fttype',
),
'bundles' => array('test_entity_2' => array('label' => 'Test entity 2')) + $bundles,
'view modes' => $test_entity_modes,
),
// @see EntityPropertiesTestCase::testEntityLabel()
'test_entity_no_label' => array(
'label' => t('Test entity without label'),
'entity class' => 'Drupal\field_test\TestEntity',
'controller class' => 'Drupal\field_test\TestEntityController',
'fieldable' => TRUE,
'field cache' => FALSE,
'base table' => 'test_entity',
'revision table' => 'test_entity_revision',
'entity keys' => array(
'id' => 'ftid',
'revision' => 'ftvid',
'bundle' => 'fttype',
),
'bundles' => $bundles,
'view modes' => $test_entity_modes,
),
'test_entity_label' => array(
'label' => t('Test entity label'),
'entity class' => 'Drupal\field_test\TestEntity',
'controller class' => 'Drupal\field_test\TestEntityController',
'fieldable' => TRUE,
'field cache' => FALSE,
'base table' => 'test_entity',
'revision table' => 'test_entity_revision',
'entity keys' => array(
'id' => 'ftid',
'revision' => 'ftvid',
'bundle' => 'fttype',
'label' => 'ftlabel',
),
'bundles' => $bundles,
'view modes' => $test_entity_modes,
),
'test_entity_label_callback' => array(
'label' => t('Test entity label callback'),
'entity class' => 'Drupal\field_test\TestEntity',
'controller class' => 'Drupal\field_test\TestEntityController',
'fieldable' => TRUE,
'field cache' => FALSE,
'base table' => 'test_entity',
'revision table' => 'test_entity_revision',
'label callback' => 'field_test_entity_label_callback',
'entity keys' => array(
'id' => 'ftid',
'revision' => 'ftvid',
'bundle' => 'fttype',
),
'bundles' => $bundles,
'view modes' => $test_entity_modes,
),
);
}
/** /**
* Implements hook_entity_info_alter(). * Implements hook_entity_info_alter().
@ -153,6 +19,25 @@ function field_test_entity_info_alter(&$entity_info) {
// Disable the entity type translation handler. // Disable the entity type translation handler.
foreach ($entity_info as $entity_type => $info) { foreach ($entity_info as $entity_type => $info) {
$entity_info[$entity_type]['translation'][$entity_type] = FALSE; $entity_info[$entity_type]['translation'][$entity_type] = FALSE;
if ($info['module'] == 'field_test') {
$entity_info[$entity_type]['view_modes'] = array(
'full' => array(
'label' => t('Full object'),
'custom_settings' => TRUE,
),
'teaser' => array(
'label' => t('Teaser'),
'custom_settings' => TRUE,
),
);
$entity_info[$entity_type]['bundles'] = variable_get('field_test_bundles', array('test_bundle' => array('label' => 'Test Bundle')));
if ($entity_type == 'test_entity_bundle') {
$entity_info[$entity_type]['bundles'] += array('test_entity_2' => array('label' => 'Test entity 2'));
}
if ($entity_type == 'test_entity_bundle_key') {
$entity_info[$entity_type]['bundles'] += array('bundle1' => array('label' => 'Bundle1'), 'bundle2' => array('label' => 'Bundle2'));
}
}
} }
} }
@ -183,9 +68,11 @@ function field_test_create_bundle($bundle, $text = NULL) {
$bundles += array($bundle => array('label' => $text ? $text : $bundle)); $bundles += array($bundle => array('label' => $text ? $text : $bundle));
variable_set('field_test_bundles', $bundles); variable_set('field_test_bundles', $bundles);
$info = field_test_entity_info(); $info = entity_get_info();
foreach ($info as $type => $type_info) { foreach ($info as $type => $type_info) {
field_attach_create_bundle($type, $bundle); if ($type_info['module'] == 'field_test') {
field_attach_create_bundle($type, $bundle);
}
} }
} }
@ -203,9 +90,11 @@ function field_test_rename_bundle($bundle_old, $bundle_new) {
unset($bundles[$bundle_old]); unset($bundles[$bundle_old]);
variable_set('field_test_bundles', $bundles); variable_set('field_test_bundles', $bundles);
$info = field_test_entity_info(); $info = entity_get_info();
foreach ($info as $type => $type_info) { foreach ($info as $type => $type_info) {
field_attach_rename_bundle($type, $bundle_old, $bundle_new); if ($type_info['module'] == 'field_test') {
field_attach_rename_bundle($type, $bundle_old, $bundle_new);
}
} }
} }
@ -220,9 +109,11 @@ function field_test_delete_bundle($bundle) {
unset($bundles[$bundle]); unset($bundles[$bundle]);
variable_set('field_test_bundles', $bundles); variable_set('field_test_bundles', $bundles);
$info = field_test_entity_info(); $info = entity_get_info();
foreach ($info as $type => $type_info) { foreach ($info as $type => $type_info) {
field_attach_delete_bundle($type, $bundle); if ($type_info['module'] == 'field_test') {
field_attach_delete_bundle($type, $bundle);
}
} }
} }

View File

@ -319,7 +319,7 @@ function field_test_field_storage_query($field_id, $conditions, $count, &$cursor
// If querying all revisions and the entity type has revisions, we need // If querying all revisions and the entity type has revisions, we need
// to key the results by revision_ids. // to key the results by revision_ids.
$entity_type = entity_get_info($row->type); $entity_type = entity_get_info($row->type);
$id = ($load_current || empty($entity_type['entity keys']['revision'])) ? $row->entity_id : $row->revision_id; $id = ($load_current || empty($entity_type['entity_keys']['revision'])) ? $row->entity_id : $row->revision_id;
if (!isset($return[$row->type][$id])) { if (!isset($return[$row->type][$id])) {
$return[$row->type][$id] = (object) array('entity_id' => $row->entity_id, 'revision_id' => $row->revision_id, 'bundle' => $row->bundle); $return[$row->type][$id] = (object) array('entity_id' => $row->entity_id, 'revision_id' => $row->revision_id, 'bundle' => $row->bundle);

View File

@ -0,0 +1,35 @@
<?php
/**
* @file
* Contains Drupal\field_test\Plugin\Core\Entity\BundleKeyTestEntity.
*/
namespace Drupal\field_test\Plugin\Core\Entity;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/**
* Test entity class.
*
* @Plugin(
* id = "test_entity_bundle_key",
* label = @Translation("Test Entity with a bundle key"),
* module = "field_test",
* controller_class = "Drupal\field_test\TestEntityController",
* form_controller_class = {
* "default" = "Drupal\field_test\TestEntityFormController"
* },
* field_cache = FALSE,
* base_table = "test_entity_bundle_key",
* fieldable = TRUE,
* entity_keys = {
* "id" = "ftid",
* "bundle" = "fttype"
* }
* )
*/
class BundleKeyTestEntity extends TestEntity {
}

View File

@ -0,0 +1,35 @@
<?php
/**
* @file
* Contains Drupal\field_test\Plugin\Core\Entity\BundleTestEntity.
*/
namespace Drupal\field_test\Plugin\Core\Entity;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/**
* Test entity class.
*
* @Plugin(
* id = "test_entity_bundle",
* label = @Translation("Test Entity with a specified bundle"),
* module = "field_test",
* controller_class = "Drupal\field_test\TestEntityController",
* form_controller_class = {
* "default" = "Drupal\field_test\TestEntityFormController"
* },
* field_cache = FALSE,
* base_table = "test_entity_bundle",
* fieldable = TRUE,
* entity_keys = {
* "id" = "ftid",
* "bundle" = "fttype"
* }
* )
*/
class BundleTestEntity extends TestEntity {
}

View File

@ -0,0 +1,32 @@
<?php
/**
* @file
* Contains Drupal\field_test\Plugin\Core\Entity\CacheableTestEntity.
*/
namespace Drupal\field_test\Plugin\Core\Entity;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/**
* Test entity class.
*
* @Plugin(
* id = "test_cacheable_entity",
* label = @Translation("Test Entity, cacheable"),
* module = "field_test",
* controller_class = "Drupal\field_test\TestEntityController",
* field_cache = TRUE,
* fieldable = TRUE,
* entity_keys = {
* "id" = "ftid",
* "revision" = "ftvid",
* "bundle" = "fttype"
* }
* )
*/
class CacheableTestEntity extends TestEntity {
}

View File

@ -0,0 +1,35 @@
<?php
/**
* @file
* Contains Drupal\field_test\Plugin\Core\Entity\LabelCallbackTestEntity.
*/
namespace Drupal\field_test\Plugin\Core\Entity;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/**
* Test entity class.
*
* @Plugin(
* id = "test_entity_label_callback",
* label = @Translation("Test entity label callback"),
* module = "field_test",
* controller_class = "Drupal\field_test\TestEntityController",
* field_cache = FALSE,
* base_table = "test_entity",
* revision_table = "test_entity_revision",
* label_callback = "field_test_entity_label_callback",
* fieldable = TRUE,
* entity_keys = {
* "id" = "ftid",
* "revision" = "ftvid",
* "bundle" = "fttype"
* }
* )
*/
class LabelCallbackTestEntity extends TestEntity {
}

View File

@ -0,0 +1,38 @@
<?php
/**
* @file
* Contains Drupal\field_test\Plugin\Core\Entity\LabelTestEntity.
*/
namespace Drupal\field_test\Plugin\Core\Entity;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/**
* Test entity class.
*
* @Plugin(
* id = "test_entity_label",
* label = @Translation("Test Entity label"),
* module = "field_test",
* controller_class = "Drupal\field_test\TestEntityController",
* form_controller_class = {
* "default" = "Drupal\field_test\TestEntityFormController"
* },
* field_cache = FALSE,
* base_table = "test_entity",
* revision_table = "test_entity_revision",
* fieldable = TRUE,
* entity_keys = {
* "id" = "ftid",
* "revision" = "ftvid",
* "bundle" = "fttype",
* "label" = "ftlabel"
* }
* )
*/
class LabelTestEntity extends TestEntity {
}

View File

@ -0,0 +1,37 @@
<?php
/**
* @file
* Contains Drupal\field_test\Plugin\Core\Entity\NoLabelTestEntity.
*/
namespace Drupal\field_test\Plugin\Core\Entity;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/**
* Test entity class.
*
* @Plugin(
* id = "test_entity_no_label",
* label = @Translation("Test Entity without label"),
* module = "field_test",
* controller_class = "Drupal\field_test\TestEntityController",
* form_controller_class = {
* "default" = "Drupal\field_test\TestEntityFormController"
* },
* field_cache = FALSE,
* base_table = "test_entity",
* revision_table = "test_entity_revision",
* fieldable = TRUE,
* entity_keys = {
* "id" = "ftid",
* "revision" = "ftvid",
* "bundle" = "fttype"
* }
* )
*/
class NoLabelTestEntity extends TestEntity {
}

View File

@ -1,16 +1,37 @@
<?php <?php
/* /**
* @file * @file
* Definition of Drupal\field_test\TestEntity. * Contains Drupal\field_test\Plugin\Core\Entity\TestEntity.
*/ */
namespace Drupal\field_test; namespace Drupal\field_test\Plugin\Core\Entity;
use Drupal\Core\Entity\Entity; use Drupal\Core\Entity\Entity;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/** /**
* Test entity class. * Test entity class.
*
* @Plugin(
* id = "test_entity",
* label = @Translation("Test Entity"),
* module = "field_test",
* controller_class = "Drupal\field_test\TestEntityController",
* form_controller_class = {
* "default" = "Drupal\field_test\TestEntityFormController"
* },
* field_cache = FALSE,
* base_table = "test_entity",
* revision_table = "test_entity_revision",
* fieldable = TRUE,
* entity_keys = {
* "id" = "ftid",
* "revision" = "ftvid",
* "bundle" = "fttype"
* }
* )
*/ */
class TestEntity extends Entity { class TestEntity extends Entity {

View File

@ -169,7 +169,7 @@ function field_ui_menu() {
// view modes, and use an access callback to determine which ones are // view modes, and use an access callback to determine which ones are
// actually visible for a given bundle. // actually visible for a given bundle.
$weight = 0; $weight = 0;
$view_modes = array('default' => array('label' => t('Default'))) + $entity_info['view modes']; $view_modes = array('default' => array('label' => t('Default'))) + $entity_info['view_modes'];
foreach ($view_modes as $view_mode => $view_mode_info) { foreach ($view_modes as $view_mode => $view_mode_info) {
$items["$path/display/$view_mode"] = array( $items["$path/display/$view_mode"] = array(
'title' => $view_mode_info['label'], 'title' => $view_mode_info['label'],

View File

@ -333,7 +333,7 @@ class DisplayOverview extends OverviewBase {
// Custom display settings. // Custom display settings.
if ($this->view_mode == 'default') { if ($this->view_mode == 'default') {
$entity_info = entity_get_info($this->entity_type); $entity_info = entity_get_info($this->entity_type);
$view_modes = $entity_info['view modes']; $view_modes = $entity_info['view_modes'];
// Only show the settings if there is more than one view mode. // Only show the settings if there is more than one view mode.
if (count($view_modes) > 1) { if (count($view_modes) > 1) {
$form['modes'] = array( $form['modes'] = array(
@ -460,7 +460,7 @@ class DisplayOverview extends OverviewBase {
// settings. // settings.
$view_mode_settings = field_view_mode_settings($this->entity_type, $this->bundle); $view_mode_settings = field_view_mode_settings($this->entity_type, $this->bundle);
if (!empty($value) && empty($view_mode_settings[$view_mode_name]['custom_settings'])) { if (!empty($value) && empty($view_mode_settings[$view_mode_name]['custom_settings'])) {
$view_mode_label = $entity_info['view modes'][$view_mode_name]['label']; $view_mode_label = $entity_info['view_modes'][$view_mode_name]['label'];
$path = _field_ui_bundle_admin_path($this->entity_type, $this->bundle) . "/display/$view_mode_name"; $path = _field_ui_bundle_admin_path($this->entity_type, $this->bundle) . "/display/$view_mode_name";
drupal_set_message(t('The %view_mode mode now uses custom display settings. You might want to <a href="@url">configure them</a>.', array('%view_mode' => $view_mode_label, '@url' => url($path)))); drupal_set_message(t('The %view_mode mode now uses custom display settings. You might want to <a href="@url">configure them</a>.', array('%view_mode' => $view_mode_label, '@url' => url($path))));
// Initialize the newly customized view mode with the display settings // Initialize the newly customized view mode with the display settings

View File

@ -7,7 +7,7 @@
namespace Drupal\field_ui\Tests; namespace Drupal\field_ui\Tests;
use Drupal\node\Node; use Drupal\node\Plugin\Core\Entity\Node;
/** /**
* Tests the functionality of the 'Manage display' screens. * Tests the functionality of the 'Manage display' screens.

View File

@ -5,7 +5,7 @@
* Defines a "managed_file" Form API field and a "file" field for Field module. * Defines a "managed_file" Form API field and a "file" field for Field module.
*/ */
use Drupal\file\File; use Drupal\file\Plugin\Core\Entity\File;
use Drupal\Core\Template\Attribute; use Drupal\Core\Template\Attribute;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\file\FileUsage\DatabaseFileUsageBackend; use Drupal\file\FileUsage\DatabaseFileUsageBackend;
@ -86,31 +86,6 @@ function file_element_info() {
return $types; return $types;
} }
/**
* Implements hook_entity_info().
*/
function file_entity_info() {
return array(
'file' => array(
'label' => t('File'),
'base table' => 'file_managed',
'controller class' => 'Drupal\file\FileStorageController',
'entity class' => 'Drupal\file\File',
'entity keys' => array(
'id' => 'fid',
'label' => 'filename',
'uuid' => 'uuid',
),
'view modes' => array(
'full' => array(
'label' => t('File default'),
'custom settings' => FALSE,
),
),
'static cache' => FALSE,
),
);
}
/** /**
* Loads file entities from the database. * Loads file entities from the database.
* *
@ -1555,7 +1530,7 @@ function file_get_file_references(File $file, $field = NULL, $age = FIELD_LOAD_R
// The usage table contains usage of every revision. If we are looking // The usage table contains usage of every revision. If we are looking
// for every revision or the entity does not support revisions then // for every revision or the entity does not support revisions then
// every usage is already a match. // every usage is already a match.
$match_entity_type = $age == FIELD_LOAD_REVISION || !isset($entity_info['entity keys']['revision']); $match_entity_type = $age == FIELD_LOAD_REVISION || !isset($entity_info['entity_keys']['revision']);
$entities = entity_load_multiple($entity_type, $entity_ids); $entities = entity_load_multiple($entity_type, $entity_ids);
foreach ($entities as $entity) { foreach ($entities as $entity) {
$bundle = $entity->bundle(); $bundle = $entity->bundle();

View File

@ -500,8 +500,8 @@ function file_field_views_data_views_data_alter(&$data, $field) {
'field_name' => $field['field_name'], 'field_name' => $field['field_name'],
'field table' => _field_sql_storage_tablename($field), 'field table' => _field_sql_storage_tablename($field),
'field field' => $field['field_name'] . '_fid', 'field field' => $field['field_name'] . '_fid',
'base' => $entity_info['base table'], 'base' => $entity_info['base_table'],
'base field' => $entity_info['entity keys']['id'], 'base field' => $entity_info['entity_keys']['id'],
'label' => t('!field_name', array('!field_name' => $field['field_name'])), 'label' => t('!field_name', array('!field_name' => $field['field_name'])),
'join_extra' => array( 'join_extra' => array(
0 => array( 0 => array(

View File

@ -9,7 +9,7 @@ namespace Drupal\file\FileUsage;
use Drupal\Core\Database\Connection; use Drupal\Core\Database\Connection;
use Drupal\Core\Database\DatabaseExceptionWrapper; use Drupal\Core\Database\DatabaseExceptionWrapper;
use Drupal\file\File; use Drupal\file\Plugin\Core\Entity\File;
/** /**
* Defines the database file usage backend. This is the default Drupal backend. * Defines the database file usage backend. This is the default Drupal backend.

View File

@ -7,7 +7,7 @@
namespace Drupal\file\FileUsage; namespace Drupal\file\FileUsage;
use Drupal\file\File; use Drupal\file\Plugin\Core\Entity\File;
/** /**
* Defines the base class for database file usage backend. * Defines the base class for database file usage backend.

View File

@ -7,7 +7,7 @@
namespace Drupal\file\FileUsage; namespace Drupal\file\FileUsage;
use Drupal\file\File; use Drupal\file\Plugin\Core\Entity\File;
/** /**
* File usage backend interface. * File usage backend interface.

View File

@ -2,16 +2,38 @@
/** /**
* @file * @file
* Definition of Drupal\file\File. * Definition of Drupal\file\Plugin\Core\Entity\File.
*/ */
namespace Drupal\file; namespace Drupal\file\Plugin\Core\Entity;
use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\Entity; use Drupal\Core\Entity\Entity;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/** /**
* Defines the file entity class. * Defines the file entity class.
*
* @Plugin(
* id = "file",
* label = @Translation("File"),
* module = "file",
* controller_class = "Drupal\file\FileStorageController",
* base_table = "file_managed",
* static_cache = FALSE,
* entity_keys = {
* "id" = "fid",
* "label" = "filename",
* "uuid" = "uuid"
* },
* view_modes = {
* "full" = {
* "label" = "File default",
* "custom_settings" = FALSE
* }
* }
* )
*/ */
class File extends Entity implements ContentEntityInterface { class File extends Entity implements ContentEntityInterface {

View File

@ -6,7 +6,7 @@
*/ */
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\file\File; use Drupal\file\Plugin\Core\Entity\File;
/** /**
* Implements hook_menu(). * Implements hook_menu().

View File

@ -8,7 +8,7 @@
* calling file_test_get_calls() or file_test_set_return(). * calling file_test_get_calls() or file_test_set_return().
*/ */
use Drupal\file\File; use Drupal\file\Plugin\Core\Entity\File;
const FILE_URL_TEST_CDN_1 = 'http://cdn1.example.com'; const FILE_URL_TEST_CDN_1 = 'http://cdn1.example.com';
const FILE_URL_TEST_CDN_2 = 'http://cdn2.example.com'; const FILE_URL_TEST_CDN_2 = 'http://cdn2.example.com';

View File

@ -5,8 +5,8 @@
* Provides discussion forums. * Provides discussion forums.
*/ */
use Drupal\node\Node; use Drupal\node\Plugin\Core\Entity\Node;
use Drupal\taxonomy\Term; use Drupal\taxonomy\Plugin\Core\Entity\Term;
/** /**
* Implements hook_help(). * Implements hook_help().
@ -220,8 +220,8 @@ function forum_menu_local_tasks_alter(&$data, $router_item, $root_path) {
function forum_entity_info_alter(&$info) { function forum_entity_info_alter(&$info) {
// Take over URI construction for taxonomy terms that are forums. // Take over URI construction for taxonomy terms that are forums.
if ($vid = config('forum.settings')->get('vocabulary')) { if ($vid = config('forum.settings')->get('vocabulary')) {
// Within hook_entity_info(), we can't invoke entity_load() as that would // Within hook_entity_info_alter(), we can't invoke entity_load() as that
// cause infinite recursion, so we call taxonomy_vocabulary_get_names() // would cause infinite recursion, so we call taxonomy_vocabulary_get_names()
// instead of taxonomy_vocabulary_load(). All we need is the machine name // instead of taxonomy_vocabulary_load(). All we need is the machine name
// of $vid, so retrieving and iterating all the vocabulary names is somewhat // of $vid, so retrieving and iterating all the vocabulary names is somewhat
// inefficient, but entity info is cached across page requests, and an // inefficient, but entity info is cached across page requests, and an
@ -229,7 +229,7 @@ function forum_entity_info_alter(&$info) {
// and is done as part of taxonomy_entity_info() anyway. // and is done as part of taxonomy_entity_info() anyway.
foreach (taxonomy_vocabulary_get_names() as $machine_name => $vocabulary) { foreach (taxonomy_vocabulary_get_names() as $machine_name => $vocabulary) {
if ($vid == $vocabulary->vid) { if ($vid == $vocabulary->vid) {
$info['taxonomy_term']['bundles'][$machine_name]['uri callback'] = 'forum_uri'; $info['taxonomy_term']['bundles'][$machine_name]['uri_callback'] = 'forum_uri';
} }
} }
} }

View File

@ -7,7 +7,7 @@
namespace Drupal\forum\Tests; namespace Drupal\forum\Tests;
use Drupal\node\Node; use Drupal\node\Plugin\Core\Entity\Node;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
/** /**

View File

@ -74,7 +74,7 @@ function hook_image_effect_info_alter(&$effects) {
* be cleared using this hook. This hook is called whenever a style is updated, * be cleared using this hook. This hook is called whenever a style is updated,
* deleted, or any effect associated with the style is update or deleted. * deleted, or any effect associated with the style is update or deleted.
* *
* @param Drupal\image\ImageStyle $style * @param Drupal\image\Plugin\Core\Entity\ImageStyle $style
* The image style array that is being flushed. * The image style array that is being flushed.
*/ */
function hook_image_style_flush($style) { function hook_image_style_flush($style) {

View File

@ -9,8 +9,8 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Drupal\Component\Uuid\Uuid; use Drupal\Component\Uuid\Uuid;
use Drupal\file\File; use Drupal\file\Plugin\Core\Entity\File;
use Drupal\image\ImageStyle; use Drupal\image\Plugin\Core\Entity\ImageStyle;
/** /**
* Image style constant for user presets in the database. * Image style constant for user presets in the database.
@ -597,7 +597,7 @@ function image_image_style_update($style) {
/** /**
* Delete an image style. * Delete an image style.
* *
* @param Drupal\image\ImageStyle $style * @param Drupal\image\Plugin\Core\Entity\ImageStyle $style
* An image style array. * An image style array.
* @param $replacement_style_name * @param $replacement_style_name
* (optional) When deleting a style, specify a replacement style name so * (optional) When deleting a style, specify a replacement style name so
@ -1163,26 +1163,6 @@ function _image_effect_definitions_sort($a, $b) {
return strcasecmp($a['name'], $b['name']); return strcasecmp($a['name'], $b['name']);
} }
/**
* Implements hook_entity_info().
*/
function image_entity_info() {
return array(
'image_style' => array(
'label' => t('Image style'),
'entity class' => 'Drupal\image\ImageStyle',
'controller class' => 'Drupal\Core\Config\Entity\ConfigStorageController',
'uri callback' => 'image_style_uri',
'config prefix' => 'image.style',
'entity keys' => array(
'id' => 'name',
'label' => 'label',
'uuid' => 'uuid',
),
),
);
}
/** /**
* URI callbacks for image styles. * URI callbacks for image styles.
*/ */

View File

@ -53,8 +53,8 @@ function image_field_views_data_views_data_alter(&$data, $field) {
'field_name' => $field['field_name'], 'field_name' => $field['field_name'],
'field table' => _field_sql_storage_tablename($field), 'field table' => _field_sql_storage_tablename($field),
'field field' => $field['field_name'] . '_fid', 'field field' => $field['field_name'] . '_fid',
'base' => $entity_info['base table'], 'base' => $entity_info['base_table'],
'base field' => $entity_info['entity keys']['id'], 'base field' => $entity_info['entity_keys']['id'],
'label' => t('!field_name', array('!field_name' => $field['field_name'])), 'label' => t('!field_name', array('!field_name' => $field['field_name'])),
'join_extra' => array( 'join_extra' => array(
0 => array( 0 => array(

View File

@ -2,15 +2,31 @@
/** /**
* @file * @file
* Definition of Drupal\image\ImageStyle. * Definition of Drupal\image\Plugin\Core\Entity\ImageStyle.
*/ */
namespace Drupal\image; namespace Drupal\image\Plugin\Core\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/** /**
* Defines an image style configuration entity. * Defines an image style configuration entity.
*
* @Plugin(
* id = "image_style",
* label = @Translation("Image style"),
* module = "image",
* controller_class = "Drupal\Core\Config\Entity\ConfigStorageController",
* uri_callback = "image_style_uri",
* config_prefix = "image.style",
* entity_keys = {
* "id" = "name",
* "label" = "label",
* "uuid" = "uuid"
* }
* )
*/ */
class ImageStyle extends ConfigEntityBase { class ImageStyle extends ConfigEntityBase {

View File

@ -11,7 +11,7 @@
* URLs to be added to the main site navigation menu. * URLs to be added to the main site navigation menu.
*/ */
use Drupal\node\Node; use Drupal\node\Plugin\Core\Entity\Node;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;

View File

@ -2,16 +2,57 @@
/** /**
* @file * @file
* Definition of Drupal\node\Node. * Definition of Drupal\node\Plugin\Core\Entity\Node.
*/ */
namespace Drupal\node; namespace Drupal\node\Plugin\Core\Entity;
use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\Entity; use Drupal\Core\Entity\Entity;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/** /**
* Defines the node entity class. * Defines the node entity class.
*
* @Plugin(
* id = "node",
* label = @Translation("Node"),
* module = "node",
* controller_class = "Drupal\node\NodeStorageController",
* render_controller_class = "Drupal\node\NodeRenderController",
* form_controller_class = {
* "default" = "Drupal\node\NodeFormController"
* },
* base_table = "node",
* revision_table = "node_revision",
* uri_callback = "node_uri",
* fieldable = TRUE,
* entity_keys = {
* "id" = "nid",
* "revision" = "vid",
* "bundle" = "type",
* "label" = "title",
* "uuid" = "uuid"
* },
* bundle_keys = {
* "bundle" = "type"
* },
* view_modes = {
* "full" = {
* "label" = "Full content",
* "custom_settings" = FALSE
* },
* "teaser" = {
* "label" = "Teaser",
* "custom_settings" = TRUE
* },
* "rss" = {
* "label" = "RSS",
* "custom_settings" = FALSE
* }
* }
* )
*/ */
class Node extends Entity implements ContentEntityInterface { class Node extends Entity implements ContentEntityInterface {

View File

@ -66,8 +66,8 @@ class Rss extends RowPluginBase {
public function buildOptionsForm_summary_options() { public function buildOptionsForm_summary_options() {
$entity_info = entity_get_info('node'); $entity_info = entity_get_info('node');
$options = array(); $options = array();
if (!empty($entity_info['view modes'])) { if (!empty($entity_info['view_modes'])) {
foreach ($entity_info['view modes'] as $mode => $settings) { foreach ($entity_info['view_modes'] as $mode => $settings) {
$options[$mode] = $settings['label']; $options[$mode] = $settings['label'];
} }
} }

View File

@ -15,8 +15,8 @@ use Drupal\Core\Database\Query\AlterableInterface;
use Drupal\Core\Database\Query\SelectExtender; use Drupal\Core\Database\Query\SelectExtender;
use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Database\Query\SelectInterface;
use Drupal\Core\Template\Attribute; use Drupal\Core\Template\Attribute;
use Drupal\node\Node; use Drupal\node\Plugin\Core\Entity\Node;
use Drupal\file\File; use Drupal\file\Plugin\Core\Entity\File;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
/** /**
@ -191,67 +191,24 @@ function node_cron() {
} }
/** /**
* Implements hook_entity_info(). * Implements hook_entity_info_alter().
*/ */
function node_entity_info() { function node_entity_info_alter(&$info) {
$return = array(
'node' => array(
'label' => t('Node'),
'entity class' => 'Drupal\node\Node',
'controller class' => 'Drupal\node\NodeStorageController',
'form controller class' => array(
'default' => 'Drupal\node\NodeFormController',
),
'base table' => 'node',
'revision table' => 'node_revision',
'uri callback' => 'node_uri',
'fieldable' => TRUE,
'entity keys' => array(
'id' => 'nid',
'revision' => 'vid',
'bundle' => 'type',
'label' => 'title',
'uuid' => 'uuid',
),
'bundle keys' => array(
'bundle' => 'type',
),
'bundles' => array(),
'render controller class' => 'Drupal\node\NodeRenderController',
'view modes' => array(
'full' => array(
'label' => t('Full content'),
'custom settings' => FALSE,
),
'teaser' => array(
'label' => t('Teaser'),
'custom settings' => TRUE,
),
'rss' => array(
'label' => t('RSS'),
'custom settings' => FALSE,
),
),
),
);
// Add a translation handler for fields if the language module is enabled. // Add a translation handler for fields if the language module is enabled.
if (module_exists('language')) { if (module_exists('language')) {
$return['node']['translation']['node'] = TRUE; $info['node']['translation']['node'] = TRUE;
} }
// Search integration is provided by node.module, so search-related // Search integration is provided by node.module, so search-related
// view modes for nodes are defined here and not in search.module. // view modes for nodes are defined here and not in search.module.
if (module_exists('search')) { if (module_exists('search')) {
$return['node']['view modes'] += array( $info['node']['view_modes']['search_index'] = array(
'search_index' => array( 'label' => t('Search index'),
'label' => t('Search index'), 'custom_settings' => FALSE,
'custom settings' => FALSE, );
), $info['node']['view_modes']['search_result'] = array(
'search_result' => array( 'label' => t('Search result'),
'label' => t('Search result'), 'custom_settings' => FALSE,
'custom settings' => FALSE,
),
); );
} }
@ -259,7 +216,7 @@ function node_entity_info() {
// messages, and the path to attach Field admin pages to. // messages, and the path to attach Field admin pages to.
node_type_cache_reset(); node_type_cache_reset();
foreach (node_type_get_names() as $type => $name) { foreach (node_type_get_names() as $type => $name) {
$return['node']['bundles'][$type] = array( $info['node']['bundles'][$type] = array(
'label' => $name, 'label' => $name,
'admin' => array( 'admin' => array(
'path' => 'admin/structure/types/manage/%node_type', 'path' => 'admin/structure/types/manage/%node_type',
@ -269,8 +226,6 @@ function node_entity_info() {
), ),
); );
} }
return $return;
} }
/** /**

View File

@ -9,7 +9,7 @@
* @see node_menu() * @see node_menu()
*/ */
use Drupal\node\Node; use Drupal\node\Plugin\Core\Entity\Node;
/** /**
* Page callback: Presents the node editing form. * Page callback: Presents the node editing form.

View File

@ -7,7 +7,7 @@
* a special 'node test view' permission. * a special 'node test view' permission.
*/ */
use Drupal\node\Node; use Drupal\node\Plugin\Core\Entity\Node;
/** /**
* Implements hook_node_grants(). * Implements hook_node_grants().

View File

@ -6,7 +6,7 @@
* the Node module. * the Node module.
*/ */
use Drupal\node\Node; use Drupal\node\Plugin\Core\Entity\Node;
/** /**
* Implements hook_node_load(). * Implements hook_node_load().

View File

@ -6,7 +6,7 @@
* the Node module. * the Node module.
*/ */
use Drupal\node\Node; use Drupal\node\Plugin\Core\Entity\Node;
/** /**
* Implements hook_node_insert(). * Implements hook_node_insert().

View File

@ -5,9 +5,9 @@
* Enables users to rename URLs. * Enables users to rename URLs.
*/ */
use Drupal\node\Node; use Drupal\node\Plugin\Core\Entity\Node;
use Drupal\taxonomy\Term; use Drupal\taxonomy\Plugin\Core\Entity\Term;
/** /**
* Implements hook_help(). * Implements hook_help().

View File

@ -5,7 +5,7 @@
* Collects votes on different topics in the form of multiple choice questions. * Collects votes on different topics in the form of multiple choice questions.
*/ */
use Drupal\node\Node; use Drupal\node\Plugin\Core\Entity\Node;
/** /**
* Implements hook_help(). * Implements hook_help().

View File

@ -7,7 +7,7 @@
namespace Drupal\rdf\Tests; namespace Drupal\rdf\Tests;
use Drupal\node\Node; use Drupal\node\Plugin\Core\Entity\Node;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
/** /**

View File

@ -5,7 +5,7 @@
* Enables site-wide keyword searching. * Enables site-wide keyword searching.
*/ */
use Drupal\node\Node; use Drupal\node\Plugin\Core\Entity\Node;
/** /**
* Matches all 'N' Unicode character classes (numbers) * Matches all 'N' Unicode character classes (numbers)

View File

@ -5,7 +5,7 @@
* Logs and displays access statistics for a site. * Logs and displays access statistics for a site.
*/ */
use Drupal\node\Node; use Drupal\node\Plugin\Core\Entity\Node;
/** /**
* Implements hook_help(). * Implements hook_help().

View File

@ -58,8 +58,8 @@ class EntityRow extends RowPluginBase {
$this->entityType = $this->definition['entity_type']; $this->entityType = $this->definition['entity_type'];
$this->entityInfo = entity_get_info($this->entityType); $this->entityInfo = entity_get_info($this->entityType);
$this->base_table = $this->entityInfo['base table']; $this->base_table = $this->entityInfo['base_table'];
$this->base_field = $this->entityInfo['entity keys']['id']; $this->base_field = $this->entityInfo['entity_keys']['id'];
} }
/** /**
@ -93,8 +93,8 @@ class EntityRow extends RowPluginBase {
*/ */
protected function buildViewModeOptions() { protected function buildViewModeOptions() {
$options = array(); $options = array();
if (!empty($this->entityInfo['view modes'])) { if (!empty($this->entityInfo['view_modes'])) {
foreach ($this->entityInfo['view modes'] as $mode => $settings) { foreach ($this->entityInfo['view_modes'] as $mode => $settings) {
$options[$mode] = $settings['label']; $options[$mode] = $settings['label'];
} }
} }

View File

@ -33,6 +33,8 @@ class EntityApiInfoTest extends WebTestBase {
// Change the label of the test entity type and make sure changes appear // Change the label of the test entity type and make sure changes appear
// after flushing caches. // after flushing caches.
variable_set('entity_cache_test_label', 'New label.'); variable_set('entity_cache_test_label', 'New label.');
$info = entity_get_info('entity_cache_test');
$this->assertEqual($info['label'], 'Entity Cache Test', 'Original label appears in cached entity info.');
$this->resetAll(); $this->resetAll();
$info = entity_get_info('entity_cache_test'); $info = entity_get_info('entity_cache_test');
$this->assertEqual($info['label'], 'New label.', 'New label appears in entity info.'); $this->assertEqual($info['label'], 'New label.', 'New label appears in entity info.');
@ -52,6 +54,6 @@ class EntityApiInfoTest extends WebTestBase {
module_enable(array('entity_cache_test')); module_enable(array('entity_cache_test'));
$info = variable_get('entity_cache_test'); $info = variable_get('entity_cache_test');
$this->assertEqual($info['label'], 'Entity Cache Test', 'Entity info label is correct.'); $this->assertEqual($info['label'], 'Entity Cache Test', 'Entity info label is correct.');
$this->assertEqual($info['controller class'], 'Drupal\Core\Entity\DatabaseStorageController', 'Entity controller class info is correct.'); $this->assertEqual($info['controller_class'], 'Drupal\Core\Entity\DatabaseStorageController', 'Entity controller class info is correct.');
} }
} }

View File

@ -7,7 +7,7 @@
namespace Drupal\bundle_test; namespace Drupal\bundle_test;
use Drupal\file\File; use Drupal\file\Plugin\Core\Entity\File;
class TestFileUsage extends FileUsageBase { class TestFileUsage extends FileUsageBase {

View File

@ -6,12 +6,8 @@
*/ */
/** /**
* Implements hook_entity_info(). * Implements hook_entity_info_alter().
*/ */
function entity_cache_test_dependency_entity_info() { function entity_cache_test_dependency_entity_info_alter(&$info) {
return array( $info['entity_cache_test']['label'] = variable_get('entity_cache_test_label', 'Entity Cache Test');
'entity_cache_test' => array(
'label' => variable_get('entity_cache_test_label', 'Entity Cache Test'),
),
);
} }

View File

@ -0,0 +1,23 @@
<?php
/**
* @file
* Contains Drupal\entity_cache_test_dependency\Plugin\Core\Entity\EntityCacheTest.
*/
namespace Drupal\entity_cache_test_dependency\Plugin\Core\Entity;
use Drupal\Core\Entity\Entity;
use Drupal\Core\Annotation\Plugin;
/**
* Defines the EntityCacheTest class.
*
* @Plugin(
* id = "entity_cache_test",
* module = "entity_cache_test_dependency"
* )
*/
class EntityCacheTest extends Entity {
}

View File

@ -6,29 +6,13 @@
*/ */
/** /**
* Implements hook_entity_info(). * Implements hook_entity_info_alter().
*/ */
function entity_test_entity_info() { function entity_test_entity_info_alter(&$info) {
$items['entity_test'] = array(
'label' => t('Test entity'),
'entity class' => 'Drupal\entity_test\EntityTest',
'controller class' => 'Drupal\entity_test\EntityTestStorageController',
'form controller class' => array(
'default' => 'Drupal\entity_test\EntityTestFormController',
),
'base table' => 'entity_test',
'data table' => 'entity_test_property_data',
'fieldable' => TRUE,
'entity keys' => array(
'id' => 'id',
'uuid' => 'uuid',
),
);
// Optionally specify a translation handler for testing translations. // Optionally specify a translation handler for testing translations.
if (variable_get('entity_test_translation')) { if (variable_get('entity_test_translation')) {
$items['entity_test']['translation']['entity_test'] = TRUE; $info['entity_test']['translation']['entity_test'] = TRUE;
} }
return $items;
} }
/** /**
@ -98,7 +82,7 @@ function entity_test_edit($entity) {
* @param bool $reset * @param bool $reset
* A boolean indicating that the internal cache should be reset. * A boolean indicating that the internal cache should be reset.
* *
* @return Drupal\entity_test\EntityTest * @return Drupal\entity_test\Plugin\Core\Entity\EntityTest
* The loaded entity object, or FALSE if the entity cannot be loaded. * The loaded entity object, or FALSE if the entity cannot be loaded.
*/ */
function entity_test_load($id, $reset = FALSE) { function entity_test_load($id, $reset = FALSE) {

View File

@ -2,15 +2,34 @@
/** /**
* @file * @file
* Definition of Drupal\entity_test\EntityTest. * Definition of Drupal\entity_test\Plugin\Core\Entity\EntityTest.
*/ */
namespace Drupal\entity_test; namespace Drupal\entity_test\Plugin\Core\Entity;
use Drupal\Core\Entity\EntityNG; use Drupal\Core\Entity\EntityNG;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/** /**
* Defines the test entity class. * Defines the test entity class.
*
* @Plugin(
* id = "entity_test",
* label = @Translation("Test entity"),
* module = "entity_test",
* controller_class = "Drupal\entity_test\EntityTestStorageController",
* form_controller_class = {
* "default" = "Drupal\entity_test\EntityTestFormController"
* },
* base_table = "entity_test",
* data_table = "entity_test_property_data",
* fieldable = TRUE,
* entity_keys = {
* "id" = "id",
* "uuid" = "uuid"
* }
* )
*/ */
class EntityTest extends EntityNG { class EntityTest extends EntityNG {

View File

@ -7,7 +7,7 @@
* @see Drupal\taxonomy\Tests\TaxonomyHooksTestCase::testTaxonomyTermHooks() * @see Drupal\taxonomy\Tests\TaxonomyHooksTestCase::testTaxonomyTermHooks()
*/ */
use Drupal\taxonomy\Term; use Drupal\taxonomy\Plugin\Core\Entity\Term;
/** /**
* Implements hook_taxonomy_term_load(). * Implements hook_taxonomy_term_load().

View File

@ -18,4 +18,4 @@ function theme_page_test_system_theme_info() {
$themes['test_invalid_basetheme'] = drupal_get_path('module', 'system') . '/tests/themes/test_invalid_basetheme/test_invalid_basetheme.info'; $themes['test_invalid_basetheme'] = drupal_get_path('module', 'system') . '/tests/themes/test_invalid_basetheme/test_invalid_basetheme.info';
$themes['test_invalid_engine'] = drupal_get_path('module', 'system') . '/tests/themes/test_invalid_engine/test_invalid_engine.info'; $themes['test_invalid_engine'] = drupal_get_path('module', 'system') . '/tests/themes/test_invalid_engine/test_invalid_engine.info';
return $themes; return $themes;
} }

View File

@ -2,16 +2,47 @@
/** /**
* @file * @file
* Definition of Drupal\taxonomy\Term. * Definition of Drupal\taxonomy\Plugin\Core\Entity\Term.
*/ */
namespace Drupal\taxonomy; namespace Drupal\taxonomy\Plugin\Core\Entity;
use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\Entity; use Drupal\Core\Entity\Entity;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/** /**
* Defines the taxonomy term entity. * Defines the taxonomy term entity.
*
* @Plugin(
* id = "taxonomy_term",
* label = @Translation("Taxonomy term"),
* module = "taxonomy",
* controller_class = "Drupal\taxonomy\TermStorageController",
* render_controller_class = "Drupal\taxonomy\TermRenderController",
* form_controller_class = {
* "default" = "Drupal\taxonomy\TermFormController"
* },
* base_table = "taxonomy_term_data",
* uri_callback = "taxonomy_term_uri",
* fieldable = TRUE,
* entity_keys = {
* "id" = "tid",
* "bundle" = "vocabulary_machine_name",
* "label" = "name",
* "uuid" = "uuid"
* },
* bundle_keys = {
* "bundle" = "machine_name"
* },
* view_modes = {
* "full" = {
* "label" = "Taxonomy term page",
* "custom_settings" = FALSE
* }
* }
* )
*/ */
class Term extends Entity implements ContentEntityInterface { class Term extends Entity implements ContentEntityInterface {

View File

@ -2,15 +2,38 @@
/** /**
* @file * @file
* Definition of Drupal\taxonomy\Vocabulary. * Definition of Drupal\taxonomy\Plugin\Core\Entity\Vocabulary.
*/ */
namespace Drupal\taxonomy; namespace Drupal\taxonomy\Plugin\Core\Entity;
use Drupal\Core\Entity\Entity; use Drupal\Core\Entity\Entity;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/** /**
* Defines the taxonomy vocabulary entity. * Defines the taxonomy vocabulary entity.
*
* @Plugin(
* id = "taxonomy_vocabulary",
* label = @Translation("Taxonomy vocabulary"),
* module = "taxonomy",
* controller_class = "Drupal\taxonomy\VocabularyStorageController",
* form_controller_class = {
* "default" = "Drupal\taxonomy\VocabularyFormController"
* },
* base_table = "taxonomy_vocabulary",
* entity_keys = {
* "id" = "vid",
* "label" = "name"
* },
* view_modes = {
* "full" = {
* "label" = "Taxonomy vocabulary",
* "custom_settings" = FALSE
* }
* }
* )
*/ */
class Vocabulary extends Entity { class Vocabulary extends Entity {

View File

@ -5,8 +5,8 @@
* Administrative page callbacks for the taxonomy module. * Administrative page callbacks for the taxonomy module.
*/ */
use Drupal\taxonomy\Term; use Drupal\taxonomy\Plugin\Core\Entity\Term;
use Drupal\taxonomy\Vocabulary; use Drupal\taxonomy\Plugin\Core\Entity\Vocabulary;
/** /**
* Form builder to list and manage vocabularies. * Form builder to list and manage vocabularies.
@ -131,7 +131,7 @@ function taxonomy_vocabulary_add() {
* Display a tree of all the terms in a vocabulary, with options to edit * Display a tree of all the terms in a vocabulary, with options to edit
* each one. The form is made drag and drop by the theme function. * each one. The form is made drag and drop by the theme function.
* *
* @param Drupal\taxonomy\Vocabulary $vocabulary * @param Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary
* The taxonomy vocabulary entity to list terms for. * The taxonomy vocabulary entity to list terms for.
* *
* @ingroup forms * @ingroup forms

View File

@ -34,10 +34,10 @@ function hook_taxonomy_vocabulary_load(array $vocabularies) {
* Modules implementing this hook can act on the vocabulary object before it is * Modules implementing this hook can act on the vocabulary object before it is
* inserted or updated. * inserted or updated.
* *
* @param Drupal\taxonomy\Vocabulary $vocabulary * @param Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary
* A taxonomy vocabulary entity. * A taxonomy vocabulary entity.
*/ */
function hook_taxonomy_vocabulary_presave(Drupal\taxonomy\Vocabulary $vocabulary) { function hook_taxonomy_vocabulary_presave(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) {
$vocabulary->foo = 'bar'; $vocabulary->foo = 'bar';
} }
@ -47,10 +47,10 @@ function hook_taxonomy_vocabulary_presave(Drupal\taxonomy\Vocabulary $vocabulary
* Modules implementing this hook can act on the vocabulary object when saved * Modules implementing this hook can act on the vocabulary object when saved
* to the database. * to the database.
* *
* @param Drupal\taxonomy\Vocabulary $vocabulary * @param Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary
* A taxonomy vocabulary entity. * A taxonomy vocabulary entity.
*/ */
function hook_taxonomy_vocabulary_insert(Drupal\taxonomy\Vocabulary $vocabulary) { function hook_taxonomy_vocabulary_insert(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) {
if ($vocabulary->synonyms) { if ($vocabulary->synonyms) {
variable_set('taxonomy_' . $vocabulary->vid . '_synonyms', TRUE); variable_set('taxonomy_' . $vocabulary->vid . '_synonyms', TRUE);
} }
@ -61,10 +61,10 @@ function hook_taxonomy_vocabulary_insert(Drupal\taxonomy\Vocabulary $vocabulary)
* *
* Modules implementing this hook can act on the vocabulary object when updated. * Modules implementing this hook can act on the vocabulary object when updated.
* *
* @param Drupal\taxonomy\Vocabulary $vocabulary * @param Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary
* A taxonomy vocabulary entity. * A taxonomy vocabulary entity.
*/ */
function hook_taxonomy_vocabulary_update(Drupal\taxonomy\Vocabulary $vocabulary) { function hook_taxonomy_vocabulary_update(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) {
$status = $vocabulary->synonyms ? TRUE : FALSE; $status = $vocabulary->synonyms ? TRUE : FALSE;
if ($vocabulary->synonyms) { if ($vocabulary->synonyms) {
variable_set('taxonomy_' . $vocabulary->vid . '_synonyms', $status); variable_set('taxonomy_' . $vocabulary->vid . '_synonyms', $status);
@ -78,13 +78,13 @@ function hook_taxonomy_vocabulary_update(Drupal\taxonomy\Vocabulary $vocabulary)
* field_attach_delete_bundle() is called and before the vocabulary is actually * field_attach_delete_bundle() is called and before the vocabulary is actually
* removed from the database. * removed from the database.
* *
* @param Drupal\taxonomy\Vocabulary $vocabulary * @param Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary
* The taxonomy vocabulary entity that is about to be deleted. * The taxonomy vocabulary entity that is about to be deleted.
* *
* @see hook_taxonomy_vocabulary_delete() * @see hook_taxonomy_vocabulary_delete()
* @see taxonomy_vocabulary_delete() * @see taxonomy_vocabulary_delete()
*/ */
function hook_taxonomy_vocabulary_predelete(Drupal\taxonomy\Vocabulary $vocabulary) { function hook_taxonomy_vocabulary_predelete(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) {
if (variable_get('taxonomy_' . $vocabulary->vid . '_synonyms', FALSE)) { if (variable_get('taxonomy_' . $vocabulary->vid . '_synonyms', FALSE)) {
variable_del('taxonomy_' . $vocabulary->vid . '_synonyms'); variable_del('taxonomy_' . $vocabulary->vid . '_synonyms');
} }
@ -97,13 +97,13 @@ function hook_taxonomy_vocabulary_predelete(Drupal\taxonomy\Vocabulary $vocabula
* field_attach_delete_bundle() has been called and after the vocabulary has * field_attach_delete_bundle() has been called and after the vocabulary has
* been removed from the database. * been removed from the database.
* *
* @param Drupal\taxonomy\Vocabulary $vocabulary * @param Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary
* The taxonomy vocabulary entity that has been deleted. * The taxonomy vocabulary entity that has been deleted.
* *
* @see hook_taxonomy_vocabulary_predelete() * @see hook_taxonomy_vocabulary_predelete()
* @see taxonomy_vocabulary_delete() * @see taxonomy_vocabulary_delete()
*/ */
function hook_taxonomy_vocabulary_delete(Drupal\taxonomy\Vocabulary $vocabulary) { function hook_taxonomy_vocabulary_delete(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) {
if (variable_get('taxonomy_' . $vocabulary->vid . '_synonyms', FALSE)) { if (variable_get('taxonomy_' . $vocabulary->vid . '_synonyms', FALSE)) {
variable_del('taxonomy_' . $vocabulary->vid . '_synonyms'); variable_del('taxonomy_' . $vocabulary->vid . '_synonyms');
} }

Some files were not shown because too many files have changed in this diff Show More