diff --git a/core/lib/Drupal/Core/Entity/EntityAccessController.php b/core/lib/Drupal/Core/Entity/EntityAccessController.php index a811110..128c28f 100644 --- a/core/lib/Drupal/Core/Entity/EntityAccessController.php +++ b/core/lib/Drupal/Core/Entity/EntityAccessController.php @@ -33,6 +33,13 @@ class EntityAccessController implements EntityAccessControllerInterface { protected $entityType; /** + * The entity info array. + * + * @var array + */ + protected $entityInfo; + + /** * The module handler service. * * @var \Drupal\Core\Extension\ModuleHandlerInterface @@ -44,9 +51,12 @@ class EntityAccessController implements EntityAccessControllerInterface { * * @param string $entity_type * The entity type of the access controller instance. + * @param array $entity_info + * An array of entity info for the entity type. */ - public function __construct($entity_type) { + public function __construct($entity_type, array $entity_info) { $this->entityType = $entity_type; + $this->entityInfo = $entity_info; } /** @@ -127,7 +137,12 @@ protected function processAccessHookResults(array $access) { * could not be determined. */ protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { - return NULL; + if (!empty($this->entityInfo['admin_permission'])) { + return $account->hasPermission($this->entityInfo['admin_permission']); + } + else { + return NULL; + } } /** @@ -243,7 +258,12 @@ public function createAccess($entity_bundle = NULL, AccountInterface $account = * could not be determined. */ protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { - return NULL; + if (!empty($this->entityInfo['admin_permission'])) { + return $account->hasPermission($this->entityInfo['admin_permission']); + } + else { + return NULL; + } } /** diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index e9808d2..90bf5d1 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -354,7 +354,7 @@ protected function getController($entity_type, $controller_type) { $this->controllers[$controller_type][$entity_type] = $class::createInstance($this->container, $entity_type, $this->getDefinition($entity_type)); } else { - $this->controllers[$controller_type][$entity_type] = new $class($entity_type); + $this->controllers[$controller_type][$entity_type] = new $class($entity_type, $this->getDefinition($entity_type)); } } return $this->controllers[$controller_type][$entity_type]; diff --git a/core/modules/action/lib/Drupal/action/ActionAccessController.php b/core/modules/action/lib/Drupal/action/ActionAccessController.php deleted file mode 100644 index d94edd3..0000000 --- a/core/modules/action/lib/Drupal/action/ActionAccessController.php +++ /dev/null @@ -1,24 +0,0 @@ -aliasManager = $alias_manager; } @@ -46,6 +48,7 @@ public function __construct($entity_type, AliasManagerInterface $alias_manager) public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) { return new static( $entity_type, + $entity_info, $container->get('path.alias_manager') ); } diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestAccessController.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestAccessController.php index f084453..cec5421 100644 --- a/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestAccessController.php +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestAccessController.php @@ -20,7 +20,7 @@ class ConfigTestAccessController extends EntityAccessController { /** * {@inheritdoc} */ - public function access(EntityInterface $entity, $operation, $langcode = Language::LANGCODE_DEFAULT, AccountInterface $account = NULL) { + public function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { return TRUE; } diff --git a/core/modules/entity/lib/Drupal/entity/Entity/EntityFormMode.php b/core/modules/entity/lib/Drupal/entity/Entity/EntityFormMode.php index ac13757..c0b1c6c 100644 --- a/core/modules/entity/lib/Drupal/entity/Entity/EntityFormMode.php +++ b/core/modules/entity/lib/Drupal/entity/Entity/EntityFormMode.php @@ -35,7 +35,7 @@ * module = "entity", * controllers = { * "list" = "Drupal\entity\EntityFormModeListController", - * "access" = "Drupal\entity\EntityDisplayModeAccessController", + * "access" = "Drupal\Core\Entity\EntityAccessController", * "form" = { * "add" = "Drupal\entity\Form\EntityFormModeAddForm", * "edit" = "Drupal\entity\Form\EntityDisplayModeEditForm", @@ -43,6 +43,7 @@ * }, * "storage" = "Drupal\entity\EntityDisplayModeStorageController" * }, + * admin_permission = "administer display modes", * config_prefix = "entity.form_mode", * entity_keys = { * "id" = "id", diff --git a/core/modules/entity/lib/Drupal/entity/Entity/EntityViewMode.php b/core/modules/entity/lib/Drupal/entity/Entity/EntityViewMode.php index c46ef60..6a4abad 100644 --- a/core/modules/entity/lib/Drupal/entity/Entity/EntityViewMode.php +++ b/core/modules/entity/lib/Drupal/entity/Entity/EntityViewMode.php @@ -36,7 +36,6 @@ * module = "entity", * controllers = { * "list" = "Drupal\entity\EntityDisplayModeListController", - * "access" = "Drupal\entity\EntityDisplayModeAccessController", * "form" = { * "add" = "Drupal\entity\Form\EntityDisplayModeAddForm", * "edit" = "Drupal\entity\Form\EntityDisplayModeEditForm", @@ -44,6 +43,7 @@ * }, * "storage" = "Drupal\entity\EntityDisplayModeStorageController" * }, + * admin_permission = "administer display modes", * config_prefix = "entity.view_mode", * entity_keys = { * "id" = "id", diff --git a/core/modules/entity/lib/Drupal/entity/EntityDisplayModeAccessController.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayModeAccessController.php deleted file mode 100644 index 92e8f42..0000000 --- a/core/modules/entity/lib/Drupal/entity/EntityDisplayModeAccessController.php +++ /dev/null @@ -1,31 +0,0 @@ -hasPermission('administer display modes'); - } - } - -} diff --git a/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php b/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php index aabef1e..bd8feb9 100644 --- a/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php +++ b/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php @@ -33,8 +33,8 @@ * }, * "storage" = "Drupal\Core\Config\Entity\ConfigStorageController", * "list" = "Drupal\image\ImageStyleListController", - * "access" = "Drupal\image\ImageStyleAccessController" * }, + * admin_permission = "administer image styles", * config_prefix = "image.style", * entity_keys = { * "id" = "name", diff --git a/core/modules/image/lib/Drupal/image/ImageStyleAccessController.php b/core/modules/image/lib/Drupal/image/ImageStyleAccessController.php deleted file mode 100644 index deb9123..0000000 --- a/core/modules/image/lib/Drupal/image/ImageStyleAccessController.php +++ /dev/null @@ -1,34 +0,0 @@ -hasPermission('administer image styles'); - break; - } - } - -} diff --git a/core/modules/language/lib/Drupal/language/Entity/Language.php b/core/modules/language/lib/Drupal/language/Entity/Language.php index 53e721f..c1c1006 100644 --- a/core/modules/language/lib/Drupal/language/Entity/Language.php +++ b/core/modules/language/lib/Drupal/language/Entity/Language.php @@ -31,6 +31,7 @@ * "delete" = "Drupal\language\Form\LanguageDeleteForm" * } * }, + * admin_permission = "administer languages", * config_prefix = "language.entity", * entity_keys = { * "id" = "id", diff --git a/core/modules/language/lib/Drupal/language/LanguageAccessController.php b/core/modules/language/lib/Drupal/language/LanguageAccessController.php index 1609dd0..2cc17d0 100644 --- a/core/modules/language/lib/Drupal/language/LanguageAccessController.php +++ b/core/modules/language/lib/Drupal/language/LanguageAccessController.php @@ -17,21 +17,14 @@ class LanguageAccessController extends EntityAccessController { /** * {@inheritdoc} */ - public function access(EntityInterface $entity, $operation, $langcode = Language::LANGCODE_DEFAULT, AccountInterface $account = NULL) { + public function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { switch ($operation) { case 'update': case 'delete': - return !$entity->locked && user_access('administer languages'); + return !$entity->locked && parent::checkAccess($entity, $operation, $langcode, $account); break; } return FALSE; } - /** - * {@inheritdoc} - */ - protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { - return $account->hasPermission('administer languages'); - } - } diff --git a/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php b/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php index a238ad6..616755f 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php @@ -33,6 +33,7 @@ * "default" = "Drupal\menu_link\MenuLinkFormController" * } * }, + * admin_permission = "administer menu", * static_cache = FALSE, * base_table = "menu_links", * uri_callback = "menu_link_uri", diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkAccessController.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkAccessController.php index a1c2c69..85cc796 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkAccessController.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkAccessController.php @@ -38,11 +38,4 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A return $access; } - /** - * {@inheritdoc} - */ - protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { - return $account->hasPermission('administer menu'); - } - } diff --git a/core/modules/node/lib/Drupal/node/Entity/NodeType.php b/core/modules/node/lib/Drupal/node/Entity/NodeType.php index 8a63816..5bc423e 100644 --- a/core/modules/node/lib/Drupal/node/Entity/NodeType.php +++ b/core/modules/node/lib/Drupal/node/Entity/NodeType.php @@ -30,6 +30,7 @@ * }, * "list" = "Drupal\node\NodeTypeListController", * }, + * admin_permission = "administer content types", * config_prefix = "node.type", * bundle_of = "node", * entity_keys = { diff --git a/core/modules/node/lib/Drupal/node/NodeAccessController.php b/core/modules/node/lib/Drupal/node/NodeAccessController.php index 0f06917..944b411 100644 --- a/core/modules/node/lib/Drupal/node/NodeAccessController.php +++ b/core/modules/node/lib/Drupal/node/NodeAccessController.php @@ -35,11 +35,13 @@ class NodeAccessController extends EntityAccessController implements NodeAccessC * * @param string $entity_type * The entity type of the access controller instance. + * @param array $entity_info + * An array of entity info for the entity type. * @param \Drupal\node\NodeGrantDatabaseStorageInterface $grant_storage * The node grant storage. */ - public function __construct($entity_type, NodeGrantDatabaseStorageInterface $grant_storage) { - parent::__construct($entity_type); + public function __construct($entity_type, array $entity_info, NodeGrantDatabaseStorageInterface $grant_storage) { + parent::__construct($entity_type, $entity_info); $this->grantStorage = $grant_storage; } @@ -49,6 +51,7 @@ public function __construct($entity_type, NodeGrantDatabaseStorageInterface $gra public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) { return new static( $entity_type, + $entity_info, $container->get('node.grant_storage') ); } diff --git a/core/modules/node/lib/Drupal/node/NodeTypeAccessController.php b/core/modules/node/lib/Drupal/node/NodeTypeAccessController.php index b7133bd..23ec80f 100644 --- a/core/modules/node/lib/Drupal/node/NodeTypeAccessController.php +++ b/core/modules/node/lib/Drupal/node/NodeTypeAccessController.php @@ -25,14 +25,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A if ($operation == 'delete' && $entity->isLocked()) { return FALSE; } - return user_access('administer content types', $account); - } - - /** - * {@inheritdoc} - */ - protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { - return user_access('administer content types', $account); + return parent::checkAccess($entity, $operation, $langcode, $account); } } diff --git a/core/modules/picture/lib/Drupal/picture/Entity/PictureMapping.php b/core/modules/picture/lib/Drupal/picture/Entity/PictureMapping.php index b42fbee..c5a6e98 100644 --- a/core/modules/picture/lib/Drupal/picture/Entity/PictureMapping.php +++ b/core/modules/picture/lib/Drupal/picture/Entity/PictureMapping.php @@ -21,7 +21,6 @@ * module = "picture", * controllers = { * "storage" = "Drupal\Core\Config\Entity\ConfigStorageController", - * "access" = "Drupal\picture\PictureMappingAccessController", * "list" = "Drupal\picture\PictureMappingListController", * "form" = { * "edit" = "Drupal\picture\PictureMappingFormController", @@ -31,6 +30,7 @@ * } * }, * list_path = "admin/config/media/picturemapping", + * admin_permission = "administer pictures", * config_prefix = "picture.mappings", * entity_keys = { * "id" = "id", diff --git a/core/modules/picture/lib/Drupal/picture/PictureMappingAccessController.php b/core/modules/picture/lib/Drupal/picture/PictureMappingAccessController.php deleted file mode 100644 index 281bcee..0000000 --- a/core/modules/picture/lib/Drupal/picture/PictureMappingAccessController.php +++ /dev/null @@ -1,38 +0,0 @@ -hasPermission('administer pictures'); - } - } - - /** - * {@inheritdoc} - */ - protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { - return $account->hasPermission('administer pictures'); - } - -} diff --git a/core/modules/system/lib/Drupal/system/Entity/Action.php b/core/modules/system/lib/Drupal/system/Entity/Action.php index ac68e3e..5192858 100644 --- a/core/modules/system/lib/Drupal/system/Entity/Action.php +++ b/core/modules/system/lib/Drupal/system/Entity/Action.php @@ -24,8 +24,9 @@ * module = "system", * controllers = { * "storage" = "Drupal\Core\Config\Entity\ConfigStorageController", - * "access" = "Drupal\action\ActionAccessController" + * "access" = "Drupal\Core\Entity\EntityAccessController" * }, + * admin_permission = "administer actions", * config_prefix = "system.action", * entity_keys = { * "id" = "id", diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php index ed179dd..721d5ea 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php @@ -22,7 +22,6 @@ * module = "taxonomy", * controllers = { * "storage" = "Drupal\taxonomy\VocabularyStorageController", - * "access" = "Drupal\taxonomy\VocabularyAccessController", * "list" = "Drupal\taxonomy\VocabularyListController", * "form" = { * "default" = "Drupal\taxonomy\VocabularyFormController", @@ -30,6 +29,7 @@ * "delete" = "Drupal\taxonomy\Form\VocabularyDeleteForm" * } * }, + * admin_permission = "administer taxonomy", * config_prefix = "taxonomy.vocabulary", * bundle_of = "taxonomy_term", * entity_keys = { diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyAccessController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyAccessController.php deleted file mode 100644 index 56b92ed..0000000 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyAccessController.php +++ /dev/null @@ -1,35 +0,0 @@ -hasPermission('administer taxonomy'); - } - - /** - * {@inheritdoc} - */ - protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { - return $account->hasPermission('administer taxonomy'); - } - -} diff --git a/core/modules/user/lib/Drupal/user/Entity/Role.php b/core/modules/user/lib/Drupal/user/Entity/Role.php index 0f8e90e..5bb6631 100644 --- a/core/modules/user/lib/Drupal/user/Entity/Role.php +++ b/core/modules/user/lib/Drupal/user/Entity/Role.php @@ -27,6 +27,7 @@ * "delete" = "Drupal\user\Form\UserRoleDelete" * } * }, + * admin_permission = "administer permissions", * config_prefix = "user.role", * entity_keys = { * "id" = "id", diff --git a/core/modules/user/lib/Drupal/user/Entity/User.php b/core/modules/user/lib/Drupal/user/Entity/User.php index d8dc8e4..074cd9b 100644 --- a/core/modules/user/lib/Drupal/user/Entity/User.php +++ b/core/modules/user/lib/Drupal/user/Entity/User.php @@ -30,6 +30,7 @@ * }, * "translation" = "Drupal\user\ProfileTranslationController" * }, + * admin_permission = "administer user", * base_table = "users", * uri_callback = "user_uri", * route_base_path = "admin/config/people/accounts", diff --git a/core/modules/user/lib/Drupal/user/RoleAccessController.php b/core/modules/user/lib/Drupal/user/RoleAccessController.php index e98c540..0ab9ad8 100644 --- a/core/modules/user/lib/Drupal/user/RoleAccessController.php +++ b/core/modules/user/lib/Drupal/user/RoleAccessController.php @@ -27,15 +27,8 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A } default: - return user_access('administer permissions', $account); + return parent::checkAccess($entity, $operation, $langcode, $account); } } - /** - * {@inheritdoc} - */ - protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { - return user_access('administer permissions', $account); - } - } diff --git a/core/modules/user/lib/Drupal/user/UserAccessController.php b/core/modules/user/lib/Drupal/user/UserAccessController.php index e6f6ed6..618dfe3 100644 --- a/core/modules/user/lib/Drupal/user/UserAccessController.php +++ b/core/modules/user/lib/Drupal/user/UserAccessController.php @@ -41,13 +41,6 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A } /** - * {@inheritdoc} - */ - protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { - return user_access('administer users', $account); - } - - /** * Check view access. * * See EntityAccessControllerInterface::view() for parameters. diff --git a/core/modules/views/lib/Drupal/views/Entity/View.php b/core/modules/views/lib/Drupal/views/Entity/View.php index a24e53e..ceb423e 100644 --- a/core/modules/views/lib/Drupal/views/Entity/View.php +++ b/core/modules/views/lib/Drupal/views/Entity/View.php @@ -25,6 +25,7 @@ * "storage" = "Drupal\views\ViewStorageController", * "access" = "Drupal\views\ViewAccessController" * }, + * admin_permission = "administer views", * config_prefix = "views.view", * entity_keys = { * "id" = "id", diff --git a/core/modules/views/lib/Drupal/views/ViewAccessController.php b/core/modules/views/lib/Drupal/views/ViewAccessController.php index 80ad8a9..e761af2 100644 --- a/core/modules/views/lib/Drupal/views/ViewAccessController.php +++ b/core/modules/views/lib/Drupal/views/ViewAccessController.php @@ -20,15 +20,8 @@ class ViewAccessController extends EntityAccessController { /** * {@inheritdoc} */ - public function access(EntityInterface $entity, $operation, $langcode = Language::LANGCODE_DEFAULT, AccountInterface $account = NULL) { - return $operation == 'view' || user_access('administer views', $account); - } - - /** - * {@inheritdoc} - */ - protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { - return user_access('administer views', $account); + public function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { + return $operation == 'view' || parent::checkAccess($entity, $operation, $langcode, $account); } }