diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 7712bf1..e583993 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -274,6 +274,11 @@ public function getIterator() { * Implements \Drupal\Core\TypedData\AccessibleInterface::access(). */ public function access($operation = 'view', AccountInterface $account = NULL) { + if ($operation == 'create') { + return \Drupal::entityManager() + ->getAccessController($this->entityType) + ->createAccess($this->bundle(), $operation, Language::LANGCODE_DEFAULT, $account); + } return \Drupal::entityManager() ->getAccessController($this->entityType) ->access($this, $operation, Language::LANGCODE_DEFAULT, $account); diff --git a/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php b/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php index 7db038a..c0296dd 100644 --- a/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php @@ -18,11 +18,14 @@ /** * Checks access to an operation on a given entity or entity translation. * + * Use \Drupal\Core\Entity\EntityAccessControllerInterface::createAccess() + * to check access to create an entity. + * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity for which to check access. * @param string $operation * The operation access should be checked for. - * Usually one of "view", "create", "update" or "delete". + * Usually one of "view", "update" or "delete". * @param string $langcode * (optional) The language code for which to check access. Defaults to * Language::LANGCODE_DEFAULT. @@ -36,7 +39,7 @@ public function access(EntityInterface $entity, $operation, $langcode = Language::LANGCODE_DEFAULT, AccountInterface $account = NULL); /** - * Checks access to create an entity. + * Checks access to create an entity. * * @param string $entity_bundle * (optional) The bundle of the entity. Required if the entity supports diff --git a/core/lib/Drupal/Core/Entity/EntityNG.php b/core/lib/Drupal/Core/Entity/EntityNG.php index 3d0c5c6..403f004 100644 --- a/core/lib/Drupal/Core/Entity/EntityNG.php +++ b/core/lib/Drupal/Core/Entity/EntityNG.php @@ -422,6 +422,11 @@ public function isEmpty() { * {@inheritdoc} */ public function access($operation = 'view', AccountInterface $account = NULL) { + if ($operation == 'create') { + return \Drupal::entityManager() + ->getAccessController($this->entityType) + ->createAccess($this->bundle(), $operation, $this->activeLangcode, $account); + } return \Drupal::entityManager() ->getAccessController($this->entityType) ->access($this, $operation, $this->activeLangcode, $account); diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockAccessController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockAccessController.php index 8ac282a..9990a2e 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockAccessController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockAccessController.php @@ -23,9 +23,16 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A if ($operation === 'view') { return TRUE; } - elseif (in_array($operation, array('create', 'update', 'delete'))) { + elseif (in_array($operation, array('update', 'delete'))) { return user_access('administer blocks', $account); } } + /** + * {@inheritdoc} + */ + protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { + return user_access('administer blocks', $account); + } + } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeAccessController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeAccessController.php index 3aa95ce..95b74ac 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeAccessController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeAccessController.php @@ -23,9 +23,16 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A if ($operation === 'view') { return TRUE; } - elseif (in_array($operation, array('create', 'update', 'delete'))) { + elseif (in_array($operation, array('update', 'delete'))) { return user_access('administer blocks', $account); } } + /** + * {@inheritdoc} + */ + protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { + return user_access('administer blocks', $account); + } + } diff --git a/core/modules/comment/lib/Drupal/comment/CommentAccessController.php b/core/modules/comment/lib/Drupal/comment/CommentAccessController.php index 4749428..ee67c3e 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentAccessController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentAccessController.php @@ -27,10 +27,6 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A return user_access('access comments', $account); break; - case 'create': - return user_access('post comments', $account); - break; - case 'update': return ($account->uid && $account->uid == $entity->uid->value && $entity->status->value == COMMENT_PUBLISHED && user_access('edit own comments', $account)) || user_access('administer comments', $account); break; @@ -45,4 +41,11 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A } } + /** + * {@inheritdoc} + */ + protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { + return user_access('post comments', $account); + } + } 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 cde6f41..f084453 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 @@ -24,4 +24,11 @@ public function access(EntityInterface $entity, $operation, $langcode = Language return TRUE; } + /** + * {@inheritdoc} + */ + protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { + return TRUE; + } + } diff --git a/core/modules/filter/lib/Drupal/filter/FilterFormatAccessController.php b/core/modules/filter/lib/Drupal/filter/FilterFormatAccessController.php index 133c309..1242b94 100644 --- a/core/modules/filter/lib/Drupal/filter/FilterFormatAccessController.php +++ b/core/modules/filter/lib/Drupal/filter/FilterFormatAccessController.php @@ -36,4 +36,11 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A return !empty($permission) && user_access($permission, $account); } + /** + * {@inheritdoc} + */ + protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { + return user_access('administer filters', $account); + } + } diff --git a/core/modules/menu/lib/Drupal/menu/MenuAccessController.php b/core/modules/menu/lib/Drupal/menu/MenuAccessController.php index 4cb2962..b7128c0 100644 --- a/core/modules/menu/lib/Drupal/menu/MenuAccessController.php +++ b/core/modules/menu/lib/Drupal/menu/MenuAccessController.php @@ -31,9 +31,16 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A } } - if (in_array($operation, array('create', 'update', 'delete'))) { + if (in_array($operation, array('update', 'delete'))) { return user_access('administer menu', $account); } } + /** + * {@inheritdoc} + */ + protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { + return user_access('administer menu', $account); + } + } diff --git a/core/modules/node/lib/Drupal/node/NodeAccessController.php b/core/modules/node/lib/Drupal/node/NodeAccessController.php index 2b402ba..d21c402 100644 --- a/core/modules/node/lib/Drupal/node/NodeAccessController.php +++ b/core/modules/node/lib/Drupal/node/NodeAccessController.php @@ -95,9 +95,9 @@ protected function checkCreateAccess(AccountInterface $account, array $context, * Determines access to nodes based on node grants. * * @param \Drupal\Core\Entity\EntityInterface $node - * The entity for which to check 'create' access. + * The entity for which to check access. * @param string $operation - * The entity operation. Usually one of 'view', 'edit', 'create' or + * The entity operation. Usually one of 'view', 'edit' or * 'delete'. * @param string $langcode * The language code for which to check access. diff --git a/core/modules/node/lib/Drupal/node/NodeTypeAccessController.php b/core/modules/node/lib/Drupal/node/NodeTypeAccessController.php index 40327e3..55238a6 100644 --- a/core/modules/node/lib/Drupal/node/NodeTypeAccessController.php +++ b/core/modules/node/lib/Drupal/node/NodeTypeAccessController.php @@ -28,4 +28,11 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A 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); + } + } diff --git a/core/modules/picture/lib/Drupal/picture/PictureMappingAccessController.php b/core/modules/picture/lib/Drupal/picture/PictureMappingAccessController.php index 5ee0ade..2696100 100644 --- a/core/modules/picture/lib/Drupal/picture/PictureMappingAccessController.php +++ b/core/modules/picture/lib/Drupal/picture/PictureMappingAccessController.php @@ -23,9 +23,16 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A if ($operation === 'view') { return TRUE; } - elseif (in_array($operation, array('create', 'update', 'delete'))) { + elseif (in_array($operation, array('update', 'delete'))) { return user_access('administer pictures', $account); } } + /** + * {@inheritdoc} + */ + protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { + return user_access('administer pictures', $account); + } + } diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestAccessController.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestAccessController.php index c2b5594..034caa3 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestAccessController.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestAccessController.php @@ -27,9 +27,16 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A } return user_access('view test entity', $account); } - elseif (in_array($operation, array('create', 'update', 'delete'))) { + elseif (in_array($operation, array('update', 'delete'))) { return user_access('administer entity_test content', $account); } } + /** + * {@inheritdoc} + */ + protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { + return user_access('administer entity_test content', $account); + } + } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermAccessController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermAccessController.php index d562e84..d945ef5 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermAccessController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermAccessController.php @@ -27,10 +27,6 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A return user_access('access content', $account); break; - case 'create': - return user_access('administer taxonomy', $account); - break; - case 'update': return user_access("edit terms in {$entity->bundle()}", $account) || user_access('administer taxonomy', $account); break; @@ -41,4 +37,11 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A } } + /** + * {@inheritdoc} + */ + protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { + return user_access('administer taxonomy', $account); + } + } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyAccessController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyAccessController.php index 0750593..ac5ebe9 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyAccessController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyAccessController.php @@ -25,4 +25,11 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A return user_access('administer taxonomy', $account); } + /** + * {@inheritdoc} + */ + protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { + return user_access('administer taxonomy', $account); + } + } diff --git a/core/modules/user/lib/Drupal/user/RoleAccessController.php b/core/modules/user/lib/Drupal/user/RoleAccessController.php index 13afa61..e98c540 100644 --- a/core/modules/user/lib/Drupal/user/RoleAccessController.php +++ b/core/modules/user/lib/Drupal/user/RoleAccessController.php @@ -31,4 +31,11 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A } } + /** + * {@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 fd46efa..e6f6ed6 100644 --- a/core/modules/user/lib/Drupal/user/UserAccessController.php +++ b/core/modules/user/lib/Drupal/user/UserAccessController.php @@ -25,10 +25,6 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A return $this->viewAccess($entity, $langcode, $account); break; - case 'create': - return user_access('administer users', $account); - break; - case 'update': // Users can always edit their own account. Users with the 'administer // users' permission can edit any account except the anonymous account. @@ -45,6 +41,13 @@ 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/ViewAccessController.php b/core/modules/views/lib/Drupal/views/ViewAccessController.php index a4aaae6..80ad8a9 100644 --- a/core/modules/views/lib/Drupal/views/ViewAccessController.php +++ b/core/modules/views/lib/Drupal/views/ViewAccessController.php @@ -24,4 +24,11 @@ public function access(EntityInterface $entity, $operation, $langcode = Language 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); + } + }