Commit 629ebca2 authored by alexpott's avatar alexpott

Issue #1976158 by Berdir | msonnabaum: Rename entity storage/list/form/render...

Issue #1976158 by Berdir | msonnabaum: Rename entity storage/list/form/render "controllers" to handlers.
parent 4b42df3d
......@@ -15,7 +15,7 @@
function entity_render_cache_clear() {
$entity_manager = Drupal::entityManager();
foreach ($entity_manager->getDefinitions() as $entity_type => $info) {
if ($entity_manager->hasController($entity_type, 'view_builder')) {
if ($entity_manager->hasHandler($entity_type, 'view_builder')) {
$entity_manager->getViewBuilder($entity_type)->resetCache();
}
}
......@@ -282,21 +282,6 @@ function entity_create($entity_type, array $values = array()) {
->create($values);
}
/**
* Gets the entity controller class for an entity type.
*
* @return \Drupal\Core\Entity\EntityStorageInterface
*
* @see \Drupal\Core\Entity\EntityManagerInterface::getStorage()
*
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
* Use \Drupal::entityManager()->getStorage().
*/
function entity_get_controller($entity_type) {
return \Drupal::entityManager()
->getStorage($entity_type);
}
/**
* Returns the label of an entity.
*
......
......@@ -67,7 +67,7 @@ public function __construct($definition) {
parent::__construct($definition);
// Always add a default 'uuid' key.
$this->entity_keys['uuid'] = 'uuid';
$this->controllers += array(
$this->handlers += array(
'storage' => 'Drupal\Core\Config\Entity\ConfigEntityStorage',
);
}
......
......@@ -845,8 +845,8 @@ public function updateOriginalValues() {
/**
* Implements the magic method for getting object properties.
*
* @todo: A lot of code still uses non-fields (e.g. $entity->content in render
* controllers) by reference. Clean that up.
* @todo: A lot of code still uses non-fields (e.g. $entity->content in view
* builders) by reference. Clean that up.
*/
public function &__get($name) {
// If this is an entity field, handle it accordingly. We first check whether
......
......@@ -23,11 +23,9 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines a base entity controller class.
* A content entity database storage implementation.
*
* Default implementation of Drupal\Core\Entity\EntityStorageInterface.
*
* This class can be used as-is by most simple entity types. Entity types
* This class can be used as-is by most content entity types. Entity types
* requiring special handling can extend the class.
*
* The class uses \Drupal\Core\Entity\Schema\ContentEntitySchemaHandler
......@@ -229,7 +227,7 @@ public function getSchema() {
}
/**
* Gets the schema handler for this storage controller.
* Gets the schema handler for this entity storage.
*
* @return \Drupal\Core\Entity\Schema\ContentEntitySchemaHandler
* The schema handler.
......@@ -275,7 +273,7 @@ public function getTableMapping() {
$revisionable = $this->entityType->isRevisionable();
// @todo Remove the data table check once all entity types are using
// entity query and we have a views data controller. See:
// entity query and we have a views data handler. See:
// - https://drupal.org/node/2068325
// - https://drupal.org/node/1740492
$translatable = $this->entityType->getDataTable() && $this->entityType->isTranslatable();
......
......@@ -17,7 +17,7 @@ class ContentEntityType extends EntityType implements ContentEntityTypeInterface
*/
public function __construct($definition) {
parent::__construct($definition);
$this->controllers += array(
$this->handlers += array(
'storage' => 'Drupal\Core\Entity\ContentEntityDatabaseStorage',
);
}
......
......@@ -453,7 +453,7 @@ protected function onSaveOrDelete() {
}
foreach ($referenced_entities as $entity_type => $entities) {
if ($this->entityManager()->hasController($entity_type, 'view_builder')) {
if ($this->entityManager()->hasHandler($entity_type, 'view_builder')) {
$this->entityManager()->getViewBuilder($entity_type)->resetCache($entities);
}
}
......@@ -510,7 +510,7 @@ protected function onUpdateBundleEntity() {
// builder class, then invalidate the render cache of entities for which
// this entity is a bundle.
$entity_manager = $this->entityManager();
if ($entity_manager->hasController($bundle_of, 'view_builder')) {
if ($entity_manager->hasHandler($bundle_of, 'view_builder')) {
$entity_manager->getViewBuilder($bundle_of)->resetCache();
}
// Entity bundle field definitions may depend on bundle settings.
......
......@@ -15,7 +15,7 @@
/**
* Defines a default implementation for entity access control handler.
*/
class EntityAccessControlHandler extends EntityControllerBase implements EntityAccessControlHandlerInterface {
class EntityAccessControlHandler extends EntityHandlerBase implements EntityAccessControlHandlerInterface {
/**
* Stores calculated access check results.
......@@ -284,7 +284,8 @@ public function fieldAccess($operation, FieldDefinitionInterface $field_definiti
// Get the default access restriction that lives within this field.
$default = $items ? $items->defaultAccess($operation, $account) : TRUE;
// Get the default access restriction as specified by the access controller.
// Get the default access restriction as specified by the access control
// handler.
$entity_default = $this->checkFieldAccess($operation, $field_definition, $account, $items);
// Combine default access, denying access wins.
......@@ -320,7 +321,7 @@ public function fieldAccess($operation, FieldDefinitionInterface $field_definiti
}
/**
* Default field access as determined by this access controller.
* Default field access as determined by this access control handler.
*
* @param string $operation
* The operation access should be checked for.
......
......@@ -14,7 +14,7 @@
use Drupal\Core\Session\AccountInterface;
/**
* Defines a common interface for entity access control handlers.
* Defines an interface for entity access control handlers.
*/
interface EntityAccessControlHandlerInterface {
......
......@@ -8,7 +8,7 @@
namespace Drupal\Core\Entity;
/**
* Defines a common interface for entity change timestamp tracking.
* Defines an interface for entity change timestamp tracking.
*
* This data may be useful for more precise cache invalidation (especially
* on the client side) and concurrent editing locking.
......
......@@ -12,7 +12,7 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines a base entity controller class.
* Defines a base entity storage class.
*
* This class only supports bare, non-content entities.
*/
......
......@@ -89,7 +89,7 @@ public function getFormId() {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// During the initial form build, add this controller to the form state and
// During the initial form build, add this form object to the form state and
// allow for initial preparation before form building and processing.
if (!isset($form_state['controller'])) {
$this->init($form_state);
......@@ -117,7 +117,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
* Initialize the form state and the entity before the first form build.
*/
protected function init(FormStateInterface $form_state) {
// Add the controller to the form state so it can be easily accessed by
// Add the form object to the form state so it can be easily accessed by
// module-provided form handlers there.
$form_state['controller'] = $this;
......@@ -318,8 +318,8 @@ protected function updateFormLangcode(FormStateInterface $form_state) {
public function buildEntity(array $form, FormStateInterface $form_state) {
$entity = clone $this->entity;
// If you submit a form, the form state comes from caching, which forces
// the controller to be the one before caching. Ensure to have the
// controller of the current request.
// the form object to be the one before caching. Ensure to have the
// form object of the current request.
$form_state['controller'] = $this;
$this->copyFormValuesToEntity($entity, $form, $form_state);
......
......@@ -13,7 +13,7 @@
use Drupal\Core\StringTranslation\TranslationInterface;
/**
* Defines a common interface for entity form classes.
* Defines an interface for entity form classes.
*/
interface EntityFormInterface extends BaseFormIdInterface {
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\Core\Entity\EntityControllerBase.
* Contains \Drupal\Core\Entity\EntityHandlerBase.
*/
namespace Drupal\Core\Entity;
......@@ -10,14 +10,13 @@
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
/**
* Provides a base class for entity controllers.
* Provides a base class for entity handlers.
*
* @todo Convert this to a trait.
*/
abstract class EntityControllerBase {
abstract class EntityHandlerBase {
use StringTranslationTrait;
use DependencySerializationTrait;
......@@ -42,7 +41,7 @@ protected function moduleHandler() {
}
/**
* Sets the module handler for this controller.
* Sets the module handler for this handler.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
......
......@@ -2,27 +2,23 @@
/**
* @file
* Contains \Drupal\Core\Entity\EntityControllerInterface.
* Contains \Drupal\Core\Entity\EntityHandlerInterface.
*/
namespace Drupal\Core\Entity;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines a common interface for entity controllers.
* Defines an interface for entity handlers.
*
* This interface can be implemented by entity controllers that require
* dependency injection. These are not controllers in the routing sense of the
* word, but instead are handlers that perform a specific function for an entity
* type.
* This interface can be implemented by entity handlers that require
* dependency injection.
*/
interface EntityControllerInterface {
interface EntityHandlerInterface {
/**
* Instantiates a new instance of this entity controller.
* Instantiates a new instance of this entity handler.
*
* This is a factory method that returns a new instance of this object. The
* factory should pass any needed dependencies into the constructor of this
......@@ -35,7 +31,7 @@ interface EntityControllerInterface {
* The entity type definition.
*
* @return static
* A new instance of the entity controller.
* A new instance of the entity handler.
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type);
......
......@@ -16,7 +16,7 @@
*
* @ingroup entity_api
*/
class EntityListBuilder extends EntityControllerBase implements EntityListBuilderInterface, EntityControllerInterface {
class EntityListBuilder extends EntityHandlerBase implements EntityListBuilderInterface, EntityHandlerInterface {
/**
* The entity storage class.
......
......@@ -54,11 +54,11 @@ class EntityManager extends DefaultPluginManager implements EntityManagerInterfa
protected $extraFields = array();
/**
* Contains instantiated controllers keyed by controller type and entity type.
* Contains instantiated handlers keyed by handler type and entity type.
*
* @var array
*/
protected $controllers = array();
protected $handlers = array();
/**
* Static cache of base field definitions.
......@@ -230,9 +230,9 @@ public function getDefinition($entity_type_id, $exception_on_invalid = TRUE) {
/**
* {@inheritdoc}
*/
public function hasController($entity_type, $controller_type) {
public function hasHandler($entity_type, $handler_type) {
if ($definition = $this->getDefinition($entity_type, FALSE)) {
return $definition->hasControllerClass($controller_type);
return $definition->hasHandlerClass($handler_type);
}
return FALSE;
}
......@@ -241,92 +241,75 @@ public function hasController($entity_type, $controller_type) {
* {@inheritdoc}
*/
public function getStorage($entity_type) {
return $this->getController($entity_type, 'storage', 'getStorageClass');
return $this->getHandler($entity_type, 'storage');
}
/**
* {@inheritdoc}
*/
public function getListBuilder($entity_type) {
return $this->getController($entity_type, 'list_builder', 'getListBuilderClass');
return $this->getHandler($entity_type, 'list_builder');
}
/**
* {@inheritdoc}
*/
public function getFormObject($entity_type, $operation) {
if (!isset($this->controllers['form'][$operation][$entity_type])) {
if (!isset($this->handlers['form'][$operation][$entity_type])) {
if (!$class = $this->getDefinition($entity_type, TRUE)->getFormClass($operation)) {
throw new InvalidPluginDefinitionException($entity_type, sprintf('The "%s" entity type did not specify a "%s" form class.', $entity_type, $operation));
}
$controller = $this->classResolver->getInstanceFromDefinition($class);
$form_object = $this->classResolver->getInstanceFromDefinition($class);
$controller
$form_object
->setStringTranslation($this->translationManager)
->setModuleHandler($this->moduleHandler)
->setOperation($operation);
$this->controllers['form'][$operation][$entity_type] = $controller;
$this->handlers['form'][$operation][$entity_type] = $form_object;
}
return $this->controllers['form'][$operation][$entity_type];
return $this->handlers['form'][$operation][$entity_type];
}
/**
* {@inheritdoc}
*/
public function getViewBuilder($entity_type) {
return $this->getController($entity_type, 'view_builder', 'getViewBuilderClass');
return $this->getHandler($entity_type, 'view_builder');
}
/**
* {@inheritdoc}
*/
public function getAccessControlHandler($entity_type) {
return $this->getController($entity_type, 'access', 'getAccessControlClass');
return $this->getHandler($entity_type, 'access');
}
/**
* Creates a new controller instance.
*
* @param string $entity_type
* The entity type for this controller.
* @param string $controller_type
* The controller type to create an instance for.
* @param string $controller_class_getter
* (optional) The method to call on the entity type object to get the controller class.
*
* @return mixed
* A controller instance.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* {@inheritdoc}
*/
public function getController($entity_type, $controller_type, $controller_class_getter = NULL) {
if (!isset($this->controllers[$controller_type][$entity_type])) {
public function getHandler($entity_type, $handler_type) {
if (!isset($this->handlers[$handler_type][$entity_type])) {
$definition = $this->getDefinition($entity_type);
if ($controller_class_getter) {
$class = $definition->{$controller_class_getter}();
}
else {
$class = $definition->getControllerClass($controller_type);
}
$class = $definition->getHandlerClass($handler_type);
if (!$class) {
throw new InvalidPluginDefinitionException($entity_type, sprintf('The "%s" entity type did not specify a %s class.', $entity_type, $controller_type));
throw new InvalidPluginDefinitionException($entity_type, sprintf('The "%s" entity type did not specify a %s handler.', $entity_type, $handler_type));
}
if (is_subclass_of($class, 'Drupal\Core\Entity\EntityControllerInterface')) {
$controller = $class::createInstance($this->container, $definition);
if (is_subclass_of($class, 'Drupal\Core\Entity\EntityHandlerInterface')) {
$handler = $class::createInstance($this->container, $definition);
}
else {
$controller = new $class($definition);
$handler = new $class($definition);
}
if (method_exists($controller, 'setModuleHandler')) {
$controller->setModuleHandler($this->moduleHandler);
if (method_exists($handler, 'setModuleHandler')) {
$handler->setModuleHandler($this->moduleHandler);
}
if (method_exists($controller, 'setStringTranslation')) {
$controller->setStringTranslation($this->translationManager);
if (method_exists($handler, 'setStringTranslation')) {
$handler->setStringTranslation($this->translationManager);
}
$this->controllers[$controller_type][$entity_type] = $controller;
$this->handlers[$handler_type][$entity_type] = $handler;
}
return $this->controllers[$controller_type][$entity_type];
return $this->handlers[$handler_type][$entity_type];
}
/**
......
......@@ -157,7 +157,7 @@ public function clearCachedBundles();
* The entity type for this view builder.
*
* @return \Drupal\Core\Entity\EntityViewBuilderInterface.
* A render controller instance.
* A view builder instance.
*/
public function getViewBuilder($entity_type);
......@@ -186,32 +186,32 @@ public function getListBuilder($entity_type);
public function getFormObject($entity_type, $operation);
/**
* Checks whether a certain entity type has a certain controller.
* Checks whether a certain entity type has a certain handler.
*
* @param string $entity_type
* The name of the entity type.
* @param string $controller_type
* The name of the controller.
* @param string $handler_type
* The name of the handler.
*
* @return bool
* Returns TRUE if the entity type has the controller, else FALSE.
* Returns TRUE if the entity type has the handler, else FALSE.
*/
public function hasController($entity_type, $controller_type);
public function hasHandler($entity_type, $handler_type);
/**
* Creates a new controller instance.
* Creates a new handler instance.
*
* @param string $entity_type
* The entity type for this controller.
* @param string $controller_type
* @param string $handler_type
* The controller type to create an instance for.
*
* @return mixed
* A controller instance.
* A handler instance.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
*/
public function getController($entity_type, $controller_type);
public function getHandler($entity_type, $handler_type);
/**
* Get the bundle info of an entity type.
......
......@@ -13,7 +13,7 @@
/**
* A base entity storage class.
*/
abstract class EntityStorageBase extends EntityControllerBase implements EntityStorageInterface, EntityControllerInterface {
abstract class EntityStorageBase extends EntityHandlerBase implements EntityStorageInterface, EntityHandlerInterface {
/**
* Static cache of entities, keyed by entity ID.
......@@ -23,7 +23,7 @@ abstract class EntityStorageBase extends EntityControllerBase implements EntityS
protected $entities = array();
/**
* Entity type ID for this controller instance.
* Entity type ID for this storage.
*
* @var string
*/
......
......@@ -8,15 +8,13 @@
namespace Drupal\Core\Entity;
/**
* Defines a common interface for entity storage classes.
* Defines the interface for entity storage classes.
*
* All entity controller classes specified via the "controllers['storage']" key
* returned by \Drupal\Core\Entity\EntityManagerInterface or
* hook_entity_type_alter() have to implement this interface.
*
* Most simple, SQL-based entity controllers will do better by extending
* Drupal\Core\Entity\ContentEntityDatabaseStorage instead of implementing this
* interface directly.
* For common default implementations, see
* \Drupal\Core\Entity\ContentEntityDatabaseStorage for content entities and
* \Drupal\Core\Config\Entity\ConfigEntityStorage for config entities. Those
* implementations are used by default when the @ContentEntityType or
* @ConfigEntityType annotations are used.
*
* @ingroup entity_api
*/
......
......@@ -80,11 +80,11 @@ class EntityType implements EntityTypeInterface {
protected $originalClass;
/**
* An array of controllers.
* An array of handlers.
*
* @var array
*/
protected $controllers = array();
protected $handlers = array();
/**
* The name of the default administrative permission.
......@@ -239,7 +239,7 @@ public function __construct($definition) {
'revision' => '',
'bundle' => ''
);
$this->controllers += array(
$this->handlers += array(
'access' => 'Drupal\Core\Entity\EntityAccessControlHandler',
);
}
......@@ -354,69 +354,69 @@ public function isSubclassOf($class) {
/**
* {@inheritdoc}
*/
public function getControllerClasses() {
return $this->controllers;
public function getHandlerClasses() {
return $this->handlers;
}
/**
* {@inheritdoc}
*/
public function getControllerClass($controller_type, $nested = FALSE) {
if ($this->hasControllerClass($controller_type, $nested)) {
$controllers = $this->getControllerClasses();
return $nested ? $controllers[$controller_type][$nested] : $controllers[$controller_type];
public function getHandlerClass($handler_type, $nested = FALSE) {
if ($this->hasHandlerClass($handler_type, $nested)) {
$handlers = $this->getHandlerClasses();
return $nested ? $handlers[$handler_type][$nested] : $handlers[$handler_type];
}
}
/**
* {@inheritdoc}
*/
public function setControllerClass($controller_type, $value) {
$this->controllers[$controller_type] = $value;
public function setHandlerClass($handler_type, $value) {
$this->handlers[$handler_type] = $value;
return $this;
}
/**
* {@inheritdoc}
*/
public function hasControllerClass($controller_type, $nested = FALSE) {
$controllers = $this->getControllerClasses();
if (!isset($controllers[$controller_type]) || ($nested && !isset($controllers[$controller_type][$nested]))) {
public function hasHandlerClass($handler_type, $nested = FALSE) {
$handlers = $this->getHandlerClasses();
if (!isset($handlers[$handler_type]) || ($nested && !isset($handlers[$handler_type][$nested]))) {
return FALSE;
}
$controller = $controllers[$controller_type];
$handler = $handlers[$handler_type];
if ($nested) {
$controller = $controller[$nested];
$handler = $handler[$nested];
}
return class_exists($controller);
return class_exists($handler);
}
/**
* {@inheritdoc}
*/
public function getStorageClass() {
return $this->getControllerClass('storage');
return $this->getHandlerClass('storage');
}
/**
* {@inheritdoc}
*/
public function setStorageClass($class) {
$this->controllers['storage'] = $class;
$this->handlers['storage'] = $class;
}
/**
* {@inheritdoc}
*/
public function getFormClass($operation) {
return $this->getControllerClass('form', $operation);
return $this->getHandlerClass('form', $operation);
}
/**
* {@inheritdoc}
*/
public function setFormClass($operation, $class) {
$this->controllers['form'][$operation] = $class;
$this->handlers['form'][$operation] = $class;
return $this;
}
......@@ -424,21 +424,21 @@ public function setFormClass($operation, $class) {
* {@inheritdoc}
*/
public function hasFormClasses() {
return !empty($this->controllers['form']);
return !empty($this->handlers['form']);
}
/**
* {@inheritdoc}
*/
public function getListBuilderClass() {
return $this->getControllerClass('list_builder');
return $this->getHandlerClass('list_builder');
}
/**
* {@inheritdoc}
*/
public function setListBuilderClass($class) {
$this->controllers['list_builder'] = $class;
$this->handlers['list_builder'] = $class;
return $this;
}
......@@ -446,21 +446,21 @@ public function setListBuilderClass($class) {
* {@inheritdoc}
*/
public function hasListBuilderClass() {
return $this->hasControllerClass('list_builder');
return $this->hasHandlerClass('list_builder');