Commit bc3a902f authored by alexpott's avatar alexpott

Issue #1807042 by tim.plunkett, effulgentsia: Rename entity...

Issue #1807042 by tim.plunkett, effulgentsia: Rename entity storage/list/form/render controllers to handlers, part 1: organize existing annotation keys.
parent 91fc0d3e
...@@ -26,8 +26,8 @@ ...@@ -26,8 +26,8 @@
function hook_entity_info(&$entity_info) { function hook_entity_info(&$entity_info) {
// Add a form controller for a custom node form without overriding the default // Add a form controller for a custom node form without overriding the default
// node form. To override the default node form, use hook_entity_info_alter() // node form. To override the default node form, use hook_entity_info_alter()
// to alter $entity_info['node']['form_controller_class']['default']. // to alter $entity_info['node']['controllers']['form']['default'].
$entity_info['node']['form_controller_class']['mymodule_foo'] = 'Drupal\mymodule\NodeFooFormController'; $entity_info['node']['controllers']['form']['mymodule_foo'] = 'Drupal\mymodule\NodeFooFormController';
} }
/** /**
...@@ -216,7 +216,7 @@ function hook_entity_bundle_delete($entity_type, $bundle) { ...@@ -216,7 +216,7 @@ function hook_entity_bundle_delete($entity_type, $bundle) {
function hook_entity_info_alter(&$entity_info) { function hook_entity_info_alter(&$entity_info) {
// Set the controller class for nodes to an alternate implementation of the // Set the controller class for nodes to an alternate implementation of the
// Drupal\Core\Entity\EntityStorageControllerInterface interface. // Drupal\Core\Entity\EntityStorageControllerInterface interface.
$entity_info['node']['controller_class'] = 'Drupal\mymodule\MyCustomNodeStorageController'; $entity_info['node']['controllers']['storage'] = 'Drupal\mymodule\MyCustomNodeStorageController';
} }
/** /**
......
...@@ -250,8 +250,8 @@ function entity_load_by_uuid($entity_type, $uuid, $reset = FALSE) { ...@@ -250,8 +250,8 @@ function entity_load_by_uuid($entity_type, $uuid, $reset = FALSE) {
* Drupal\Core\Entity\EntityStorageControllerInterface interface. By default, * Drupal\Core\Entity\EntityStorageControllerInterface interface. By default,
* Drupal\Core\Entity\DatabaseStorageController is used. Entity types can * Drupal\Core\Entity\DatabaseStorageController is used. Entity types can
* specify that a different class should be used by setting the * specify that a different class should be used by setting the
* 'controller_class' key in the entity plugin annotation. These classes can * "controllers['storage']" key in the entity plugin annotation. These classes
* either implement the Drupal\Core\Entity\EntityStorageControllerInterface * can either implement the Drupal\Core\Entity\EntityStorageControllerInterface
* interface, or, most commonly, extend the * interface, or, most commonly, extend the
* Drupal\Core\Entity\DatabaseStorageController class. * Drupal\Core\Entity\DatabaseStorageController class.
* See Drupal\node\Plugin\Core\Entity\Node and Drupal\node\NodeStorageController * See Drupal\node\Plugin\Core\Entity\Node and Drupal\node\NodeStorageController
......
...@@ -42,13 +42,37 @@ class EntityType extends Plugin { ...@@ -42,13 +42,37 @@ class EntityType extends Plugin {
public $base_table; public $base_table;
/** /**
* The name of the class that is used to load the objects. * An associative array where the keys are the names of different controller
* types (listed below) and the values are the names of the classes that
* implement that controller:
* - storage: The name of the class that is used to load the objects. The
* class must implement \Drupal\Core\Entity\EntityStorageControllerInterface.
* - form: An associative array where the keys are the names of the different
* form operations (such as 'create', 'edit', or 'delete') and the values
* are the names of the controller classes for those operations. The name of
* the operation is passed also to the form controller's constructor, so
* that one class can be used for multiple entity forms when the forms are
* similar. The classes must implement
* \Drupal\Core\Entity\EntityFormControllerInterface
* - list: The name of the class that provides listings of the entities. The
* class must implement \Drupal\Core\Entity\EntityListControllerInterface.
* - render: The name of the class that is used to render the entities. The
* class must implement \Drupal\Core\Entity\EntityRenderControllerInterface.
* - access: The name of the class that is used for access checks. The class
* must implement \Drupal\Core\Entity\EntityAccessControllerInterface.
* Defaults to \Drupal\Core\Entity\EntityAccessController.
* - translation: The name of the controller class that should be used to
* handle the translation process. The class must implement
* \Drupal\translation_entity\EntityTranslationControllerInterface.
* *
* This must implement \Drupal\Core\Entity\EntityStorageControllerInterface. * @todo Interfaces from outside \Drupal\Core or \Drupal\Component should not
* be used here.
* *
* @var string * @var array
*/ */
public $controller_class = 'Drupal\Core\Entity\DatabaseStorageController'; public $controllers = array(
'access' => 'Drupal\Core\Entity\EntityAccessController',
);
/** /**
* Boolean indicating whether fields can be attached to entities of this type. * Boolean indicating whether fields can be attached to entities of this type.
...@@ -67,20 +91,6 @@ class EntityType extends Plugin { ...@@ -67,20 +91,6 @@ class EntityType extends Plugin {
*/ */
public $field_cache = TRUE; public $field_cache = TRUE;
/**
* The names of classes for various form operations.
*
* An associative array where the keys are the names of the different form
* operations (such as 'create', 'edit', or 'delete') and the values are the
* names of the controller classes for those operations. The name of the
* operation is passed also to the form controller's constructor, so that one
* class can be used for multiple entity forms when the forms are similar.
* Defaults to Drupal\Core\Entity\EntityFormController.
*
* @var array (optional)
*/
public $form_controller_class = array('Drupal\Core\Entity\EntityFormController');
/** /**
* The human-readable name of the type. * The human-readable name of the type.
* *
...@@ -114,43 +124,6 @@ class EntityType extends Plugin { ...@@ -114,43 +124,6 @@ class EntityType extends Plugin {
*/ */
public $label_callback; public $label_callback;
/**
* The name of the class that provides listings of the entities.
*
* The class must implement \Drupal\Core\Entity\EntityListControllerInterface.
*
* @var string
*/
public $list_controller_class = 'Drupal\Core\Entity\EntityListController';
/**
* The name of the class that is used to render the entities.
*
* @var string
*/
public $render_controller_class;
/**
* The name of the class that is used for access checks.
*
* The class must implement \Drupal\Core\Entity\EntityAccessControllerInterface.
*
* @var string
*/
public $access_controller_class = 'Drupal\Core\Entity\EntityAccessController';
/**
* The name of the translation controller class that should be used to handle the translation process.
*
* The class must implement \Drupal\translation_entity\EntityTranslationControllerInterface.
*
* @todo Interfaces from outside \Drupal\Core or \Drupal\Component should not
* be used here.
*
* @var string
*/
public $translation_controller_class;
/** /**
* Boolean indicating whether entities should be statically cached during a page request. * Boolean indicating whether entities should be statically cached during a page request.
* *
......
...@@ -70,7 +70,7 @@ public function __construct(array $namespaces) { ...@@ -70,7 +70,7 @@ public function __construct(array $namespaces) {
*/ */
public function hasController($entity_type, $controller_type) { public function hasController($entity_type, $controller_type) {
$definition = $this->getDefinition($entity_type); $definition = $this->getDefinition($entity_type);
return !empty($definition[$controller_type]); return !empty($definition['controllers'][$controller_type]);
} }
/** /**
...@@ -89,6 +89,7 @@ public function hasController($entity_type, $controller_type) { ...@@ -89,6 +89,7 @@ public function hasController($entity_type, $controller_type) {
*/ */
public function getControllerClass($entity_type, $controller_type, $nested = NULL) { public function getControllerClass($entity_type, $controller_type, $nested = NULL) {
$definition = $this->getDefinition($entity_type); $definition = $this->getDefinition($entity_type);
$definition = $definition['controllers'];
if (empty($definition[$controller_type])) { if (empty($definition[$controller_type])) {
throw new \InvalidArgumentException(sprintf('The entity (%s) did not specify a %s.', $entity_type, $controller_type)); throw new \InvalidArgumentException(sprintf('The entity (%s) did not specify a %s.', $entity_type, $controller_type));
} }
...@@ -122,7 +123,7 @@ public function getControllerClass($entity_type, $controller_type, $nested = NUL ...@@ -122,7 +123,7 @@ public function getControllerClass($entity_type, $controller_type, $nested = NUL
*/ */
public function getStorageController($entity_type) { public function getStorageController($entity_type) {
if (!isset($this->controllers['storage'][$entity_type])) { if (!isset($this->controllers['storage'][$entity_type])) {
$class = $this->getControllerClass($entity_type, 'controller_class'); $class = $this->getControllerClass($entity_type, 'storage');
$this->controllers['storage'][$entity_type] = new $class($entity_type); $this->controllers['storage'][$entity_type] = new $class($entity_type);
} }
return $this->controllers['storage'][$entity_type]; return $this->controllers['storage'][$entity_type];
...@@ -139,7 +140,7 @@ public function getStorageController($entity_type) { ...@@ -139,7 +140,7 @@ public function getStorageController($entity_type) {
*/ */
public function getListController($entity_type) { public function getListController($entity_type) {
if (!isset($this->controllers['listing'][$entity_type])) { if (!isset($this->controllers['listing'][$entity_type])) {
$class = $this->getControllerClass($entity_type, 'list_controller_class'); $class = $this->getControllerClass($entity_type, 'list');
$this->controllers['listing'][$entity_type] = new $class($entity_type, $this->getStorageController($entity_type)); $this->controllers['listing'][$entity_type] = new $class($entity_type, $this->getStorageController($entity_type));
} }
return $this->controllers['listing'][$entity_type]; return $this->controllers['listing'][$entity_type];
...@@ -158,7 +159,7 @@ public function getListController($entity_type) { ...@@ -158,7 +159,7 @@ public function getListController($entity_type) {
*/ */
public function getFormController($entity_type, $operation) { public function getFormController($entity_type, $operation) {
if (!isset($this->controllers['form'][$operation][$entity_type])) { if (!isset($this->controllers['form'][$operation][$entity_type])) {
$class = $this->getControllerClass($entity_type, 'form_controller_class', $operation); $class = $this->getControllerClass($entity_type, 'form', $operation);
$this->controllers['form'][$operation][$entity_type] = new $class($operation); $this->controllers['form'][$operation][$entity_type] = new $class($operation);
} }
return $this->controllers['form'][$operation][$entity_type]; return $this->controllers['form'][$operation][$entity_type];
...@@ -175,7 +176,7 @@ public function getFormController($entity_type, $operation) { ...@@ -175,7 +176,7 @@ public function getFormController($entity_type, $operation) {
*/ */
public function getRenderController($entity_type) { public function getRenderController($entity_type) {
if (!isset($this->controllers['render'][$entity_type])) { if (!isset($this->controllers['render'][$entity_type])) {
$class = $this->getControllerClass($entity_type, 'render_controller_class'); $class = $this->getControllerClass($entity_type, 'render');
$this->controllers['render'][$entity_type] = new $class($entity_type); $this->controllers['render'][$entity_type] = new $class($entity_type);
} }
return $this->controllers['render'][$entity_type]; return $this->controllers['render'][$entity_type];
...@@ -192,7 +193,7 @@ public function getRenderController($entity_type) { ...@@ -192,7 +193,7 @@ public function getRenderController($entity_type) {
*/ */
public function getAccessController($entity_type) { public function getAccessController($entity_type) {
if (!isset($this->controllers['access'][$entity_type])) { if (!isset($this->controllers['access'][$entity_type])) {
$class = $this->getControllerClass($entity_type, 'access_controller_class'); $class = $this->getControllerClass($entity_type, 'access');
$this->controllers['access'][$entity_type] = new $class($entity_type); $this->controllers['access'][$entity_type] = new $class($entity_type);
} }
return $this->controllers['access'][$entity_type]; return $this->controllers['access'][$entity_type];
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
/** /**
* Defines a common interface for entity controller classes. * Defines a common interface for entity controller classes.
* *
* All entity controller classes specified via the 'controller_class' key * All entity controller classes specified via the "controllers['storage']" key
* returned by \Drupal\Core\Entity\EntityManager or hook_entity_info_alter() * returned by \Drupal\Core\Entity\EntityManager or hook_entity_info_alter()
* have to implement this interface. * have to implement this interface.
* *
......
...@@ -19,10 +19,12 @@ ...@@ -19,10 +19,12 @@
* id = "aggregator_feed", * id = "aggregator_feed",
* label = @Translation("Aggregator feed"), * label = @Translation("Aggregator feed"),
* module = "aggregator", * module = "aggregator",
* controller_class = "Drupal\aggregator\FeedStorageController", * controllers = {
* render_controller_class = "Drupal\aggregator\FeedRenderController", * "storage" = "Drupal\aggregator\FeedStorageController",
* form_controller_class = { * "render" = "Drupal\aggregator\FeedRenderController",
* "default" = "Drupal\aggregator\FeedFormController" * "form" = {
* "default" = "Drupal\aggregator\FeedFormController"
* }
* }, * },
* base_table = "aggregator_feed", * base_table = "aggregator_feed",
* fieldable = TRUE, * fieldable = TRUE,
......
...@@ -19,8 +19,10 @@ ...@@ -19,8 +19,10 @@
* id = "aggregator_item", * id = "aggregator_item",
* label = @Translation("Aggregator feed item"), * label = @Translation("Aggregator feed item"),
* module = "aggregator", * module = "aggregator",
* controller_class = "Drupal\aggregator\ItemStorageController", * controllers = {
* render_controller_class = "Drupal\aggregator\ItemRenderController", * "storage" = "Drupal\aggregator\ItemStorageController",
* "render" = "Drupal\aggregator\ItemRenderController"
* },
* base_table = "aggregator_item", * base_table = "aggregator_item",
* fieldable = TRUE, * fieldable = TRUE,
* entity_keys = { * entity_keys = {
......
...@@ -20,13 +20,15 @@ ...@@ -20,13 +20,15 @@
* label = @Translation("Custom Block"), * label = @Translation("Custom Block"),
* bundle_label = @Translation("Custom Block type"), * bundle_label = @Translation("Custom Block type"),
* module = "custom_block", * module = "custom_block",
* controller_class = "Drupal\custom_block\CustomBlockStorageController", * controllers = {
* access_controller_class = "Drupal\custom_block\CustomBlockAccessController", * "storage" = "Drupal\custom_block\CustomBlockStorageController",
* render_controller_class = "Drupal\custom_block\CustomBlockRenderController", * "access" = "Drupal\custom_block\CustomBlockAccessController",
* form_controller_class = { * "render" = "Drupal\custom_block\CustomBlockRenderController",
* "default" = "Drupal\custom_block\CustomBlockFormController" * "form" = {
* "default" = "Drupal\custom_block\CustomBlockFormController"
* },
* "translation" = "Drupal\custom_block\CustomBlockTranslationController"
* }, * },
* translation_controller_class = "Drupal\custom_block\CustomBlockTranslationController",
* base_table = "custom_block", * base_table = "custom_block",
* revision_table = "custom_block_revision", * revision_table = "custom_block_revision",
* menu_base_path = "block/%custom_block", * menu_base_path = "block/%custom_block",
......
...@@ -18,10 +18,12 @@ ...@@ -18,10 +18,12 @@
* id = "custom_block_type", * id = "custom_block_type",
* label = @Translation("Custom block type"), * label = @Translation("Custom block type"),
* module = "custom_block", * module = "custom_block",
* controller_class = "Drupal\custom_block\CustomBlockTypeStorageController", * controllers = {
* list_controller_class = "Drupal\custom_block\CustomBlockTypeListController", * "storage" = "Drupal\custom_block\CustomBlockTypeStorageController",
* form_controller_class = { * "form" = {
* "default" = "Drupal\custom_block\CustomBlockTypeFormController" * "default" = "Drupal\custom_block\CustomBlockTypeFormController"
* },
* "list" = "Drupal\custom_block\CustomBlockTypeListController"
* }, * },
* config_prefix = "custom_block.type", * config_prefix = "custom_block.type",
* entity_keys = { * entity_keys = {
......
...@@ -19,12 +19,14 @@ ...@@ -19,12 +19,14 @@
* id = "block", * id = "block",
* label = @Translation("Block"), * label = @Translation("Block"),
* module = "block", * module = "block",
* controller_class = "Drupal\block\BlockStorageController", * controllers = {
* access_controller_class = "Drupal\block\BlockAccessController", * "storage" = "Drupal\block\BlockStorageController",
* render_controller_class = "Drupal\block\BlockRenderController", * "access" = "Drupal\block\BlockAccessController",
* list_controller_class = "Drupal\block\BlockListController", * "render" = "Drupal\block\BlockRenderController",
* form_controller_class = { * "list" = "Drupal\block\BlockListController",
* "default" = "Drupal\block\BlockFormController" * "form" = {
* "default" = "Drupal\block\BlockFormController"
* }
* }, * },
* config_prefix = "block.block", * config_prefix = "block.block",
* fieldable = FALSE, * fieldable = FALSE,
......
...@@ -23,7 +23,9 @@ ...@@ -23,7 +23,9 @@
* id = "breakpoint", * id = "breakpoint",
* label = @Translation("Breakpoint"), * label = @Translation("Breakpoint"),
* module = "breakpoint", * module = "breakpoint",
* controller_class = "Drupal\Core\Config\Entity\ConfigStorageController", * controllers = {
* "storage" = "Drupal\Core\Config\Entity\ConfigStorageController"
* },
* config_prefix = "breakpoint.breakpoint", * config_prefix = "breakpoint.breakpoint",
* entity_keys = { * entity_keys = {
* "id" = "id", * "id" = "id",
......
...@@ -20,7 +20,9 @@ ...@@ -20,7 +20,9 @@
* id = "breakpoint_group", * id = "breakpoint_group",
* label = @Translation("Breakpoint group"), * label = @Translation("Breakpoint group"),
* module = "breakpoint", * module = "breakpoint",
* controller_class = "Drupal\Core\Config\Entity\ConfigStorageController", * controllers = {
* "storage" = "Drupal\Core\Config\Entity\ConfigStorageController"
* },
* config_prefix = "breakpoint.breakpoint_group", * config_prefix = "breakpoint.breakpoint_group",
* entity_keys = { * entity_keys = {
* "id" = "id", * "id" = "id",
......
...@@ -20,13 +20,15 @@ ...@@ -20,13 +20,15 @@
* label = @Translation("Comment"), * label = @Translation("Comment"),
* bundle_label = @Translation("Content type"), * bundle_label = @Translation("Content type"),
* module = "comment", * module = "comment",
* controller_class = "Drupal\comment\CommentStorageController", * controllers = {
* access_controller_class = "Drupal\comment\CommentAccessController", * "storage" = "Drupal\comment\CommentStorageController",
* render_controller_class = "Drupal\comment\CommentRenderController", * "access" = "Drupal\comment\CommentAccessController",
* form_controller_class = { * "render" = "Drupal\comment\CommentRenderController",
* "default" = "Drupal\comment\CommentFormController" * "form" = {
* "default" = "Drupal\comment\CommentFormController"
* },
* "translation" = "Drupal\comment\CommentTranslationController"
* }, * },
* translation_controller_class = "Drupal\comment\CommentTranslationController",
* base_table = "comment", * base_table = "comment",
* uri_callback = "comment_uri", * uri_callback = "comment_uri",
* fieldable = TRUE, * fieldable = TRUE,
......
...@@ -17,10 +17,12 @@ ...@@ -17,10 +17,12 @@
* id = "config_query_test", * id = "config_query_test",
* label = @Translation("Test configuration for query"), * label = @Translation("Test configuration for query"),
* module = "config_test", * module = "config_test",
* controller_class = "Drupal\config_test\ConfigTestStorageController", * controllers = {
* list_controller_class = "Drupal\Core\Config\Entity\ConfigEntityListController", * "storage" = "Drupal\config_test\ConfigTestStorageController",
* form_controller_class = { * "list" = "Drupal\Core\Config\Entity\ConfigEntityListController",
* "default" = "Drupal\config_test\ConfigTestFormController" * "form" = {
* "default" = "Drupal\config_test\ConfigTestFormController"
* }
* }, * },
* uri_callback = "config_test_uri", * uri_callback = "config_test_uri",
* config_prefix = "config_query_test.dynamic", * config_prefix = "config_query_test.dynamic",
......
...@@ -18,10 +18,12 @@ ...@@ -18,10 +18,12 @@
* id = "config_test", * id = "config_test",
* label = @Translation("Test configuration"), * label = @Translation("Test configuration"),
* module = "config_test", * module = "config_test",
* controller_class = "Drupal\config_test\ConfigTestStorageController", * controllers = {
* list_controller_class = "Drupal\Core\Config\Entity\ConfigEntityListController", * "storage" = "Drupal\config_test\ConfigTestStorageController",
* form_controller_class = { * "list" = "Drupal\Core\Config\Entity\ConfigEntityListController",
* "default" = "Drupal\config_test\ConfigTestFormController" * "form" = {
* "default" = "Drupal\config_test\ConfigTestFormController"
* }
* }, * },
* uri_callback = "config_test_uri", * uri_callback = "config_test_uri",
* config_prefix = "config_test.dynamic", * config_prefix = "config_test.dynamic",
......
...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
* id = "config_test_empty_manifest", * id = "config_test_empty_manifest",
* label = @Translation("Test empty manifest creation"), * label = @Translation("Test empty manifest creation"),
* module = "config_test", * module = "config_test",
* controller_class = "Drupal\config_test\ConfigTestStorageController", * controllers = {
* "storage" = "Drupal\config_test\ConfigTestStorageController"
* },
* config_prefix = "config_test.empty_manifest", * config_prefix = "config_test.empty_manifest",
* entity_keys = { * entity_keys = {
* "id" = "id", * "id" = "id",
......
...@@ -18,10 +18,12 @@ ...@@ -18,10 +18,12 @@
* id = "contact_category", * id = "contact_category",
* label = @Translation("Contact category"), * label = @Translation("Contact category"),
* module = "contact", * module = "contact",
* controller_class = "Drupal\contact\CategoryStorageController", * controllers = {
* list_controller_class = "Drupal\contact\CategoryListController", * "storage" = "Drupal\contact\CategoryStorageController",
* form_controller_class = { * "list" = "Drupal\contact\CategoryListController",
* "default" = "Drupal\contact\CategoryFormController" * "form" = {
* "default" = "Drupal\contact\CategoryFormController"
* }
* }, * },
* uri_callback = "contact_category_uri", * uri_callback = "contact_category_uri",
* config_prefix = "contact.category", * config_prefix = "contact.category",
......
...@@ -18,10 +18,13 @@ ...@@ -18,10 +18,13 @@
* id = "contact_message", * id = "contact_message",
* label = @Translation("Contact message"), * label = @Translation("Contact message"),
* module = "contact", * module = "contact",
* form_controller_class = { * controllers = {
* "default" = "Drupal\contact\MessageFormController" * "storage" = "Drupal\Core\Entity\DatabaseStorageController",
* "render" = "Drupal\contact\MessageRenderController",
* "form" = {
* "default" = "Drupal\contact\MessageFormController"
* }
* }, * },
* render_controller_class = "Drupal\contact\MessageRenderController",
* entity_keys = { * entity_keys = {
* "bundle" = "category" * "bundle" = "category"
* }, * },
......
...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
* id = "editor", * id = "editor",
* label = @Translation("Editor"), * label = @Translation("Editor"),
* module = "editor", * module = "editor",
* controller_class = "Drupal\Core\Config\Entity\ConfigStorageController", * controllers = {
* "storage" = "Drupal\Core\Config\Entity\ConfigStorageController"
* },
* config_prefix = "editor.editor", * config_prefix = "editor.editor",
* entity_keys = { * entity_keys = {
* "id" = "format", * "id" = "format",
......
...@@ -19,7 +19,9 @@ ...@@ -19,7 +19,9 @@
* id = "entity_display", * id = "entity_display",
* label = @Translation("Entity display"), * label = @Translation("Entity display"),
* module = "entity", * module = "entity",
* controller_class = "Drupal\Core\Config\Entity\ConfigStorageController", * controllers = {
* "storage" = "Drupal\Core\Config\Entity\ConfigStorageController"
* },
* config_prefix = "entity.display", * config_prefix = "entity.display",
* entity_keys = { * entity_keys = {
* "id" = "id", * "id" = "id",
......
...@@ -22,7 +22,9 @@ ...@@ -22,7 +22,9 @@
* id = "field_entity", * id = "field_entity",
* label = @Translation("Field"),