diff --git a/core/includes/file.inc b/core/includes/file.inc index b476bc78ddb53464d7da7fdcb54fdc3255a9a093..7559608a265d60dc8ff8b051f346030a27a34a54 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -582,8 +582,8 @@ function file_save_htaccess($directory, $private = TRUE) { * (deprecated) An associative array of conditions on the {file_managed} * table, where the keys are the database fields and the values are the * values those fields must have. Instead, it is preferable to use - * EntityFieldQuery to retrieve a list of entity IDs loadable by - * this function. + * Drupal\entity\EntityFieldQuery to retrieve a list of entity IDs + * loadable by this function. * * @return array * An array of file objects, indexed by fid. @@ -593,7 +593,7 @@ function file_save_htaccess($directory, $private = TRUE) { * @see hook_file_load() * @see file_load() * @see entity_load() - * @see EntityFieldQuery + * @see Drupal\entity\EntityFieldQuery */ function file_load_multiple($fids = array(), array $conditions = array()) { return entity_load_multiple('file', $fids, $conditions); diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 79f2ecb459b8594184856de60e35b3e984c248e7..5b42861c6bd1b846b07fa6bce68e4897ab839897 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1506,8 +1506,8 @@ function comment_delete_multiple($cids) { * (deprecated) An associative array of conditions on the {comments} * table, where the keys are the database fields and the values are the * values those fields must have. Instead, it is preferable to use - * EntityFieldQuery to retrieve a list of entity IDs loadable by - * this function. + * Drupal\entity\EntityFieldQuery to retrieve a list of entity IDs + * loadable by this function. * @param bool $reset * Whether to reset the internal static entity cache. Note that the static * cache is disabled in comment_entity_info() by default. @@ -1518,7 +1518,7 @@ function comment_delete_multiple($cids) { * @todo Remove $conditions in Drupal 8. * * @see entity_load() - * @see EntityFieldQuery + * @see Drupal\entity\EntityFieldQuery */ function comment_load_multiple($cids = array(), array $conditions = array(), $reset = FALSE) { return entity_load_multiple('comment', $cids, $conditions, $reset); diff --git a/core/modules/comment/lib/Drupal/comment/Comment.php b/core/modules/comment/lib/Drupal/comment/Comment.php index e75973f5e2459cca570ea0c5a5e2b7f5ec434d92..a335d501b02295f3a96b33edbbac151a0d054d92 100644 --- a/core/modules/comment/lib/Drupal/comment/Comment.php +++ b/core/modules/comment/lib/Drupal/comment/Comment.php @@ -7,7 +7,7 @@ namespace Drupal\comment; -use Entity; +use Drupal\entity\Entity; /** * Defines the comment entity class. diff --git a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php index 698fd7041d68f43e924fa5f267d7dc70d753010a..2909a99d05ee30eb84933d158b47f94979db517c 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php @@ -7,8 +7,8 @@ namespace Drupal\comment; -use EntityDatabaseStorageController; -use EntityInterface; +use Drupal\entity\EntityInterface; +use Drupal\entity\EntityDatabaseStorageController; /** * Defines the controller class for comments. diff --git a/core/modules/entity/entity.api.php b/core/modules/entity/entity.api.php index 8f721cf09835653361f5f68fd6400cce1a619bc9..87115bdd460b70be46655d5d25dc6b2ff6b52a0c 100644 --- a/core/modules/entity/entity.api.php +++ b/core/modules/entity/entity.api.php @@ -22,18 +22,19 @@ * properties of those types that the system needs to know about: * - label: The human-readable name of the type. * - controller class: The name of the class that is used to load the objects. - * The class has to implement the DrupalEntityControllerInterface interface. - * Leave blank to use the DrupalDefaultEntityController implementation. - * - base table: (used by DrupalDefaultEntityController) The name of the + * The class has to implement the Drupal\entity\EntityControllerInterface + * interface. Leave blank to use the Drupal\entity\EntityController + * implementation. + * - base table: (used by Drupal\entity\EntityController) The name of the * entity type's base table. - * - static cache: (used by DrupalDefaultEntityController) FALSE to disable + * - static cache: (used by Drupal\entity\EntityController) 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. * - load hook: The name of the hook which should be invoked by - * DrupalDefaultEntityController:attachLoad(), for example 'node_load'. + * Drupal\entity\EntityController::attachLoad(), for example 'node_load'. * - 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(). @@ -210,8 +211,8 @@ function hook_entity_info() { */ function hook_entity_info_alter(&$entity_info) { // Set the controller class for nodes to an alternate implementation of the - // DrupalEntityController interface. - $entity_info['node']['controller class'] = 'MyCustomNodeController'; + // Drupal\entity\EntityController interface. + $entity_info['node']['controller class'] = 'Drupal\mymodule\MyCustomNodeController'; } /** @@ -337,9 +338,9 @@ function hook_entity_delete($entity, $type) { } /** - * Alter or execute an EntityFieldQuery. + * Alter or execute an Drupal\entity\EntityFieldQuery. * - * @param EntityFieldQuery $query + * @param Drupal\entity\EntityFieldQuery $query * An EntityFieldQuery. One of the most important properties to be changed is * EntityFieldQuery::executeCallback. If this is set to an existing function, * this function will get the query as its single argument and its result diff --git a/core/modules/entity/entity.info b/core/modules/entity/entity.info index b15fadda266229658ea5457f50692da1cc2960ba..f8440cc7fcc52d60fd13d617030cca4659f37c4e 100644 --- a/core/modules/entity/entity.info +++ b/core/modules/entity/entity.info @@ -4,9 +4,6 @@ package = Core version = VERSION core = 8.x required = TRUE -files[] = entity.class.inc -files[] = entity.query.inc -files[] = entity.controller.inc files[] = tests/entity_crud_hook_test.test files[] = tests/entity_query.test files[] = tests/entity.test diff --git a/core/modules/entity/entity.module b/core/modules/entity/entity.module index a6599ebf73d506c38215712fcfa1783bfc606c06..c167bd4b0d1cc4d2493caa61fdd03082ddfaf3fb 100644 --- a/core/modules/entity/entity.module +++ b/core/modules/entity/entity.module @@ -5,6 +5,8 @@ * Entity API for handling entities like nodes or users. */ +use Drupal\entity\EntityMalformedException; + /** * Implements hook_help(). */ @@ -66,7 +68,7 @@ function entity_get_info($entity_type = NULL) { foreach ($entity_info as $name => $data) { $entity_info[$name] += array( 'fieldable' => FALSE, - 'controller class' => 'DrupalDefaultEntityController', + 'controller class' => 'Drupal\entity\EntityController', 'static cache' => TRUE, 'field cache' => TRUE, 'load hook' => $name . '_load', @@ -90,7 +92,7 @@ function entity_get_info($entity_type = NULL) { $entity_info[$name]['bundles'] = array($name => array('label' => $entity_info[$name]['label'])); } // Prepare entity schema fields SQL info for - // DrupalEntityControllerInterface::buildQuery(). + // Drupal\entity\EntityControllerInterface::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'])) { @@ -204,9 +206,9 @@ function entity_create_stub_entity($entity_type, $ids) { * * @see hook_entity_info() * @see entity_load_multiple() - * @see DrupalEntityControllerInterface - * @see DrupalDefaultEntityController - * @see EntityFieldQuery + * @see Drupal\entity\EntityControllerInterface + * @see Drupal\entity\EntityController + * @see Drupal\entity\EntityFieldQuery */ function entity_load($entity_type, $id, $reset = FALSE) { $entities = entity_load_multiple($entity_type, array($id), array(), $reset); @@ -221,13 +223,13 @@ function entity_load($entity_type, $id, $reset = FALSE) { * database access if loaded again during the same page request. * * The actual loading is done through a class that has to implement the - * DrupalEntityControllerInterface interface. By default, - * DrupalDefaultEntityController is used. Entity types can specify that a - * different class should be used by setting the 'controller class' key in - * hook_entity_info(). These classes can either implement the - * DrupalEntityControllerInterface interface, or, most commonly, extend the - * DrupalDefaultEntityController class. See node_entity_info() and the - * NodeController in node.module as an example. + * Drupal\entity\EntityControllerInterface interface. By default, + * Drupal\entity\EntityController is used. Entity types can specify + * that a different class should be used by setting the 'controller class' key + * in hook_entity_info(). These classes can either implement the + * Drupal\entity\EntityControllerInterface interface, or, most + * commonly, extend the Drupal\entity\EntityController class. See + * node_entity_info() and the NodeController in node.module as an example. * * @param string $entity_type * The entity type to load, e.g. node or user. @@ -247,9 +249,9 @@ function entity_load($entity_type, $id, $reset = FALSE) { * @todo Remove $conditions in Drupal 8. * * @see hook_entity_info() - * @see DrupalEntityControllerInterface - * @see DrupalDefaultEntityController - * @see EntityFieldQuery + * @see Drupal\entity\EntityControllerInterface + * @see Drupal\entity\EntityController + * @see Drupal\entity\EntityFieldQuery */ function entity_load_multiple($entity_type, $ids = FALSE, $conditions = array(), $reset = FALSE) { if ($reset) { @@ -301,7 +303,7 @@ function entity_delete_multiple($entity_type, $ids) { * An array of values to set, keyed by property name. If the entity type has * bundles the bundle key has to be specified. * - * @return EntityInterface + * @return Drupal\entity\EntityInterface * A new entity object. */ function entity_create($entity_type, array $values) { @@ -311,7 +313,7 @@ function entity_create($entity_type, array $values) { /** * Gets the entity controller class for an entity type. * - * @return EntityStorageControllerInterface + * @return Drupal\entity\EntityStorageControllerInterface */ function entity_get_controller($entity_type) { $controllers = &drupal_static(__FUNCTION__, array()); @@ -495,8 +497,3 @@ function entity_form_submit_build_entity($entity_type, $entity, $form, &$form_st field_attach_submit($entity_type, $entity, $form, $form_state); } } - -/** - * Defines an exception thrown when a malformed entity is passed. - */ -class EntityMalformedException extends Exception { } diff --git a/core/modules/entity/entity.class.inc b/core/modules/entity/lib/Drupal/entity/Entity.php similarity index 60% rename from core/modules/entity/entity.class.inc rename to core/modules/entity/lib/Drupal/entity/Entity.php index 9a007184a773b9f88dfbd4f526719a9f7425413e..f0f5a7658d790fa1049ae3c5f3f4de9fe4c0ca3a 100644 --- a/core/modules/entity/entity.class.inc +++ b/core/modules/entity/lib/Drupal/entity/Entity.php @@ -2,185 +2,10 @@ /** * @file - * Provides an interface and a base class for entities. + * Definition of Drupal\entity\Entity. */ -/** - * Defines a common interface for all entity objects. - */ -interface EntityInterface { - - /** - * Constructs a new entity object. - * - * @param $values - * An array of values to set, keyed by property name. If the entity type - * has bundles, the bundle key has to be specified. - * @param $entity_type - * The type of the entity to create. - */ - public function __construct(array $values, $entity_type); - - /** - * Returns the entity identifier (the entity's machine name or numeric ID). - * - * @return - * The identifier of the entity, or NULL if the entity does not yet have - * an identifier. - */ - public function id(); - - /** - * Returns whether the entity is new. - * - * Usually an entity is new if no ID exists for it yet. However, entities may - * be enforced to be new with existing IDs too. - * - * @return - * TRUE if the entity is new, or FALSE if the entity has already been saved. - * - * @see EntityInterface::enforceIsNew() - */ - public function isNew(); - - /** - * Enforces an entity to be new. - * - * Allows migrations to create entities with pre-defined IDs by forcing the - * entity to be new before saving. - * - * @param bool $value - * (optional) Whether the entity should be forced to be new. Defaults to - * TRUE. - * - * @see EntityInterface::isNew() - */ - public function enforceIsNew($value = TRUE); - - /** - * Returns the type of the entity. - * - * @return - * The type of the entity. - */ - public function entityType(); - - /** - * Returns the bundle of the entity. - * - * @return - * The bundle of the entity. Defaults to the entity type if the entity type - * does not make use of different bundles. - */ - public function bundle(); - - /** - * Returns the label of the entity. - * - * @return - * The label of the entity, or NULL if there is no label defined. - */ - public function label(); - - /** - * Returns the URI elements of the entity. - * - * @return - * An array containing the 'path' and 'options' keys used to build the URI - * of the entity, and matching the signature of url(). NULL if the entity - * has no URI of its own. - */ - public function uri(); - - /** - * Returns the default language of a language-specific entity. - * - * @return - * The language object of the entity's default language, or FALSE if the - * entity is not language-specific. - * - * @see EntityInterface::translations() - */ - public function language(); - - /** - * Returns the languages the entity is translated to. - * - * @return - * An array of language objects, keyed by language codes. - * - * @see EntityInterface::language() - */ - public function translations(); - - /** - * Returns the value of an entity property. - * - * @param $property_name - * The name of the property to return; e.g., 'title'. - * @param $langcode - * (optional) If the property is translatable, the language code of the - * language that should be used for getting the property. If set to NULL, - * the entity's default language is being used. - * - * @return - * The property value, or NULL if it is not defined. - * - * @see EntityInterface::language() - */ - public function get($property_name, $langcode = NULL); - - /** - * Sets the value of an entity property. - * - * @param $property_name - * The name of the property to set; e.g., 'title'. - * @param $value - * The value to set, or NULL to unset the property. - * @param $langcode - * (optional) If the property is translatable, the language code of the - * language that should be used for getting the property. If set to - * NULL, the entity's default language is being used. - * - * @see EntityInterface::language() - */ - public function set($property_name, $value, $langcode = NULL); - - /** - * Saves an entity permanently. - * - * @return - * Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed. - * - * @throws EntityStorageException - * In case of failures an exception is thrown. - */ - public function save(); - - /** - * Deletes an entity permanently. - * - * @throws EntityStorageException - * In case of failures an exception is thrown. - */ - public function delete(); - - /** - * Creates a duplicate of the entity. - * - * @return EntityInterface - * A clone of the current entity with all identifiers unset, so saving - * it inserts a new entity into the storage system. - */ - public function createDuplicate(); - - /** - * Returns the info of the type of the entity. - * - * @see entity_get_info() - */ - public function entityInfo(); -} +namespace Drupal\entity; /** * Defines a base entity class. diff --git a/core/modules/entity/entity.controller.inc b/core/modules/entity/lib/Drupal/entity/EntityController.php similarity index 60% rename from core/modules/entity/entity.controller.inc rename to core/modules/entity/lib/Drupal/entity/EntityController.php index 60a1e5fcad5599633a654c154d3ab0aaa0de4f48..3ef0fcbc41217263cf14b4da2ab9fe77dc1dd0e6 100644 --- a/core/modules/entity/entity.controller.inc +++ b/core/modules/entity/lib/Drupal/entity/EntityController.php @@ -2,62 +2,22 @@ /** * @file - * Entity API controller classes and interface. + * Definition of Drupal\entity\EntityController. */ -/** - * Defines a common interface for entity controller classes. - * - * All entity controller classes specified via the 'controller class' key - * returned by hook_entity_info() or hook_entity_info_alter() have to implement - * this interface. - * - * Most simple, SQL-based entity controllers will do better by extending - * DrupalDefaultEntityController instead of implementing this interface - * directly. - */ -interface DrupalEntityControllerInterface { - - /** - * Constructs a new DrupalEntityControllerInterface object. - * - * @param $entityType - * The entity type for which the instance is created. - */ - public function __construct($entityType); +namespace Drupal\entity; - /** - * Resets the internal, static entity cache. - * - * @param $ids - * (optional) If specified, the cache is reset for the entities with the - * given ids only. - */ - public function resetCache(array $ids = NULL); - - /** - * Loads one or more entities. - * - * @param $ids - * An array of entity IDs, or FALSE to load all entities. - * @param $conditions - * An array of conditions in the form 'field' => $value. - * - * @return - * An array of entity objects indexed by their ids. - */ - public function load($ids = array(), $conditions = array()); -} +use PDO; /** * Defines a base entity controller class. * - * Default implementation of DrupalEntityControllerInterface. + * Default implementation of Drupal\entity\EntityControllerInterface. * * This class can be used as-is by most simple entity types. Entity types * requiring special handling can extend the class. */ -class DrupalDefaultEntityController implements DrupalEntityControllerInterface { +class EntityController implements EntityControllerInterface { /** * Static cache of entities. @@ -85,7 +45,7 @@ class DrupalDefaultEntityController implements DrupalEntityControllerInterface { /** * Additional arguments to pass to hook_TYPE_load(). * - * Set before calling DrupalDefaultEntityController::attachLoad(). + * Set before calling Drupal\entity\EntityController::attachLoad(). * * @var array */ @@ -124,7 +84,7 @@ class DrupalDefaultEntityController implements DrupalEntityControllerInterface { protected $cache; /** - * Implements DrupalEntityControllerInterface::__construct(). + * Implements Drupal\entity\EntityController::__construct(). * * Sets basic variables. */ @@ -149,7 +109,7 @@ public function __construct($entityType) { } /** - * Implements DrupalEntityControllerInterface::resetCache(). + * Implements Drupal\entity\EntityControllerInterface::resetCache(). */ public function resetCache(array $ids = NULL) { if (isset($ids)) { @@ -163,7 +123,7 @@ public function resetCache(array $ids = NULL) { } /** - * Implements DrupalEntityControllerInterface::load(). + * Implements Drupal\entity\EntityControllerInterface::load(). */ public function load($ids = array(), $conditions = array()) { $entities = array(); @@ -204,7 +164,7 @@ public function load($ids = array(), $conditions = array()) { if (!empty($this->entityInfo['entity class'])) { // We provide the necessary arguments for PDO to create objects of the // specified entity class. - // @see EntityInterface::__construct() + // @see Drupal\entity\EntityInterface::__construct() $query_result->setFetchMode(PDO::FETCH_CLASS, $this->entityInfo['entity class'], array(array(), $this->entityType)); } $queried_entities = $query_result->fetchAllAssoc($this->idKey); @@ -397,199 +357,3 @@ protected function cacheSet($entities) { $this->entityCache += $entities; } } - -/** - * Defines a common interface for entity storage controllers. - */ -interface EntityStorageControllerInterface extends DrupalEntityControllerInterface { - - /** - * Constructs a new entity object, without permanently saving it. - * - * @param $values - * An array of values to set, keyed by property name. If the entity type has - * bundles the bundle key has to be specified. - * - * @return EntityInterface - * A new entity object. - */ - public function create(array $values); - - /** - * Deletes permanently saved entities. - * - * @param $ids - * An array of entity IDs. - * - * @throws EntityStorageException - * In case of failures, an exception is thrown. - */ - public function delete($ids); - - /** - * Saves the entity permanently. - * - * @param EntityInterface $entity - * The entity to save. - * - * @return - * SAVED_NEW or SAVED_UPDATED is returned depending on the operation - * performed. - * - * @throws EntityStorageException - * In case of failures, an exception is thrown. - */ - public function save(EntityInterface $entity); - -} - -/** - * Defines an exception thrown when storage operations fail. - */ -class EntityStorageException extends Exception { } - -/** - * Implements the entity storage controller interface for the database. - */ -class EntityDatabaseStorageController extends DrupalDefaultEntityController implements EntityStorageControllerInterface { - - /** - * Implements EntityStorageControllerInterface::create(). - */ - public function create(array $values) { - $class = isset($this->entityInfo['entity class']) ? $this->entityInfo['entity class'] : 'Entity'; - return new $class($values, $this->entityType); - } - - /** - * Implements EntityStorageControllerInterface::delete(). - */ - public function delete($ids) { - $entities = $ids ? $this->load($ids) : FALSE; - if (!$entities) { - // If no IDs or invalid IDs were passed, do nothing. - return; - } - $transaction = db_transaction(); - - try { - $this->preDelete($entities); - foreach ($entities as $id => $entity) { - $this->invokeHook('predelete', $entity); - } - $ids = array_keys($entities); - - db_delete($this->entityInfo['base table']) - ->condition($this->idKey, $ids, 'IN') - ->execute(); - // Reset the cache as soon as the changes have been applied. - $this->resetCache($ids); - - $this->postDelete($entities); - foreach ($entities as $id => $entity) { - $this->invokeHook('delete', $entity); - } - // Ignore slave server temporarily. - db_ignore_slave(); - } - catch (Exception $e) { - $transaction->rollback(); - watchdog_exception($this->entityType, $e); - throw new EntityStorageException($e->getMessage, $e->getCode, $e); - } - } - - /** - * Implements EntityStorageControllerInterface::save(). - */ - public function save(EntityInterface $entity) { - $transaction = db_transaction(); - try { - // Load the stored entity, if any. - if (!$entity->isNew() && !isset($entity->original)) { - $entity->original = entity_load_unchanged($this->entityType, $entity->id()); - } - - $this->preSave($entity); - $this->invokeHook('presave', $entity); - - if (!$entity->isNew()) { - $return = drupal_write_record($this->entityInfo['base table'], $entity, $this->idKey); - $this->resetCache(array($entity->{$this->idKey})); - $this->postSave($entity, TRUE); - $this->invokeHook('update', $entity); - } - else { - $return = drupal_write_record($this->entityInfo['base table'], $entity); - // Reset general caches, but keep caches specific to certain entities. - $this->resetCache(array()); - - $entity->enforceIsNew(FALSE); - $this->postSave($entity, FALSE); - $this->invokeHook('insert', $entity); - } - - // Ignore slave server temporarily. - db_ignore_slave(); - unset($entity->original); - - return $return; - } - catch (Exception $e) { - $transaction->rollback(); - watchdog_exception($this->entityType, $e); - throw new EntityStorageException($e->getMessage(), $e->getCode(), $e); - } - } - - /** - * Acts on an entity before the presave hook is invoked. - * - * Used before the entity is saved and before invoking the presave hook. - */ - protected function preSave(EntityInterface $entity) { } - - /** - * Acts on a saved entity before the insert or update hook is invoked. - * - * Used after the entity is saved, but before invoking the insert or update - * hook. - * - * @param $update - * (bool) TRUE if the entity has been updated, or FALSE if it has been - * inserted. - */ - protected function postSave(EntityInterface $entity, $update) { } - - /** - * Acts on entities before they are deleted. - * - * Used before the entities are deleted and before invoking the delete hook. - */ - protected function preDelete($entities) { } - - /** - * Acts on deleted entities before the delete hook is invoked. - * - * Used after the entities are deleted but before invoking the delete hook. - */ - protected function postDelete($entities) { } - - /** - * Invokes a hook on behalf of the entity. - * - * @param $hook - * One of 'presave', 'insert', 'update', 'predelete', or 'delete'. - * @param $entity - * The entity object. - */ - protected function invokeHook($hook, EntityInterface $entity) { - if (!empty($this->entityInfo['fieldable']) && function_exists($function = 'field_attach_' . $hook)) { - $function($this->entityType, $entity); - } - // Invoke the hook. - module_invoke_all($this->entityType . '_' . $hook, $entity); - // Invoke the respective entity-level hook. - module_invoke_all('entity_' . $hook, $entity, $this->entityType); - } -} diff --git a/core/modules/entity/lib/Drupal/entity/EntityControllerInterface.php b/core/modules/entity/lib/Drupal/entity/EntityControllerInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..703094f816f711eec91b6db14effb002f8bd9285 --- /dev/null +++ b/core/modules/entity/lib/Drupal/entity/EntityControllerInterface.php @@ -0,0 +1,52 @@ +<?php + +/** + * @file + * Definition of Drupal\entity\EntityControllerInterface. + */ + +namespace Drupal\entity; + +/** + * Defines a common interface for entity controller classes. + * + * All entity controller classes specified via the 'controller class' key + * returned by hook_entity_info() or hook_entity_info_alter() have to implement + * this interface. + * + * Most simple, SQL-based entity controllers will do better by extending + * Drupal\entity\EntityController instead of implementing this interface + * directly. + */ +interface EntityControllerInterface { + + /** + * Constructs a new Drupal\entity\EntityControllerInterface object. + * + * @param $entityType + * The entity type for which the instance is created. + */ + public function __construct($entityType); + + /** + * Resets the internal, static entity cache. + * + * @param $ids + * (optional) If specified, the cache is reset for the entities with the + * given ids only. + */ + public function resetCache(array $ids = NULL); + + /** + * Loads one or more entities. + * + * @param $ids + * An array of entity IDs, or FALSE to load all entities. + * @param $conditions + * An array of conditions in the form 'field' => $value. + * + * @return + * An array of entity objects indexed by their ids. + */ + public function load($ids = array(), $conditions = array()); +} diff --git a/core/modules/entity/lib/Drupal/entity/EntityDatabaseStorageController.php b/core/modules/entity/lib/Drupal/entity/EntityDatabaseStorageController.php new file mode 100644 index 0000000000000000000000000000000000000000..13a529ab7243eb5a3a929ff0b14f5905c9a1ddad --- /dev/null +++ b/core/modules/entity/lib/Drupal/entity/EntityDatabaseStorageController.php @@ -0,0 +1,154 @@ +<?php + +/** + * @file + * Definition of Drupal\entity\EntityDatabaseStorageController. + */ + +namespace Drupal\entity; + +/** + * Implements the entity storage controller interface for the database. + */ +class EntityDatabaseStorageController extends EntityController implements EntityStorageControllerInterface { + + /** + * Implements Drupal\entity\EntityStorageControllerInterface::create(). + */ + public function create(array $values) { + $class = isset($this->entityInfo['entity class']) ? $this->entityInfo['entity class'] : 'Drupal\entity\Entity'; + return new $class($values, $this->entityType); + } + + /** + * Implements Drupal\entity\EntityStorageControllerInterface::delete(). + */ + public function delete($ids) { + $entities = $ids ? $this->load($ids) : FALSE; + if (!$entities) { + // If no IDs or invalid IDs were passed, do nothing. + return; + } + $transaction = db_transaction(); + + try { + $this->preDelete($entities); + foreach ($entities as $id => $entity) { + $this->invokeHook('predelete', $entity); + } + $ids = array_keys($entities); + + db_delete($this->entityInfo['base table']) + ->condition($this->idKey, $ids, 'IN') + ->execute(); + // Reset the cache as soon as the changes have been applied. + $this->resetCache($ids); + + $this->postDelete($entities); + foreach ($entities as $id => $entity) { + $this->invokeHook('delete', $entity); + } + // Ignore slave server temporarily. + db_ignore_slave(); + } + catch (Exception $e) { + $transaction->rollback(); + watchdog_exception($this->entityType, $e); + throw new EntityStorageException($e->getMessage, $e->getCode, $e); + } + } + + /** + * Implements Drupal\entity\EntityStorageControllerInterface::save(). + */ + public function save(EntityInterface $entity) { + $transaction = db_transaction(); + try { + // Load the stored entity, if any. + if (!$entity->isNew() && !isset($entity->original)) { + $entity->original = entity_load_unchanged($this->entityType, $entity->id()); + } + + $this->preSave($entity); + $this->invokeHook('presave', $entity); + + if (!$entity->isNew()) { + $return = drupal_write_record($this->entityInfo['base table'], $entity, $this->idKey); + $this->resetCache(array($entity->{$this->idKey})); + $this->postSave($entity, TRUE); + $this->invokeHook('update', $entity); + } + else { + $return = drupal_write_record($this->entityInfo['base table'], $entity); + // Reset general caches, but keep caches specific to certain entities. + $this->resetCache(array()); + + $entity->enforceIsNew(FALSE); + $this->postSave($entity, FALSE); + $this->invokeHook('insert', $entity); + } + + // Ignore slave server temporarily. + db_ignore_slave(); + unset($entity->original); + + return $return; + } + catch (Exception $e) { + $transaction->rollback(); + watchdog_exception($this->entityType, $e); + throw new EntityStorageException($e->getMessage(), $e->getCode(), $e); + } + } + + /** + * Acts on an entity before the presave hook is invoked. + * + * Used before the entity is saved and before invoking the presave hook. + */ + protected function preSave(EntityInterface $entity) { } + + /** + * Acts on a saved entity before the insert or update hook is invoked. + * + * Used after the entity is saved, but before invoking the insert or update + * hook. + * + * @param $update + * (bool) TRUE if the entity has been updated, or FALSE if it has been + * inserted. + */ + protected function postSave(EntityInterface $entity, $update) { } + + /** + * Acts on entities before they are deleted. + * + * Used before the entities are deleted and before invoking the delete hook. + */ + protected function preDelete($entities) { } + + /** + * Acts on deleted entities before the delete hook is invoked. + * + * Used after the entities are deleted but before invoking the delete hook. + */ + protected function postDelete($entities) { } + + /** + * Invokes a hook on behalf of the entity. + * + * @param $hook + * One of 'presave', 'insert', 'update', 'predelete', or 'delete'. + * @param $entity + * The entity object. + */ + protected function invokeHook($hook, EntityInterface $entity) { + if (!empty($this->entityInfo['fieldable']) && function_exists($function = 'field_attach_' . $hook)) { + $function($this->entityType, $entity); + } + // Invoke the hook. + module_invoke_all($this->entityType . '_' . $hook, $entity); + // Invoke the respective entity-level hook. + module_invoke_all('entity_' . $hook, $entity, $this->entityType); + } +} diff --git a/core/modules/entity/entity.query.inc b/core/modules/entity/lib/Drupal/entity/EntityFieldQuery.php similarity index 93% rename from core/modules/entity/entity.query.inc rename to core/modules/entity/lib/Drupal/entity/EntityFieldQuery.php index 840108ad09407a0f3479873074abab8669139b6f..852dced41764a2f58d4d319003457dda12fdca08 100644 --- a/core/modules/entity/entity.query.inc +++ b/core/modules/entity/lib/Drupal/entity/EntityFieldQuery.php @@ -1,20 +1,15 @@ <?php -use Drupal\Core\Database\Query\Select; - /** * @file - * Entity query API. + * Definition of Drupal\entity\EntityFieldQuery. */ -/** - * Exception thrown by EntityFieldQuery() on unsupported query syntax. - * - * Some storage modules might not support the full range of the syntax for - * conditions, and will raise an EntityFieldQueryException when an unsupported - * condition was specified. - */ -class EntityFieldQueryException extends Exception {} +namespace Drupal\entity; + +use Drupal\entity\EntityFieldQueryException; +use Drupal\Core\Database\Query\Select; +use PagerDefault; /** * Retrieves entities matching a given set of conditions. @@ -49,7 +44,7 @@ class EntityFieldQuery { /** * Indicates that both deleted and non-deleted fields should be returned. * - * @see EntityFieldQuery::deleted() + * @see Drupal\entity\EntityFieldQuery::deleted() */ const RETURN_ALL = NULL; @@ -68,7 +63,7 @@ class EntityFieldQuery { * * @var array * - * @see EntityFieldQuery::entityCondition() + * @see Drupal\entity\EntityFieldQuery::entityCondition() */ public $entityConditions = array(); @@ -77,7 +72,7 @@ class EntityFieldQuery { * * @var array * - * @see EntityFieldQuery::fieldCondition() + * @see Drupal\entity\EntityFieldQuery::fieldCondition() */ public $fieldConditions = array(); @@ -91,8 +86,8 @@ class EntityFieldQuery { * * @var array * - * @see EntityFieldQuery::fieldLanguageCondition() - * @see EntityFieldQuery::fieldDeltaCondition() + * @see Drupal\entity\EntityFieldQuery::fieldLanguageCondition() + * @see Drupal\entity\EntityFieldQuery::fieldDeltaCondition() */ public $fieldMetaConditions = array(); @@ -101,7 +96,7 @@ class EntityFieldQuery { * * @var array * - * @see EntityFieldQuery::propertyCondition() + * @see Drupal\entity\EntityFieldQuery::propertyCondition() */ public $propertyConditions = array(); @@ -117,7 +112,7 @@ class EntityFieldQuery { * * @var array * - * @see EntityFieldQuery::range() + * @see Drupal\entity\EntityFieldQuery::range() */ public $range = array(); @@ -126,7 +121,7 @@ class EntityFieldQuery { * * @var array * - * @see EntityFieldQuery::pager() + * @see Drupal\entity\EntityFieldQuery::pager() */ public $pager = array(); @@ -136,7 +131,7 @@ class EntityFieldQuery { * TRUE to return only deleted data, FALSE to return only non-deleted data, * EntityFieldQuery::RETURN_ALL to return everything. * - * @see EntityFieldQuery::deleted() + * @see Drupal\entity\EntityFieldQuery::deleted() */ public $deleted = FALSE; @@ -164,7 +159,7 @@ class EntityFieldQuery { * * @var int * - * @see EntityFieldQuery::age() + * @see Drupal\entity\EntityFieldQuery::age() */ public $age = FIELD_LOAD_CURRENT; @@ -173,7 +168,7 @@ class EntityFieldQuery { * * @var array * - * @see EntityFieldQuery::addTag() + * @see Drupal\entity\EntityFieldQuery::addTag() */ public $tags = array(); @@ -182,7 +177,7 @@ class EntityFieldQuery { * * @var array * - * @see EntityFieldQuery::addMetaData() + * @see Drupal\entity\EntityFieldQuery::addMetaData() */ public $metaData = array(); @@ -191,7 +186,7 @@ class EntityFieldQuery { * * @var array * - * @see EntityFieldQuery::execute(). + * @see Drupal\entity\EntityFieldQuery::execute(). */ public $orderedResults = array(); @@ -200,7 +195,7 @@ class EntityFieldQuery { * * @var string * - * @see EntityFieldQuery::execute(). + * @see Drupal\entity\EntityFieldQuery::execute() */ public $executeCallback = ''; @@ -240,7 +235,7 @@ class EntityFieldQuery { * The operator can be omitted, and will default to 'IN' if the value is an * array, or to '=' otherwise. * - * @return EntityFieldQuery + * @return Drupal\entity\EntityFieldQuery * The called object. */ public function entityCondition($name, $value, $operator = NULL) { @@ -269,11 +264,11 @@ public function entityCondition($name, $value, $operator = NULL) { * An arbitrary identifier: conditions in the same group must have the same * $langcode_group. * - * @return EntityFieldQuery + * @return Drupal\entity\EntityFieldQuery * The called object. * - * @see EntityFieldQuery::addFieldCondition - * @see EntityFieldQuery::deleted + * @see Drupal\entity\EntityFieldQuery::addFieldCondition() + * @see Drupal\entity\EntityFieldQuery::deleted() */ public function fieldCondition($field, $column = NULL, $value = NULL, $operator = NULL, $delta_group = NULL, $langcode_group = NULL) { return $this->addFieldCondition($this->fieldConditions, $field, $column, $value, $operator, $delta_group, $langcode_group); @@ -295,11 +290,11 @@ public function fieldCondition($field, $column = NULL, $value = NULL, $operator * An arbitrary identifier: conditions in the same group must have the same * $langcode_group. * - * @return EntityFieldQuery + * @return Drupal\entity\EntityFieldQuery * The called object. * - * @see EntityFieldQuery::addFieldCondition - * @see EntityFieldQuery::deleted + * @see Drupal\entity\EntityFieldQuery::addFieldCondition() + * @see Drupal\entity\EntityFieldQuery::deleted() */ public function fieldLanguageCondition($field, $value = NULL, $operator = NULL, $delta_group = NULL, $langcode_group = NULL) { return $this->addFieldCondition($this->fieldMetaConditions, $field, 'langcode', $value, $operator, $delta_group, $langcode_group); @@ -321,11 +316,11 @@ public function fieldLanguageCondition($field, $value = NULL, $operator = NULL, * An arbitrary identifier: conditions in the same group must have the same * $langcode_group. * - * @return EntityFieldQuery + * @return Drupal\entity\EntityFieldQuery * The called object. * - * @see EntityFieldQuery::addFieldCondition - * @see EntityFieldQuery::deleted + * @see Drupal\entity\EntityFieldQuery::addFieldCondition() + * @see Drupal\entity\EntityFieldQuery::deleted() */ public function fieldDeltaCondition($field, $value = NULL, $operator = NULL, $delta_group = NULL, $langcode_group = NULL) { return $this->addFieldCondition($this->fieldMetaConditions, $field, 'delta', $value, $operator, $delta_group, $langcode_group); @@ -371,7 +366,7 @@ public function fieldDeltaCondition($field, $value = NULL, $operator = NULL, $de * An arbitrary identifier: conditions in the same group must have the same * $langcode_group. * - * @return EntityFieldQuery + * @return Drupal\entity\EntityFieldQuery * The called object. */ protected function addFieldCondition(&$conditions, $field, $column = NULL, $value = NULL, $operator = NULL, $delta_group = NULL, $langcode_group = NULL) { @@ -425,7 +420,7 @@ protected function addFieldCondition(&$conditions, $field, $column = NULL, $valu * The operator can be omitted, and will default to 'IN' if the value is an * array, or to '=' otherwise. * - * @return EntityFieldQuery + * @return Drupal\entity\EntityFieldQuery * The called object. */ public function propertyCondition($column, $value, $operator = NULL) { @@ -451,7 +446,7 @@ public function propertyCondition($column, $value, $operator = NULL) { * @param $direction * The direction to sort. Legal values are "ASC" and "DESC". * - * @return EntityFieldQuery + * @return Drupal\entity\EntityFieldQuery * The called object. */ public function entityOrderBy($name, $direction = 'ASC') { @@ -477,7 +472,7 @@ public function entityOrderBy($name, $direction = 'ASC') { * @param $direction * The direction to sort. Legal values are "ASC" and "DESC". * - * @return EntityFieldQuery + * @return Drupal\entity\EntityFieldQuery * The called object. */ public function fieldOrderBy($field, $column, $direction = 'ASC') { @@ -518,7 +513,7 @@ public function fieldOrderBy($field, $column, $direction = 'ASC') { * @param $direction * The direction to sort. Legal values are "ASC" and "DESC". * - * @return EntityFieldQuery + * @return Drupal\entity\EntityFieldQuery * The called object. */ public function propertyOrderBy($column, $direction = 'ASC') { @@ -533,7 +528,7 @@ public function propertyOrderBy($column, $direction = 'ASC') { /** * Sets the query to be a count query only. * - * @return EntityFieldQuery + * @return Drupal\entity\EntityFieldQuery * The called object. */ public function count() { @@ -550,7 +545,7 @@ public function count() { * @param $length * The number of entities to return from the result set. * - * @return EntityFieldQuery + * @return Drupal\entity\EntityFieldQuery * The called object. */ public function range($start = NULL, $length = NULL) { @@ -571,7 +566,7 @@ public function range($start = NULL, $length = NULL) { * An optional integer to distinguish between multiple pagers on one page. * If not provided, one is automatically calculated. * - * @return EntityFieldQuery + * @return Drupal\entity\EntityFieldQuery * The called object. */ public function pager($limit = 10, $element = NULL) { @@ -596,7 +591,7 @@ public function pager($limit = 10, $element = NULL) { * An EFQ Header array based on which the order clause is added to the * query. * - * @return EntityFieldQuery + * @return Drupal\entity\EntityFieldQuery * The called object. */ public function tableSort(&$headers) { @@ -631,7 +626,7 @@ public function tableSort(&$headers) { * TRUE to only return deleted data, FALSE to return non-deleted data, * EntityFieldQuery::RETURN_ALL to return everything. Defaults to FALSE. * - * @return EntityFieldQuery + * @return Drupal\entity\EntityFieldQuery * The called object. */ public function deleted($deleted = TRUE) { @@ -652,7 +647,7 @@ public function deleted($deleted = TRUE) { * - FIELD_LOAD_REVISION: Query all revisions. The results will be keyed by * entity type and entity revision ID. * - * @return EntityFieldQuery + * @return Drupal\entity\EntityFieldQuery * The called object. */ public function age($age) { @@ -677,7 +672,7 @@ public function age($age) { * @param string $tag * The tag to add. * - * @return EntityFieldQuery + * @return Drupal\entity\EntityFieldQuery * The called object. */ public function addTag($tag) { @@ -698,7 +693,7 @@ public function addTag($tag) { * @param $object * The additional data to add to the query. May be any valid PHP variable. * - * @return EntityFieldQuery + * @return Drupal\entity\EntityFieldQuery * The called object. */ public function addMetaData($key, $object) { @@ -956,4 +951,3 @@ public function addCondition(Select $select_query, $sql_field, $condition, $havi } } - diff --git a/core/modules/entity/lib/Drupal/entity/EntityFieldQueryException.php b/core/modules/entity/lib/Drupal/entity/EntityFieldQueryException.php new file mode 100644 index 0000000000000000000000000000000000000000..12f2a1cff2b86852f7c4e136c73993dc72e13ac6 --- /dev/null +++ b/core/modules/entity/lib/Drupal/entity/EntityFieldQueryException.php @@ -0,0 +1,19 @@ +<?php + +/** + * @file + * Definition of Drupal\entity\EntityFieldQueryException. + */ + +namespace Drupal\entity; + +use Exception; + +/** + * Exception thrown by EntityFieldQuery() on unsupported query syntax. + * + * Some storage modules might not support the full range of the syntax for + * conditions, and will raise an EntityFieldQueryException when an unsupported + * condition was specified. + */ +class EntityFieldQueryException extends Exception { } diff --git a/core/modules/entity/lib/Drupal/entity/EntityInterface.php b/core/modules/entity/lib/Drupal/entity/EntityInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..c4c44c268a8c1894f5d30c782a78628868c1c1c1 --- /dev/null +++ b/core/modules/entity/lib/Drupal/entity/EntityInterface.php @@ -0,0 +1,185 @@ +<?php + +/** + * @file + * Definition of Drupal\entity\EntityInterface. + */ + +namespace Drupal\entity; + +/** + * Defines a common interface for all entity objects. + */ +interface EntityInterface { + + /** + * Constructs a new entity object. + * + * @param $values + * An array of values to set, keyed by property name. If the entity type + * has bundles, the bundle key has to be specified. + * @param $entity_type + * The type of the entity to create. + */ + public function __construct(array $values, $entity_type); + + /** + * Returns the entity identifier (the entity's machine name or numeric ID). + * + * @return + * The identifier of the entity, or NULL if the entity does not yet have + * an identifier. + */ + public function id(); + + /** + * Returns whether the entity is new. + * + * Usually an entity is new if no ID exists for it yet. However, entities may + * be enforced to be new with existing IDs too. + * + * @return + * TRUE if the entity is new, or FALSE if the entity has already been saved. + * + * @see Drupal\entity\EntityInterface::enforceIsNew() + */ + public function isNew(); + + /** + * Enforces an entity to be new. + * + * Allows migrations to create entities with pre-defined IDs by forcing the + * entity to be new before saving. + * + * @param bool $value + * (optional) Whether the entity should be forced to be new. Defaults to + * TRUE. + * + * @see Drupal\entity\EntityInterface::isNew() + */ + public function enforceIsNew($value = TRUE); + + /** + * Returns the type of the entity. + * + * @return + * The type of the entity. + */ + public function entityType(); + + /** + * Returns the bundle of the entity. + * + * @return + * The bundle of the entity. Defaults to the entity type if the entity type + * does not make use of different bundles. + */ + public function bundle(); + + /** + * Returns the label of the entity. + * + * @return + * The label of the entity, or NULL if there is no label defined. + */ + public function label(); + + /** + * Returns the URI elements of the entity. + * + * @return + * An array containing the 'path' and 'options' keys used to build the URI + * of the entity, and matching the signature of url(). NULL if the entity + * has no URI of its own. + */ + public function uri(); + + /** + * Returns the default language of a language-specific entity. + * + * @return + * The language object of the entity's default language, or FALSE if the + * entity is not language-specific. + * + * @see Drupal\entity\EntityInterface::translations() + */ + public function language(); + + /** + * Returns the languages the entity is translated to. + * + * @return + * An array of language objects, keyed by language codes. + * + * @see Drupal\entity\EntityInterface::language() + */ + public function translations(); + + /** + * Returns the value of an entity property. + * + * @param $property_name + * The name of the property to return; e.g., 'title'. + * @param $langcode + * (optional) If the property is translatable, the language code of the + * language that should be used for getting the property. If set to NULL, + * the entity's default language is being used. + * + * @return + * The property value, or NULL if it is not defined. + * + * @see Drupal\entity\EntityInterface::language() + */ + public function get($property_name, $langcode = NULL); + + /** + * Sets the value of an entity property. + * + * @param $property_name + * The name of the property to set; e.g., 'title'. + * @param $value + * The value to set, or NULL to unset the property. + * @param $langcode + * (optional) If the property is translatable, the language code of the + * language that should be used for getting the property. If set to + * NULL, the entity's default language is being used. + * + * @see Drupal\entity\EntityInterface::language() + */ + public function set($property_name, $value, $langcode = NULL); + + /** + * Saves an entity permanently. + * + * @return + * Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed. + * + * @throws Drupal\entity\EntityStorageException + * In case of failures an exception is thrown. + */ + public function save(); + + /** + * Deletes an entity permanently. + * + * @throws Drupal\entity\EntityStorageException + * In case of failures an exception is thrown. + */ + public function delete(); + + /** + * Creates a duplicate of the entity. + * + * @return Drupal\entity\EntityInterface + * A clone of the current entity with all identifiers unset, so saving + * it inserts a new entity into the storage system. + */ + public function createDuplicate(); + + /** + * Returns the info of the type of the entity. + * + * @see entity_get_info() + */ + public function entityInfo(); +} diff --git a/core/modules/entity/lib/Drupal/entity/EntityMalformedException.php b/core/modules/entity/lib/Drupal/entity/EntityMalformedException.php new file mode 100644 index 0000000000000000000000000000000000000000..bd9b500fa619cd8d60e4d58fcd45df4ada126a52 --- /dev/null +++ b/core/modules/entity/lib/Drupal/entity/EntityMalformedException.php @@ -0,0 +1,15 @@ +<?php + +/** + * @file + * Definition of Drupal\entity\EntityMalformedException. + */ + +namespace Drupal\entity; + +use Exception; + +/** + * Defines an exception thrown when a malformed entity is passed. + */ +class EntityMalformedException extends Exception { } diff --git a/core/modules/entity/lib/Drupal/entity/EntityStorageControllerInterface.php b/core/modules/entity/lib/Drupal/entity/EntityStorageControllerInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..cacc57c09bdadff2b8d6dde53e2fe2b83bdb3109 --- /dev/null +++ b/core/modules/entity/lib/Drupal/entity/EntityStorageControllerInterface.php @@ -0,0 +1,53 @@ +<?php + +/** + * @file + * Definition of Drupal\entity\EntityStorageControllerInterface. + */ + +namespace Drupal\entity; + +/** + * Defines a common interface for entity storage controllers. + */ +interface EntityStorageControllerInterface extends EntityControllerInterface { + + /** + * Constructs a new entity object, without permanently saving it. + * + * @param $values + * An array of values to set, keyed by property name. If the entity type has + * bundles the bundle key has to be specified. + * + * @return Drupal\entity\EntityInterface + * A new entity object. + */ + public function create(array $values); + + /** + * Deletes permanently saved entities. + * + * @param $ids + * An array of entity IDs. + * + * @throws Drupal\entity\EntityStorageException + * In case of failures, an exception is thrown. + */ + public function delete($ids); + + /** + * Saves the entity permanently. + * + * @param Drupal\entity\EntityInterface $entity + * The entity to save. + * + * @return + * SAVED_NEW or SAVED_UPDATED is returned depending on the operation + * performed. + * + * @throws Drupal\entity\EntityStorageException + * In case of failures, an exception is thrown. + */ + public function save(EntityInterface $entity); + +} diff --git a/core/modules/entity/lib/Drupal/entity/EntityStorageException.php b/core/modules/entity/lib/Drupal/entity/EntityStorageException.php new file mode 100644 index 0000000000000000000000000000000000000000..dff3e9318a778029f69f1d9201db432b008702f2 --- /dev/null +++ b/core/modules/entity/lib/Drupal/entity/EntityStorageException.php @@ -0,0 +1,15 @@ +<?php + +/** + * @file + * Definition of Drupal\entity\EntityStorageException. + */ + +namespace Drupal\entity; + +use Exception; + +/** + * Defines an exception thrown when storage operations fail. + */ +class EntityStorageException extends Exception { } diff --git a/core/modules/entity/tests/entity.test b/core/modules/entity/tests/entity.test index d920937b8b327a10c0c632bdcae30117991d8ed9..1047279cde37bb064615c8daa299334de51023cc 100644 --- a/core/modules/entity/tests/entity.test +++ b/core/modules/entity/tests/entity.test @@ -243,6 +243,6 @@ class EntityAPIInfoTestCase extends WebTestBase { module_enable(array('entity_cache_test')); $info = variable_get('entity_cache_test'); $this->assertEqual($info['label'], 'Entity Cache Test', 'Entity info label is correct.'); - $this->assertEqual($info['controller class'], 'DrupalDefaultEntityController', 'Entity controller class info is correct.'); + $this->assertEqual($info['controller class'], 'Drupal\entity\EntityController', 'Entity controller class info is correct.'); } } diff --git a/core/modules/entity/tests/entity_query.test b/core/modules/entity/tests/entity_query.test index edcf95a9519937c6246975070ea150f2309d5307..52018e4be05d7c50bbaa2c827ba2d1a5385a2453 100644 --- a/core/modules/entity/tests/entity_query.test +++ b/core/modules/entity/tests/entity_query.test @@ -6,9 +6,11 @@ */ use Drupal\simpletest\WebTestBase; +use Drupal\entity\EntityFieldQuery; +use Drupal\entity\EntityFieldQueryException; /** - * Tests EntityFieldQuery. + * Tests Drupal\entity\EntityFieldQuery. */ class EntityFieldQueryTestCase extends WebTestBase { diff --git a/core/modules/entity/tests/modules/entity_test/entity_test.module b/core/modules/entity/tests/modules/entity_test/entity_test.module index f6d2e3a08d8e6f262572e5479ac5d3edc8c36e07..25def33406ad8474777475fdb721201991b8ddf7 100644 --- a/core/modules/entity/tests/modules/entity_test/entity_test.module +++ b/core/modules/entity/tests/modules/entity_test/entity_test.module @@ -11,8 +11,8 @@ function entity_test_entity_info() { $items['entity_test'] = array( 'label' => t('Test entity'), - 'entity class' => 'Entity', - 'controller class' => 'EntityDatabaseStorageController', + 'entity class' => 'Drupal\entity\Entity', + 'controller class' => 'Drupal\entity\EntityDatabaseStorageController', 'base table' => 'entity_test', 'fieldable' => TRUE, 'entity keys' => array( @@ -34,7 +34,7 @@ function entity_test_entity_info() { * @param bool $reset * A boolean indicating that the internal cache should be reset. * - * @return Entity + * @return Drupal\entity\Entity * The loaded entity object, or FALSE if the entity cannot be loaded. */ function entity_test_load($id, $reset = FALSE) { diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php index 44aa50b53c8dd2f7fa7ac4880ed8ffae3562e1e2..7fce1250602702e630d7ecc8d02755c5ab2b432d 100644 --- a/core/modules/field/field.api.php +++ b/core/modules/field/field.api.php @@ -1902,18 +1902,18 @@ function hook_field_storage_delete_revision($entity_type, $entity, $fields) { } /** - * Execute an EntityFieldQuery. + * Execute a Drupal\entity\EntityFieldQuery. * * This hook is called to find the entities having certain entity and field * conditions and sort them in the given field order. If the field storage * engine also handles property sorts and orders, it should unset those * properties in the called object to signal that those have been handled. * - * @param EntityFieldQuery $query + * @param Drupal\entity\EntityFieldQuery $query * An EntityFieldQuery. * * @return - * See EntityFieldQuery::execute() for the return values. + * See Drupal\entity\EntityFieldQuery::execute() for the return values. */ function hook_field_storage_query($query) { $groups = array(); diff --git a/core/modules/field/field.crud.inc b/core/modules/field/field.crud.inc index 4a4842f19d09c9815e6b48f3649cbe17bdc8433a..d85a656e38d2726557b504ab6120ec582ae06384 100644 --- a/core/modules/field/field.crud.inc +++ b/core/modules/field/field.crud.inc @@ -6,6 +6,7 @@ */ use Drupal\field\FieldException; +use Drupal\entity\EntityFieldQuery; /** * @defgroup field_crud Field CRUD API diff --git a/core/modules/field/field.module b/core/modules/field/field.module index ab67eb26316b19c537c5386603ebf77406aa4490..6fc85ad12650f7f147170b33ebe82cf536404c3a 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -4,6 +4,8 @@ * Attach custom data fields to Drupal entities. */ +use Drupal\entity\EntityFieldQuery; + /* * Load all public Field API functions. Drupal currently has no * mechanism for auto-loading core APIs, so we have to load them on diff --git a/core/modules/field/modules/field_sql_storage/field_sql_storage.module b/core/modules/field/modules/field_sql_storage/field_sql_storage.module index f9c27a8c3730eaadc03b2965509266c987edd7f9..fd2f52c25674b192165059258ffe8568770636ec 100644 --- a/core/modules/field/modules/field_sql_storage/field_sql_storage.module +++ b/core/modules/field/modules/field_sql_storage/field_sql_storage.module @@ -1,14 +1,16 @@ <?php -use Drupal\Core\Database\Database; -use Drupal\Core\Database\Query\Select; -use Drupal\field\FieldUpdateForbiddenException; - /** * @file * Default implementation of the field storage API. */ +use Drupal\Core\Database\Database; +use Drupal\Core\Database\Query\Select; +use Drupal\entity\EntityFieldQuery; +use Drupal\entity\EntityFieldQueryException; +use Drupal\field\FieldUpdateForbiddenException; + /** * Implements hook_help(). */ @@ -612,7 +614,7 @@ function _field_sql_storage_query_join_entity(Select $select_query, $entity_type /** * Adds field (meta) conditions to the given query objects respecting groupings. * - * @param EntityFieldQuery $query + * @param Drupal\entity\EntityFieldQuery $query * The field query object to be processed. * @param SelectQuery $select_query * The SelectQuery that should get grouping conditions. diff --git a/core/modules/field/modules/list/list.module b/core/modules/field/modules/list/list.module index c80773a3d47090e6c34539fe2bd8bd5d961c4936..ec0eb6632c75c1b62af29037e053ccb9bcf794ac 100644 --- a/core/modules/field/modules/list/list.module +++ b/core/modules/field/modules/list/list.module @@ -6,6 +6,7 @@ */ use Drupal\field\FieldUpdateForbiddenException; +use Drupal\entity\EntityFieldQuery; /** * Implements hook_help(). diff --git a/core/modules/field/tests/field.test b/core/modules/field/tests/field.test index 9a850d98a17680b715cd8656e2c671c187adeca1..ca4de1be2babcac77459d4e90b45703d4b041f84 100644 --- a/core/modules/field/tests/field.test +++ b/core/modules/field/tests/field.test @@ -8,6 +8,7 @@ use Drupal\field\FieldException; use Drupal\field\FieldValidationException; use Drupal\simpletest\WebTestBase; +use Drupal\entity\EntityFieldQuery; /** * Parent class for Field API tests. diff --git a/core/modules/field/tests/field_test.entity.inc b/core/modules/field/tests/field_test.entity.inc index 52ed3fcd0988cb2c458acd6e0d0967c7d921a1b8..c8ad3d991546504bf91aa12a215072593611b5f2 100644 --- a/core/modules/field/tests/field_test.entity.inc +++ b/core/modules/field/tests/field_test.entity.inc @@ -5,6 +5,8 @@ * Defines an entity type. */ +use Drupal\entity\EntityController; + /** * Implements hook_entity_info(). */ @@ -478,10 +480,11 @@ function field_test_entity_nested_form_submit($form, &$form_state) { /** * Controller class for the test_entity_bundle entity type. * - * This extends the DrupalDefaultEntityController class, adding required - * special handling for bundles (since they are not stored in the database). + * This extends the Drupal\entity\EntityController class, adding + * required special handling for bundles (since they are not stored in the + * database). */ -class TestEntityBundleController extends DrupalDefaultEntityController { +class TestEntityBundleController extends EntityController { protected function attachLoad(&$entities, $revision_id = FALSE) { // Add bundle information. diff --git a/core/modules/field/tests/field_test.module b/core/modules/field/tests/field_test.module index 205a624a6d2f9841b1ba60d9c82e613fbc8f166d..a2da73cc94c6a8adf086763b572f870c46625787 100644 --- a/core/modules/field/tests/field_test.module +++ b/core/modules/field/tests/field_test.module @@ -13,6 +13,8 @@ * test helper functions */ +use Drupal\entity\EntityFieldQuery; + require_once DRUPAL_ROOT . '/core/modules/field/tests/field_test.entity.inc'; require_once DRUPAL_ROOT . '/core/modules/field/tests/field_test.field.inc'; require_once DRUPAL_ROOT . '/core/modules/field/tests/field_test.storage.inc'; diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 0aef8defb68ca55f7ce2416854d51a8823bb625c..f31fdfa9f1efac8420372ce06ac0f6582cbc4b96 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -5,6 +5,8 @@ * Defines a "managed_file" Form API field and a "file" field for Field module. */ +use Drupal\entity\EntityFieldQuery; + // Load all Field module hooks for File. require_once DRUPAL_ROOT . '/core/modules/file/file.field.inc'; diff --git a/core/modules/node/lib/Drupal/node/Node.php b/core/modules/node/lib/Drupal/node/Node.php index 787358e22dd012432e1f9ac2b019e2b820195802..1655ffaacb811539275f078cc735a571d8f2b5f1 100644 --- a/core/modules/node/lib/Drupal/node/Node.php +++ b/core/modules/node/lib/Drupal/node/Node.php @@ -7,7 +7,7 @@ namespace Drupal\node; -use Entity; +use Drupal\entity\Entity; /** * Defines the node entity class. diff --git a/core/modules/node/lib/Drupal/node/NodeStorageController.php b/core/modules/node/lib/Drupal/node/NodeStorageController.php index 0cdca80df753f743b10bf15ae6c2b461c8a9a5d6..c4747f2229b968e9eb6deb5956891f5fd91fe64c 100644 --- a/core/modules/node/lib/Drupal/node/NodeStorageController.php +++ b/core/modules/node/lib/Drupal/node/NodeStorageController.php @@ -7,9 +7,9 @@ namespace Drupal\node; -use EntityDatabaseStorageController; -use EntityInterface; -use EntityStorageException; +use Drupal\entity\EntityDatabaseStorageController; +use Drupal\entity\EntityInterface; +use Drupal\entity\EntityStorageException; use Exception; /** @@ -129,7 +129,7 @@ public function save(EntityInterface $entity) { /** * Saves a node revision. * - * @param EntityInterface $node + * @param Drupal\entity\EntityInterface $node * The node entity. */ protected function saveRevision(EntityInterface $entity) { @@ -152,7 +152,7 @@ protected function saveRevision(EntityInterface $entity) { } /** - * Overrides DrupalDefaultEntityController::attachLoad(). + * Overrides Drupal\entity\EntityController::attachLoad(). */ protected function attachLoad(&$nodes, $revision_id = FALSE) { // Create an array of nodes for each content type and pass this to the @@ -177,7 +177,7 @@ protected function attachLoad(&$nodes, $revision_id = FALSE) { } /** - * Overrides DrupalDefaultEntityController::buildQuery(). + * Overrides Drupal\entity\EntityController::buildQuery(). */ protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) { // Ensure that uid is taken from the {node} table, diff --git a/core/modules/node/node.api.php b/core/modules/node/node.api.php index ce3b784bfef87bb1ad96a78a715d5c67108463fd..915d906b19277c1ad88888089b8f65d2f980f6e3 100644 --- a/core/modules/node/node.api.php +++ b/core/modules/node/node.api.php @@ -529,12 +529,12 @@ function hook_node_insert(Drupal\node\Node $node) { * Act on nodes being loaded from the database. * * This hook is invoked during node loading, which is handled by entity_load(), - * via classes NodeController and DrupalDefaultEntityController. After the node - * information is read from the database or the entity cache, hook_load() is - * invoked on the node's content type module, then field_attach_node_revision() - * or field_attach_load() is called, then hook_entity_load() is invoked on all - * implementing modules, and finally hook_node_load() is invoked on all - * implementing modules. + * via classes NodeController and Drupal\entity\EntityController. + * After the node information is read from the database or the entity cache, + * hook_load() is invoked on the node's content type module, then + * field_attach_node_revision() or field_attach_load() is called, then + * hook_entity_load() is invoked on all implementing modules, and finally + * hook_node_load() is invoked on all implementing modules. * * This hook should only be used to add information that is not in the node or * node revisions table, not to replace information that is in these tables @@ -1158,12 +1158,12 @@ function hook_insert(Drupal\node\Node $node) { * (use hook_node_load() to respond to all node loads). * * This hook is invoked during node loading, which is handled by entity_load(), - * via classes NodeController and DrupalDefaultEntityController. After the node - * information is read from the database or the entity cache, hook_load() is - * invoked on the node's content type module, then field_attach_node_revision() - * or field_attach_load() is called, then hook_entity_load() is invoked on all - * implementing modules, and finally hook_node_load() is invoked on all - * implementing modules. + * via classes NodeController and Drupal\entity\EntityController. + * After the node information is read from the database or the entity cache, + * hook_load() is invoked on the node's content type module, then + * field_attach_node_revision() or field_attach_load() is called, then + * hook_entity_load() is invoked on all implementing modules, and finally + * hook_node_load() is invoked on all implementing modules. * * This hook should only be used to add information that is not in the node or * node revisions table, not to replace information that is in these tables diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 64491939e08d20b97ac20e6be7e451b3a0115586..55098302d18c33cd9040a735380e975f99141464 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -912,8 +912,8 @@ function node_invoke($node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) { * (deprecated) An associative array of conditions on the {node} * table, where the keys are the database fields and the values are the * values those fields must have. Instead, it is preferable to use - * EntityFieldQuery to retrieve a list of entity IDs loadable by - * this function. + * Drupal\entity\EntityFieldQuery to retrieve a list of entity IDs + * loadable by this function. * @param bool $reset * (optional) Whether to reset the internal node_load() cache. * @@ -923,7 +923,7 @@ function node_invoke($node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) { * @todo Remove $conditions in Drupal 8. * * @see entity_load_multiple() - * @see EntityFieldQuery + * @see Drupal\entity\EntityFieldQuery */ function node_load_multiple($nids = array(), array $conditions = array(), $reset = FALSE) { return entity_load_multiple('node', $nids, $conditions, $reset); diff --git a/core/modules/node/tests/modules/node_access_test/node_access_test.module b/core/modules/node/tests/modules/node_access_test/node_access_test.module index cda5fdfa0d75d345bf18400b0124e74791b29f4d..b6c6127406dcf3f862a324b97d8949c18d72d3f3 100644 --- a/core/modules/node/tests/modules/node_access_test/node_access_test.module +++ b/core/modules/node/tests/modules/node_access_test/node_access_test.module @@ -8,6 +8,7 @@ */ use Drupal\node\Node; +use Drupal\entity\EntityFieldQuery; /** * Implements hook_node_grants(). diff --git a/core/modules/taxonomy/taxonomy.entity.inc b/core/modules/taxonomy/taxonomy.entity.inc index 3562580ebc74d739b3e6775cd7a789a43c93b09a..773d62b0c964b64a585e4bb05f90a0984f7a7aba 100644 --- a/core/modules/taxonomy/taxonomy.entity.inc +++ b/core/modules/taxonomy/taxonomy.entity.inc @@ -5,6 +5,10 @@ * Entity classes and controllers for Taxonomy module. */ +use Drupal\entity\Entity; +use Drupal\entity\EntityInterface; +use Drupal\entity\EntityDatabaseStorageController; + /** * Defines the taxonomy term entity. */ @@ -212,7 +216,7 @@ protected function postSave(EntityInterface $entity, $update) { } /** - * Implements DrupalEntityControllerInterface::resetCache(). + * Implements Drupal\entity\EntityControllerInterface::resetCache(). */ public function resetCache(array $ids = NULL) { drupal_static_reset('taxonomy_term_count_nodes'); @@ -355,7 +359,7 @@ protected function postDelete($entities) { } /** - * Implements DrupalEntityControllerInterface::resetCache(). + * Implements Drupal\entity\EntityControllerInterface::resetCache(). */ public function resetCache(array $ids = NULL) { drupal_static_reset('taxonomy_vocabulary_get_names'); diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index 024f3edcc8fbdc5b00bab1e86b88fab42f519c51..8de8ae3f55379b52c6a007ad31f5d1a498668193 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -941,7 +941,7 @@ function taxonomy_term_load_multiple_by_name($name, $vocabulary = NULL) { * database access if loaded again during the same page request. * * @see entity_load_multiple() - * @see EntityFieldQuery + * @see Drupal\entity\EntityFieldQuery * * @param array|bool $tids * An array of taxonomy term IDs, or FALSE to load all terms. @@ -949,8 +949,8 @@ function taxonomy_term_load_multiple_by_name($name, $vocabulary = NULL) { * (deprecated) An associative array of conditions on the {taxonomy_term} * table, where the keys are the database fields and the values are the * values those fields must have. Instead, it is preferable to use - * EntityFieldQuery to retrieve a list of entity IDs loadable by - * this function. + * Drupal\entity\EntityFieldQuery to retrieve a list of entity IDs + * loadable by this function. * * @return array * An array of taxonomy term entities, indexed by tid. When no results are diff --git a/core/modules/taxonomy/taxonomy.test b/core/modules/taxonomy/taxonomy.test index d59094cba92bc1f7a93c6e8e007f9fbd6b4f0d90..55b30fa48b5081f57c729998392e07e48ec5a757 100644 --- a/core/modules/taxonomy/taxonomy.test +++ b/core/modules/taxonomy/taxonomy.test @@ -7,6 +7,7 @@ use Drupal\field\FieldValidationException; use Drupal\simpletest\WebTestBase; +use Drupal\entity\EntityFieldQuery; /** * Provides common helper methods for Taxonomy module tests. diff --git a/core/modules/user/lib/Drupal/user/User.php b/core/modules/user/lib/Drupal/user/User.php index b39d88d9ce27874276cf67bd6ecdb7ccc6b4afbc..a64652c53b34a1f7274e9674017e0f0c685f68fd 100644 --- a/core/modules/user/lib/Drupal/user/User.php +++ b/core/modules/user/lib/Drupal/user/User.php @@ -7,10 +7,7 @@ namespace Drupal\user; -/** - * @todo Switch to PSR-0 for the Entity classes: http://drupal.org/node/1495024 - */ -use Entity; +use Drupal\entity\Entity; /** * Defines the user entity class. diff --git a/core/modules/user/lib/Drupal/user/UserStorageController.php b/core/modules/user/lib/Drupal/user/UserStorageController.php index bd0d9b96cd59366db5fdab5cbc0ef1073584ed78..06d7fbc0651af3ee825a162f0edbb8fce093ce24 100644 --- a/core/modules/user/lib/Drupal/user/UserStorageController.php +++ b/core/modules/user/lib/Drupal/user/UserStorageController.php @@ -7,11 +7,9 @@ namespace Drupal\user; -/** - * @todo Switch to PSR-0 for the Entity classes: http://drupal.org/node/1495024 - */ -use EntityDatabaseStorageController; -use EntityInterface; +use Drupal\entity\EntityInterface; +use Drupal\entity\EntityMalformedException; +use Drupal\entity\EntityDatabaseStorageController; /** * Controller class for users. diff --git a/core/modules/user/user.module b/core/modules/user/user.module index a23543f2ff53a8d28474b3ca06e7e05c24781414..cfde27068bf557e0dd330f283f8cfaa6aa418156 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -273,8 +273,8 @@ function user_external_load($authname) { * (deprecated) An associative array of conditions on the {users} * table, where the keys are the database fields and the values are the * values those fields must have. Instead, it is preferable to use - * EntityFieldQuery to retrieve a list of entity IDs loadable by - * this function. + * Drupal\entity\EntityFieldQuery to retrieve a list of entity IDs + * loadable by this function. * @param bool $reset * A boolean indicating that the internal cache should be reset. Use this if * loading a user object which has been altered during the page request. @@ -286,7 +286,7 @@ function user_external_load($authname) { * @see user_load() * @see user_load_by_mail() * @see user_load_by_name() - * @see EntityFieldQuery + * @see Drupal\entity\EntityFieldQuery * * @todo Remove $conditions in Drupal 8. */