core/lib/Drupal/Core/Access/AccessManager.php | 4 +- core/lib/Drupal/Core/Access/AccessResult.php | 46 +++++++++++++++++++++- core/lib/Drupal/Core/Access/DefaultAccessCheck.php | 4 +- .../Core/Entity/EntityAccessControlHandler.php | 10 ++--- core/lib/Drupal/Core/Field/FieldItemList.php | 2 +- core/lib/Drupal/Core/Menu/MenuLinkBase.php | 2 +- core/lib/Drupal/Core/Menu/MenuLinkDefault.php | 2 +- core/lib/Drupal/Core/Theme/ThemeAccessCheck.php | 2 +- .../aggregator/src/FeedAccessControlHandler.php | 6 +-- core/modules/block/block.api.php | 2 +- .../Plugin/DisplayVariant/FullPageVariantTest.php | 2 +- .../src/BlockContentAccessControlHandler.php | 2 +- .../src/Access/BookNodeIsRemovableAccessCheck.php | 2 +- .../comment/src/CommentAccessControlHandler.php | 8 ++-- .../src/ConfigTestAccessControlHandler.php | 4 +- .../src/Access/ConfigTranslationOverviewAccess.php | 2 +- .../contact/src/Access/ContactPageAccess.php | 4 +- .../src/ContactFormAccessControlHandler.php | 4 +- .../content_translation/content_translation.module | 2 +- .../Access/ContentTranslationManageAccessCheck.php | 4 +- .../src/ContentTranslationHandler.php | 2 +- .../ContentTranslationManageAccessCheckTest.php | 2 +- .../FieldInstanceConfigAccessControlHandler.php | 6 +-- .../tests/modules/field_test/field_test.field.inc | 6 +-- .../src/FilterFormatAccessControlHandler.php | 8 ++-- .../filter/src/Tests/FilterFormatAccessTest.php | 6 +-- .../language/src/LanguageAccessControlHandler.php | 2 +- .../src/MenuLinkContentAccessControlHandler.php | 2 +- .../modules/menu_ui/src/Form/MenuLinkResetForm.php | 2 +- core/modules/node/node.api.php | 10 ++--- core/modules/node/node.module | 10 ++--- .../node/src/Access/NodeRevisionAccessCheck.php | 2 +- core/modules/node/src/NodeAccessControlHandler.php | 18 ++++----- core/modules/node/src/NodeGrantDatabaseStorage.php | 4 +- .../node/src/NodeTypeAccessControlHandler.php | 2 +- core/modules/node/src/Plugin/Search/NodeSearch.php | 2 +- .../node_access_test/node_access_test.module | 2 +- .../Plugin/Field/FieldType/PathFieldItemList.php | 4 +- .../src/Access/EditEntityFieldAccessCheck.php | 2 +- .../src/Access/EditEntityFieldAccessCheckTest.php | 8 ++-- core/modules/rest/src/Access/CSRFAccessCheck.php | 4 +- .../search/src/SearchPageAccessControlHandler.php | 6 +-- core/modules/shortcut/shortcut.module | 10 ++--- .../src/ShortcutSetAccessControlHandler.php | 8 ++-- core/modules/system/entity.api.php | 2 +- core/modules/system/src/Access/CronAccessCheck.php | 6 +-- .../system/src/DateFormatAccessControlHandler.php | 4 +- .../system/src/MenuAccessControlHandler.php | 4 +- .../system/src/Tests/Entity/FieldAccessTest.php | 4 +- .../tests/modules/entity_test/entity_test.module | 6 +-- .../src/EntityTestAccessControlHandler.php | 8 ++-- .../src/Access/DefinedTestAccessCheck.php | 4 +- .../Breadcrumbs/PathBasedBreadcrumbBuilderTest.php | 2 +- .../taxonomy/src/TermAccessControlHandler.php | 8 ++-- .../toolbar/src/Controller/ToolbarController.php | 2 +- .../src/Access/ViewOwnTrackerAccessCheck.php | 2 +- .../update/src/Access/UpdateManagerAccessCheck.php | 2 +- core/modules/user/src/Access/LoginStatusCheck.php | 2 +- .../user/src/Access/PermissionAccessCheck.php | 2 +- .../user/src/Access/RegisterAccessCheck.php | 2 +- core/modules/user/src/Access/RoleAccessCheck.php | 4 +- core/modules/user/src/Plugin/Search/UserSearch.php | 2 +- core/modules/user/src/RoleAccessControlHandler.php | 2 +- core/modules/user/src/UserAccessControlHandler.php | 12 +++--- .../modules/views/src/ViewAccessControlHandler.php | 2 +- core/modules/views/src/ViewsAccessCheck.php | 2 +- .../src/Plugin/argument_validator/EntityTest.php | 4 +- .../Drupal/Tests/Core/Access/AccessManagerTest.php | 30 +++++++------- .../Tests/Core/Access/CsrfAccessCheckTest.php | 6 +-- .../Tests/Core/Access/DefaultAccessCheckTest.php | 4 +- .../Core/Entity/ContentEntityBaseUnitTest.php | 8 ++-- .../Tests/Core/Entity/EntityAccessCheckTest.php | 4 +- .../Core/Entity/EntityCreateAccessCheckTest.php | 2 +- .../Tests/Core/Entity/EntityListBuilderTest.php | 2 +- .../Drupal/Tests/Core/Entity/EntityUnitTest.php | 8 ++-- .../Tests/Core/Menu/ContextualLinkManagerTest.php | 4 +- .../Menu/DefaultMenuLinkTreeManipulatorsTest.php | 4 +- .../Tests/Core/Route/RoleAccessCheckTest.php | 2 +- .../Tests/Core/Routing/AccessAwareRouterTest.php | 4 +- 79 files changed, 226 insertions(+), 182 deletions(-) diff --git a/core/lib/Drupal/Core/Access/AccessManager.php b/core/lib/Drupal/Core/Access/AccessManager.php index c2261b5..c73727a 100644 --- a/core/lib/Drupal/Core/Access/AccessManager.php +++ b/core/lib/Drupal/Core/Access/AccessManager.php @@ -201,12 +201,12 @@ public function checkNamedRoute($route_name, array $parameters = array(), Accoun } catch (RouteNotFoundException $e) { // Cacheable until extensions change. - return AccessResult::create()->forbid()->addCacheTags(array('extension' => TRUE)); + return AccessResult::forbidden()->addCacheTags(array('extension' => TRUE)); } catch (ParamNotConvertedException $e) { // Uncacheable because conversion of the parameter may not have been // possible due to highly dynamic circumstances. - return AccessResult::create()->forbid()->setCacheable(FALSE); + return AccessResult::forbidden()->setCacheable(FALSE); } } diff --git a/core/lib/Drupal/Core/Access/AccessResult.php b/core/lib/Drupal/Core/Access/AccessResult.php index e1949c4..a9870eb 100644 --- a/core/lib/Drupal/Core/Access/AccessResult.php +++ b/core/lib/Drupal/Core/Access/AccessResult.php @@ -73,7 +73,7 @@ public function __construct() { } /** - * Instantiates a new AccessResult object + * Instantiates a new AccessResult object. * * This factory method exists to improve DX; it allows developers to fluently * create access results. @@ -85,6 +85,50 @@ public static function create() { } /** + * Convenience method, creates an AccessResult object and calls allow(). + * + * @return \Drupal\Core\Access\AccessResult + */ + public static function allowed() { + return AccessResult::create()->allow(); + } + + /** + * Convenience method, creates an AccessResult object and calls forbid(). + * + * @return \Drupal\Core\Access\AccessResult + */ + public static function forbidden() { + return AccessResult::create()->forbid(); + } + + /** + * Convenience method, creates an AccessResult object and calls allowIf(). + * + * @param bool $condition + * The condition to evaluate. If TRUE, AccessInterface::ALLOW will be set, + * otherwise AccessInterface::DENY. + * + * @return \Drupal\Core\Access\AccessResult + */ + public static function allowedIf($condition) { + return AccessResult::create()->allowIf($condition); + } + + /** + * Convenience method, creates an AccessResult object and calls forbiddenIf(). + * + * @param bool $condition + * The condition to evaluate. If TRUE, AccessInterface::KILL will be set, + * otherwise AccessInterface::DENY. + * + * @return \Drupal\Core\Access\AccessResult + */ + public static function forbiddenIf($condition) { + AccessResult::create()->forbidIf($condition); + } + + /** * {@inheritdoc} */ public function isAllowed() { diff --git a/core/lib/Drupal/Core/Access/DefaultAccessCheck.php b/core/lib/Drupal/Core/Access/DefaultAccessCheck.php index 859eb8f..6e27a51 100644 --- a/core/lib/Drupal/Core/Access/DefaultAccessCheck.php +++ b/core/lib/Drupal/Core/Access/DefaultAccessCheck.php @@ -26,10 +26,10 @@ class DefaultAccessCheck implements RoutingAccessInterface { */ public function access(Route $route) { if ($route->getRequirement('_access') === 'TRUE') { - return AccessResult::create()->allow(); + return AccessResult::allowed(); } elseif ($route->getRequirement('_access') === 'FALSE') { - return AccessResult::create()->forbid(); + return AccessResult::forbidden(); } else { return AccessResult::create(); diff --git a/core/lib/Drupal/Core/Entity/EntityAccessControlHandler.php b/core/lib/Drupal/Core/Entity/EntityAccessControlHandler.php index 985e882..d7c0742 100644 --- a/core/lib/Drupal/Core/Entity/EntityAccessControlHandler.php +++ b/core/lib/Drupal/Core/Entity/EntityAccessControlHandler.php @@ -133,10 +133,10 @@ protected function processAccessHookResults(array $access) { */ protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { if ($operation == 'delete' && $entity->isNew()) { - return AccessResult::create()->forbid()->cacheUntilEntityChanges($entity); + return AccessResult::forbidden()->cacheUntilEntityChanges($entity); } if ($admin_permission = $this->entityType->getAdminPermission()) { - return AccessResult::create()->allowIf($account->hasPermission($this->entityType->getAdminPermission()))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission($this->entityType->getAdminPermission()))->cachePerRole(); } else { // No opinion. @@ -257,7 +257,7 @@ public function createAccess($entity_bundle = NULL, AccountInterface $account = */ protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { if ($admin_permission = $this->entityType->getAdminPermission()) { - return AccessResult::create()->allowIf($account->hasPermission($admin_permission))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission($admin_permission))->cachePerRole(); } else { // No opinion. @@ -288,7 +288,7 @@ public function fieldAccess($operation, FieldDefinitionInterface $field_definiti $account = $this->prepareUser($account); // Get the default access restriction that lives within this field. - $default = $items ? $items->defaultAccess($operation, $account) : AccessResult::create()->allow(); + $default = $items ? $items->defaultAccess($operation, $account) : AccessResult::allowed(); // Get the default access restriction as specified by the access control // handler. @@ -336,7 +336,7 @@ public function fieldAccess($operation, FieldDefinitionInterface $field_definiti * TRUE if access is allowed, FALSE otherwise. */ protected function checkFieldAccess($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) { - return AccessResult::create()->allow(); + return AccessResult::allowed(); } } diff --git a/core/lib/Drupal/Core/Field/FieldItemList.php b/core/lib/Drupal/Core/Field/FieldItemList.php index c58ffaa..4058c9d 100644 --- a/core/lib/Drupal/Core/Field/FieldItemList.php +++ b/core/lib/Drupal/Core/Field/FieldItemList.php @@ -198,7 +198,7 @@ public function access($operation = 'view', AccountInterface $account = NULL) { */ public function defaultAccess($operation = 'view', AccountInterface $account = NULL) { // Grant access per default. - return AccessResult::create()->allow(); + return AccessResult::allowed(); } /** diff --git a/core/lib/Drupal/Core/Menu/MenuLinkBase.php b/core/lib/Drupal/Core/Menu/MenuLinkBase.php index e918858..4efca53 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkBase.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkBase.php @@ -77,7 +77,7 @@ public function isExpanded() { * {@inheritdoc} */ public function isResettable() { - return AccessResult::create()->forbid(); + return AccessResult::forbidden(); } /** diff --git a/core/lib/Drupal/Core/Menu/MenuLinkDefault.php b/core/lib/Drupal/Core/Menu/MenuLinkDefault.php index ce0c21b..b822aba 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkDefault.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkDefault.php @@ -95,7 +95,7 @@ public function getDescription() { */ public function isResettable() { // The link can be reset if it has an override. - return AccessResult::create()->allowIf($this->staticOverride->loadOverride($this->getPluginId()))->setCacheable(FALSE); + return AccessResult::allowedIf($this->staticOverride->loadOverride($this->getPluginId()))->setCacheable(FALSE); } /** diff --git a/core/lib/Drupal/Core/Theme/ThemeAccessCheck.php b/core/lib/Drupal/Core/Theme/ThemeAccessCheck.php index 33365cc..6c2a4c1 100644 --- a/core/lib/Drupal/Core/Theme/ThemeAccessCheck.php +++ b/core/lib/Drupal/Core/Theme/ThemeAccessCheck.php @@ -26,7 +26,7 @@ class ThemeAccessCheck implements AccessInterface { */ public function access($theme) { // Cacheable until the theme is modified. - return AccessResult::create()->allowIf($this->checkAccess($theme))->addCacheTags(array('theme' => $theme)); + return AccessResult::allowedIf($this->checkAccess($theme))->addCacheTags(array('theme' => $theme)); } /** diff --git a/core/modules/aggregator/src/FeedAccessControlHandler.php b/core/modules/aggregator/src/FeedAccessControlHandler.php index a256ab1..f1e62ff 100644 --- a/core/modules/aggregator/src/FeedAccessControlHandler.php +++ b/core/modules/aggregator/src/FeedAccessControlHandler.php @@ -25,11 +25,11 @@ class FeedAccessControlHandler extends EntityAccessControlHandler { protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { switch ($operation) { case 'view': - return AccessResult::create()->allowIf($account->hasPermission('access news feeds'))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission('access news feeds'))->cachePerRole(); break; default: - return AccessResult::create()->allowIf($account->hasPermission('administer news feeds'))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission('administer news feeds'))->cachePerRole(); break; } } @@ -38,7 +38,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A * {@inheritdoc} */ protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { - return AccessResult::create()->allowIf($account->hasPermission('administer news feeds'))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission('administer news feeds'))->cachePerRole(); } } diff --git a/core/modules/block/block.api.php b/core/modules/block/block.api.php index 56f87e6..8ecfcd6 100644 --- a/core/modules/block/block.api.php +++ b/core/modules/block/block.api.php @@ -162,7 +162,7 @@ function hook_block_access(\Drupal\block\Entity\Block $block, $operation, \Drupa // Example code that would prevent displaying the 'Powered by Drupal' block in // a region different than the footer. if ($operation == 'view' && $block->get('plugin') == 'system_powered_by_block' && $block->get('region') != 'footer') { - return AccessResult::create()->forbid(); + return AccessResult::forbidden(); } // No opinion. diff --git a/core/modules/block/tests/src/Plugin/DisplayVariant/FullPageVariantTest.php b/core/modules/block/tests/src/Plugin/DisplayVariant/FullPageVariantTest.php index 236ddd5..56466f7 100644 --- a/core/modules/block/tests/src/Plugin/DisplayVariant/FullPageVariantTest.php +++ b/core/modules/block/tests/src/Plugin/DisplayVariant/FullPageVariantTest.php @@ -107,7 +107,7 @@ public function testBuild() { $block = $this->getMock('Drupal\block\BlockInterface'); $block->expects($this->once()) ->method('access') - ->will($this->returnValue(AccessResult::create()->allowIf($block_config[0]))); + ->will($this->returnValue(AccessResult::allowedIf($block_config[0]))); $block->expects($this->any()) ->method('get') ->will($this->returnValueMap(array( diff --git a/core/modules/block_content/src/BlockContentAccessControlHandler.php b/core/modules/block_content/src/BlockContentAccessControlHandler.php index a077238..e886432 100644 --- a/core/modules/block_content/src/BlockContentAccessControlHandler.php +++ b/core/modules/block_content/src/BlockContentAccessControlHandler.php @@ -24,7 +24,7 @@ class BlockContentAccessControlHandler extends EntityAccessControlHandler { */ protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { if ($operation === 'view') { - return AccessResult::create()->allow(); + return AccessResult::allowed(); } return parent::checkAccess($entity, $operation, $langcode, $account); } diff --git a/core/modules/book/src/Access/BookNodeIsRemovableAccessCheck.php b/core/modules/book/src/Access/BookNodeIsRemovableAccessCheck.php index 3ab72bb..ee17c70 100644 --- a/core/modules/book/src/Access/BookNodeIsRemovableAccessCheck.php +++ b/core/modules/book/src/Access/BookNodeIsRemovableAccessCheck.php @@ -44,7 +44,7 @@ public function __construct(BookManagerInterface $book_manager) { * The access result. */ public function access(NodeInterface $node) { - return AccessResult::create()->allowIf($this->bookManager->checkNodeIsRemovable($node))->cacheUntilEntityChanges($node); + return AccessResult::allowedIf($this->bookManager->checkNodeIsRemovable($node))->cacheUntilEntityChanges($node); } } diff --git a/core/modules/comment/src/CommentAccessControlHandler.php b/core/modules/comment/src/CommentAccessControlHandler.php index 532ae62..5f22f90 100644 --- a/core/modules/comment/src/CommentAccessControlHandler.php +++ b/core/modules/comment/src/CommentAccessControlHandler.php @@ -26,17 +26,17 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A /** @var \Drupal\Core\Entity\EntityInterface|\Drupal\user\EntityOwnerInterface $entity */ if ($account->hasPermission('administer comments')) { - $access = AccessResult::create()->allow()->cachePerRole(); + $access = AccessResult::allowed()->cachePerRole(); return ($operation != 'view') ? $access : $access->andIf($entity->getCommentedEntity()->access($operation, $account)); } switch ($operation) { case 'view': - return AccessResult::create()->allowIf($account->hasPermission('access comments') && $entity->isPublished())->cachePerRole()->cacheUntilEntityChanges($entity) + return AccessResult::allowedIf($account->hasPermission('access comments') && $entity->isPublished())->cachePerRole()->cacheUntilEntityChanges($entity) ->andIf($entity->getCommentedEntity()->access($operation, $account)); case 'update': - return AccessResult::create()->allowIf($account->id() && $account->id() == $entity->getOwnerId() && $entity->isPublished() && $account->hasPermission('edit own comments'))->cachePerRole()->cachePerUser()->cacheUntilEntityChanges($entity); + return AccessResult::allowedIf($account->id() && $account->id() == $entity->getOwnerId() && $entity->isPublished() && $account->hasPermission('edit own comments'))->cachePerRole()->cachePerUser()->cacheUntilEntityChanges($entity); default: // No opinion. @@ -48,7 +48,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A * {@inheritdoc} */ protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { - return AccessResult::create()->allowIf($account->hasPermission('post comments'))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission('post comments'))->cachePerRole(); } } diff --git a/core/modules/config/tests/config_test/src/ConfigTestAccessControlHandler.php b/core/modules/config/tests/config_test/src/ConfigTestAccessControlHandler.php index 9554b77..4508ce2 100644 --- a/core/modules/config/tests/config_test/src/ConfigTestAccessControlHandler.php +++ b/core/modules/config/tests/config_test/src/ConfigTestAccessControlHandler.php @@ -23,14 +23,14 @@ class ConfigTestAccessControlHandler extends EntityAccessControlHandler { * {@inheritdoc} */ public function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { - return AccessResult::create()->allow(); + return AccessResult::allowed(); } /** * {@inheritdoc} */ protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { - return AccessResult::create()->allow(); + return AccessResult::allowed(); } } diff --git a/core/modules/config_translation/src/Access/ConfigTranslationOverviewAccess.php b/core/modules/config_translation/src/Access/ConfigTranslationOverviewAccess.php index 115b6b9..407f9a1 100644 --- a/core/modules/config_translation/src/Access/ConfigTranslationOverviewAccess.php +++ b/core/modules/config_translation/src/Access/ConfigTranslationOverviewAccess.php @@ -72,7 +72,7 @@ public function access(Route $route, Request $request, AccountInterface $account $mapper->hasTranslatable() && !$this->sourceLanguage->locked; - return AccessResult::create()->allowIf($access)->cachePerRole(); + return AccessResult::allowedIf($access)->cachePerRole(); } } diff --git a/core/modules/contact/src/Access/ContactPageAccess.php b/core/modules/contact/src/Access/ContactPageAccess.php index f0d54bd..da8c07a 100644 --- a/core/modules/contact/src/Access/ContactPageAccess.php +++ b/core/modules/contact/src/Access/ContactPageAccess.php @@ -62,12 +62,12 @@ public function access(UserInterface $user, AccountInterface $account) { // Anonymous users cannot have contact forms. if ($contact_account->isAnonymous()) { - return AccessResult::create()->forbid(); + return AccessResult::forbidden(); } // Users may not contact themselves. if ($account->id() == $contact_account->id()) { - return AccessResult::create()->forbid()->cachePerUser(); + return AccessResult::forbidden()->cachePerUser(); } // User administrators should always have access to personal contact forms. diff --git a/core/modules/contact/src/ContactFormAccessControlHandler.php b/core/modules/contact/src/ContactFormAccessControlHandler.php index 10fe9a9..3af949a 100644 --- a/core/modules/contact/src/ContactFormAccessControlHandler.php +++ b/core/modules/contact/src/ContactFormAccessControlHandler.php @@ -25,12 +25,12 @@ class ContactFormAccessControlHandler extends EntityAccessControlHandler { public function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { if ($operation == 'view') { // Do not allow access personal form via site-wide route. - return AccessResult::create()->allowIf($account->hasPermission('access site-wide contact form') && $entity->id() !== 'personal')->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission('access site-wide contact form') && $entity->id() !== 'personal')->cachePerRole(); } elseif ($operation == 'delete' || $operation == 'update') { // Do not allow the 'personal' form to be deleted, as it's used for // the personal contact form. - return AccessResult::create()->allowIf($account->hasPermission('administer contact forms') && $entity->id() !== 'personal')->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission('administer contact forms') && $entity->id() !== 'personal')->cachePerRole(); } return parent::checkAccess($entity, $operation, $langcode, $account); diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 9ba09a69..4bf9bbe 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -227,7 +227,7 @@ function content_translation_translate_access(EntityInterface $entity) { $account = \Drupal::currentUser(); $condition = $entity instanceof ContentEntityInterface && empty($entity->getUntranslated()->language()->locked) && \Drupal::languageManager()->isMultilingual() && $entity->isTranslatable() && ($account->hasPermission('create content translations') || $account->hasPermission('update content translations') || $account->hasPermission('delete content translations')); - return AccessResult::create()->allowIf($condition)->cachePerRole()->cacheUntilEntityChanges($entity); + return AccessResult::allowedIf($condition)->cachePerRole()->cacheUntilEntityChanges($entity); } /** diff --git a/core/modules/content_translation/src/Access/ContentTranslationManageAccessCheck.php b/core/modules/content_translation/src/Access/ContentTranslationManageAccessCheck.php index ca4f8a6..035153a 100644 --- a/core/modules/content_translation/src/Access/ContentTranslationManageAccessCheck.php +++ b/core/modules/content_translation/src/Access/ContentTranslationManageAccessCheck.php @@ -91,7 +91,7 @@ public function access(Route $route, Request $request, AccountInterface $account && isset($languages[$source_language->getId()]) && isset($languages[$target_language->getId()]) && !isset($translations[$target_language->getId()])); - return AccessResult::create()->allowIf($is_new_translation)->cachePerRole()->cacheUntilEntityChanges($entity) + return AccessResult::allowedIf($is_new_translation)->cachePerRole()->cacheUntilEntityChanges($entity) ->andIf($handler->getTranslationAccess($entity, $operation)); case 'update': @@ -100,7 +100,7 @@ public function access(Route $route, Request $request, AccountInterface $account $has_translation = isset($languages[$language->getId()]) && $language->getId() != $entity->getUntranslated()->language()->getId() && isset($translations[$language->getId()]); - return AccessResult::create()->allowIf($has_translation)->cachePerRole()->cacheUntilEntityChanges($entity) + return AccessResult::allowedIf($has_translation)->cachePerRole()->cacheUntilEntityChanges($entity) ->andIf($handler->getTranslationAccess($entity, $operation)); } } diff --git a/core/modules/content_translation/src/ContentTranslationHandler.php b/core/modules/content_translation/src/ContentTranslationHandler.php index ac4a6c3..f1b8c61 100644 --- a/core/modules/content_translation/src/ContentTranslationHandler.php +++ b/core/modules/content_translation/src/ContentTranslationHandler.php @@ -72,7 +72,7 @@ public function getTranslationAccess(EntityInterface $entity, $op) { if (!$current_user->hasPermission('translate any entity') && $permission_granularity = $entity_type->getPermissionGranularity()) { $translate_permission = $current_user->hasPermission($permission_granularity == 'bundle' ? "translate {$entity->bundle()} {$entity->getEntityTypeId()}" : "translate {$entity->getEntityTypeId()}"); } - return AccessResult::create()->allowIf($translate_permission && $current_user->hasPermission("$op content translations"))->cachePerRole(); + return AccessResult::allowedIf($translate_permission && $current_user->hasPermission("$op content translations"))->cachePerRole(); } /** diff --git a/core/modules/content_translation/tests/src/Access/ContentTranslationManageAccessCheckTest.php b/core/modules/content_translation/tests/src/Access/ContentTranslationManageAccessCheckTest.php index 4287021..68d58c9 100644 --- a/core/modules/content_translation/tests/src/Access/ContentTranslationManageAccessCheckTest.php +++ b/core/modules/content_translation/tests/src/Access/ContentTranslationManageAccessCheckTest.php @@ -34,7 +34,7 @@ public function testCreateAccess() { $translation_handler = $this->getMock('\Drupal\content_translation\ContentTranslationHandlerInterface'); $translation_handler->expects($this->once()) ->method('getTranslationAccess') - ->will($this->returnValue(AccessResult::create()->allow())); + ->will($this->returnValue(AccessResult::allowed())); $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface'); $entity_manager->expects($this->once()) diff --git a/core/modules/field/src/FieldInstanceConfigAccessControlHandler.php b/core/modules/field/src/FieldInstanceConfigAccessControlHandler.php index 6d87f12..a242ec4 100644 --- a/core/modules/field/src/FieldInstanceConfigAccessControlHandler.php +++ b/core/modules/field/src/FieldInstanceConfigAccessControlHandler.php @@ -26,13 +26,13 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A if ($operation == 'delete') { $field_storage_entity = $entity->getFieldStorageDefinition(); if ($field_storage_entity->isLocked()) { - return AccessResult::create()->forbid()->cacheUntilEntityChanges($field_storage_entity); + return AccessResult::forbidden()->cacheUntilEntityChanges($field_storage_entity); } else { - return AccessResult::create()->allowIf($account->hasPermission('administer ' . $entity->entity_type . ' fields'))->cachePerRole()->cacheUntilEntityChanges($field_storage_entity); + return AccessResult::allowedIf($account->hasPermission('administer ' . $entity->entity_type . ' fields'))->cachePerRole()->cacheUntilEntityChanges($field_storage_entity); } } - return AccessResult::create()->allowIf($account->hasPermission('administer ' . $entity->entity_type . ' fields'))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission('administer ' . $entity->entity_type . ' fields'))->cachePerRole(); } } diff --git a/core/modules/field/tests/modules/field_test/field_test.field.inc b/core/modules/field/tests/modules/field_test/field_test.field.inc index 96fa5ce..3c6b9bd 100644 --- a/core/modules/field/tests/modules/field_test/field_test.field.inc +++ b/core/modules/field/tests/modules/field_test/field_test.field.inc @@ -41,14 +41,14 @@ function field_test_default_value(ContentEntityInterface $entity, FieldDefinitio */ function field_test_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) { if ($field_definition->getName() == "field_no_{$operation}_access") { - return AccessResult::create()->forbid()->cacheUntilEntityChanges($items->getEntity()); + return AccessResult::forbidden()->cacheUntilEntityChanges($items->getEntity()); } // Only grant view access to test_view_field fields when the user has // 'view test_view_field content' permission. if ($field_definition->getName() == 'test_view_field' && $operation == 'view' && !$account->hasPermission('view test_view_field content')) { - return AccessResult::create()->forbid()->cachePerRole()->cacheUntilEntityChanges($items->getEntity()); + return AccessResult::forbidden()->cachePerRole()->cacheUntilEntityChanges($items->getEntity()); } - return AccessResult::create()->allow(); + return AccessResult::allowed(); } diff --git a/core/modules/filter/src/FilterFormatAccessControlHandler.php b/core/modules/filter/src/FilterFormatAccessControlHandler.php index 94a9391..21d5516 100644 --- a/core/modules/filter/src/FilterFormatAccessControlHandler.php +++ b/core/modules/filter/src/FilterFormatAccessControlHandler.php @@ -28,22 +28,22 @@ protected function checkAccess(EntityInterface $filter_format, $operation, $lang // All users are allowed to use the fallback filter. if ($operation == 'use') { if ($filter_format->isFallbackFormat()) { - return AccessResult::create()->allow(); + return AccessResult::allowed(); } else { - return AccessResult::create()->allowIf($account->hasPermission($filter_format->getPermissionName()))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission($filter_format->getPermissionName()))->cachePerRole(); } } // The fallback format may not be disabled. if ($operation == 'disable' && $filter_format->isFallbackFormat()) { - return AccessResult::create()->forbid(); + return AccessResult::forbidden(); } // We do not allow filter formats to be deleted through the UI, because that // would render any content that uses them unusable. if ($operation == 'delete') { - return AccessResult::create()->forbid(); + return AccessResult::forbidden(); } if (in_array($operation, array('disable', 'update'))) { diff --git a/core/modules/filter/src/Tests/FilterFormatAccessTest.php b/core/modules/filter/src/Tests/FilterFormatAccessTest.php index 51ddb1a..0d334a2 100644 --- a/core/modules/filter/src/Tests/FilterFormatAccessTest.php +++ b/core/modules/filter/src/Tests/FilterFormatAccessTest.php @@ -122,9 +122,9 @@ function testFormatPermissions() { // Make sure that a regular user only has access to the text formats for // which they were granted access. $fallback_format = entity_load('filter_format', filter_fallback_format()); - $this->assertEqual(AccessResult::create()->cachePerRole()->allow(), $this->allowed_format->access('use', $this->web_user), 'A regular user has access to use a text format they were granted access to.'); - $this->assertEqual(AccessResult::create()->cachePerRole()->reset(), $this->disallowed_format->access('use', $this->web_user), 'A regular user does not have access to use a text format they were not granted access to.'); - $this->assertEqual(AccessResult::create()->allow(), $fallback_format->access('use', $this->web_user), 'A regular user has access to use the fallback format.'); + $this->assertEqual(AccessResult::allowed()->cachePerRole(), $this->allowed_format->access('use', $this->web_user), 'A regular user has access to use a text format they were granted access to.'); + $this->assertEqual(AccessResult::allowed()->cachePerRole(), $this->disallowed_format->access('use', $this->web_user), 'A regular user does not have access to use a text format they were not granted access to.'); + $this->assertEqual(AccessResult::allowed(), $fallback_format->access('use', $this->web_user), 'A regular user has access to use the fallback format.'); // Perform similar checks as above, but now against the entire list of // available formats for this user. diff --git a/core/modules/language/src/LanguageAccessControlHandler.php b/core/modules/language/src/LanguageAccessControlHandler.php index 19982a1..e0d0ace 100644 --- a/core/modules/language/src/LanguageAccessControlHandler.php +++ b/core/modules/language/src/LanguageAccessControlHandler.php @@ -26,7 +26,7 @@ public function checkAccess(EntityInterface $entity, $operation, $langcode, Acco switch ($operation) { case 'update': case 'delete': - return AccessResult::create()->allowIf(!$entity->locked)->cacheUntilEntityChanges($entity) + return AccessResult::allowedIf(!$entity->locked)->cacheUntilEntityChanges($entity) ->andIf(parent::checkAccess($entity, $operation, $langcode, $account)); default: diff --git a/core/modules/menu_link_content/src/MenuLinkContentAccessControlHandler.php b/core/modules/menu_link_content/src/MenuLinkContentAccessControlHandler.php index 5afb3bd..578def1 100644 --- a/core/modules/menu_link_content/src/MenuLinkContentAccessControlHandler.php +++ b/core/modules/menu_link_content/src/MenuLinkContentAccessControlHandler.php @@ -75,7 +75,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A } case 'delete': - return AccessResult::create()->allowIf(!$entity->isNew() && $account->hasPermission('administer menu'))->cachePerRole()->cacheUntilEntityChanges($entity); + return AccessResult::allowedIf(!$entity->isNew() && $account->hasPermission('administer menu'))->cachePerRole()->cacheUntilEntityChanges($entity); } } diff --git a/core/modules/menu_ui/src/Form/MenuLinkResetForm.php b/core/modules/menu_ui/src/Form/MenuLinkResetForm.php index 4bd2d92..411f13c 100644 --- a/core/modules/menu_ui/src/Form/MenuLinkResetForm.php +++ b/core/modules/menu_ui/src/Form/MenuLinkResetForm.php @@ -119,7 +119,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { * The access result. */ public function linkIsResettable(MenuLinkInterface $menu_link_plugin) { - return AccessResult::create()->allowIf($menu_link_plugin->isResettable())->setCacheable(FALSE); + return AccessResult::allowedIf($menu_link_plugin->isResettable())->setCacheable(FALSE); } } diff --git a/core/modules/node/node.api.php b/core/modules/node/node.api.php index 7141870..1a75128 100644 --- a/core/modules/node/node.api.php +++ b/core/modules/node/node.api.php @@ -334,22 +334,22 @@ function hook_node_access(\Drupal\node\NodeInterface $node, $op, \Drupal\Core\Se switch ($op) { case 'create': - return AccessResult::create()->allowIf($account->hasPermission('create ' . $type . ' content', $account))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission('create ' . $type . ' content', $account))->cachePerRole(); case 'update': if ($account->hasPermission('edit any ' . $type . ' content', $account)) { - return AccessResult::create()->allow()->cachePerRole(); + return AccessResult::allowed()->cachePerRole(); } else { - return AccessResult::create()->allowIf($account->hasPermission('edit own ' . $type . ' content', $account) && ($account->id() == $node->getOwnerId()))->cachePerRole()->cachePerUser()->cacheUntilEntityChanges($node); + return AccessResult::allowedIf($account->hasPermission('edit own ' . $type . ' content', $account) && ($account->id() == $node->getOwnerId()))->cachePerRole()->cachePerUser()->cacheUntilEntityChanges($node); } case 'delete': if ($account->hasPermission('delete any ' . $type . ' content', $account)) { - return AccessResult::create()->allow()->cachePerRole(); + return AccessResult::allowed()->cachePerRole(); } else { - return AccessResult::create()->allowIf($account->hasPermission('delete own ' . $type . ' content', $account) && ($account->id() == $node->getOwnerId()))->cachePerRole()->cachePerUser()->cacheUntilEntityChanges($node); + return AccessResult::allowedIf($account->hasPermission('delete own ' . $type . ' content', $account) && ($account->id() == $node->getOwnerId()))->cachePerRole()->cachePerUser()->cacheUntilEntityChanges($node); } default: diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 205e8ce..7eb88f2 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1155,22 +1155,22 @@ function node_node_access(NodeInterface $node, $op, $account) { switch ($op) { case 'create': - return AccessResult::create()->allowIf($account->hasPermission('create ' . $type . ' content', $account))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission('create ' . $type . ' content', $account))->cachePerRole(); case 'update': if ($account->hasPermission('edit any ' . $type . ' content', $account)) { - return AccessResult::create()->allow()->cachePerRole(); + return AccessResult::allowed()->cachePerRole(); } else { - return AccessResult::create()->allowIf($account->hasPermission('edit own ' . $type . ' content', $account) && ($account->id() == $node->getOwnerId()))->cachePerRole()->cachePerUser()->cacheUntilEntityChanges($node); + return AccessResult::allowedIf($account->hasPermission('edit own ' . $type . ' content', $account) && ($account->id() == $node->getOwnerId()))->cachePerRole()->cachePerUser()->cacheUntilEntityChanges($node); } case 'delete': if ($account->hasPermission('delete any ' . $type . ' content', $account)) { - return AccessResult::create()->allow()->cachePerRole(); + return AccessResult::allowed()->cachePerRole(); } else { - return AccessResult::create()->allowIf($account->hasPermission('delete own ' . $type . ' content', $account) && ($account->id() == $node->getOwnerId()))->cachePerRole()->cachePerUser()->cacheUntilEntityChanges($node); + return AccessResult::allowedIf($account->hasPermission('delete own ' . $type . ' content', $account) && ($account->id() == $node->getOwnerId()))->cachePerRole()->cachePerUser()->cacheUntilEntityChanges($node); } default: diff --git a/core/modules/node/src/Access/NodeRevisionAccessCheck.php b/core/modules/node/src/Access/NodeRevisionAccessCheck.php index 7d47de7..0fdc115 100644 --- a/core/modules/node/src/Access/NodeRevisionAccessCheck.php +++ b/core/modules/node/src/Access/NodeRevisionAccessCheck.php @@ -86,7 +86,7 @@ public function access(Route $route, AccountInterface $account, $node_revision = $node = $this->nodeStorage->loadRevision($node_revision); } $operation = $route->getRequirement('_access_node_revision'); - return AccessResult::create()->allowIf($node && $this->checkAccess($node, $account, $operation))->cachePerRole(); + return AccessResult::allowedIf($node && $this->checkAccess($node, $account, $operation))->cachePerRole(); } /** diff --git a/core/modules/node/src/NodeAccessControlHandler.php b/core/modules/node/src/NodeAccessControlHandler.php index 2e32a76..0678f3c 100644 --- a/core/modules/node/src/NodeAccessControlHandler.php +++ b/core/modules/node/src/NodeAccessControlHandler.php @@ -63,10 +63,10 @@ public function access(EntityInterface $entity, $operation, $langcode = Language $account = $this->prepareUser($account); if ($account->hasPermission('bypass node access')) { - return AccessResult::create()->allow()->cachePerRole(); + return AccessResult::allowed()->cachePerRole(); } if (!$account->hasPermission('access content')) { - return AccessResult::create()->forbid()->cachePerRole(); + return AccessResult::forbidden()->cachePerRole(); } return parent::access($entity, $operation, $langcode, $account)->cachePerRole(); } @@ -78,10 +78,10 @@ public function createAccess($entity_bundle = NULL, AccountInterface $account = $account = $this->prepareUser($account); if ($account->hasPermission('bypass node access')) { - return AccessResult::create()->allow()->cachePerRole(); + return AccessResult::allowed()->cachePerRole(); } if (!$account->hasPermission('access content')) { - return AccessResult::create()->forbid()->cachePerRole(); + return AccessResult::forbidden()->cachePerRole(); } return parent::createAccess($entity_bundle, $account, $context)->cachePerRole(); @@ -100,7 +100,7 @@ protected function checkAccess(EntityInterface $node, $operation, $langcode, Acc // Check if authors can view their own unpublished nodes. if ($operation === 'view' && !$status && $account->hasPermission('view own unpublished content') && $account->isAuthenticated() && $account->id() == $uid) { - return AccessResult::create()->allow()->cachePerRole()->cachePerUser()->cacheUntilEntityChanges($node); + return AccessResult::allowed()->cachePerRole()->cachePerUser()->cacheUntilEntityChanges($node); } // If no module specified either ALLOW or KILL, we fall back to the @@ -113,7 +113,7 @@ protected function checkAccess(EntityInterface $node, $operation, $langcode, Acc // If no modules implement hook_node_grants(), the default behavior is to // allow all users to view published nodes, so reflect that here. if ($operation === 'view') { - return AccessResult::create()->allowIf($status)->cacheUntilEntityChanges($node); + return AccessResult::allowedIf($status)->cacheUntilEntityChanges($node); } // No opinion. @@ -124,7 +124,7 @@ protected function checkAccess(EntityInterface $node, $operation, $langcode, Acc * {@inheritdoc} */ protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { - return AccessResult::create()->allowIf($account->hasPermission('create ' . $entity_bundle . ' content'))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission('create ' . $entity_bundle . ' content'))->cachePerRole(); } /** @@ -134,10 +134,10 @@ protected function checkFieldAccess($operation, FieldDefinitionInterface $field_ $administrative_fields = array('uid', 'status', 'created', 'promote', 'sticky', 'revision_log'); $read_only_fields = array('changed', 'revision_timestamp', 'revision_uid'); if ($operation == 'edit' && in_array($field_definition->getName(), $administrative_fields)) { - return AccessResult::create()->allowIf($account->hasPermission('administer nodes'))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission('administer nodes'))->cachePerRole(); } if ($operation == 'edit' && in_array($field_definition->getName(), $read_only_fields)) { - return AccessResult::create()->forbid(); + return AccessResult::forbidden(); } return parent::checkFieldAccess($operation, $field_definition, $account, $items); } diff --git a/core/modules/node/src/NodeGrantDatabaseStorage.php b/core/modules/node/src/NodeGrantDatabaseStorage.php index 0dfb698..78b96b5 100644 --- a/core/modules/node/src/NodeGrantDatabaseStorage.php +++ b/core/modules/node/src/NodeGrantDatabaseStorage.php @@ -94,10 +94,10 @@ public function access(NodeInterface $node, $operation, $langcode, AccountInterf // it is theoretically cacheable, because we don't have the necessary meta- // data to know it for a fact. if ($query->execute()->fetchField()) { - return AccessResult::create()->allow()->setCacheable(FALSE); + return AccessResult::allowed()->setCacheable(FALSE); } else { - return AccessResult::create()->forbid()->setCacheable(FALSE); + return AccessResult::forbidden()->setCacheable(FALSE); } } diff --git a/core/modules/node/src/NodeTypeAccessControlHandler.php b/core/modules/node/src/NodeTypeAccessControlHandler.php index ecf3101..b358944 100644 --- a/core/modules/node/src/NodeTypeAccessControlHandler.php +++ b/core/modules/node/src/NodeTypeAccessControlHandler.php @@ -25,7 +25,7 @@ class NodeTypeAccessControlHandler extends EntityAccessControlHandler { protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { if ($operation == 'delete') { if ($entity->isLocked()) { - return AccessResult::create()->forbid()->cacheUntilEntityChanges($entity); + return AccessResult::forbidden()->cacheUntilEntityChanges($entity); } else { return parent::checkAccess($entity, $operation, $langcode, $account)->cacheUntilEntityChanges($entity); diff --git a/core/modules/node/src/Plugin/Search/NodeSearch.php b/core/modules/node/src/Plugin/Search/NodeSearch.php index f2ba09ab..d6d7935 100644 --- a/core/modules/node/src/Plugin/Search/NodeSearch.php +++ b/core/modules/node/src/Plugin/Search/NodeSearch.php @@ -159,7 +159,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition * {@inheritdoc} */ public function access($operation = 'view', AccountInterface $account = NULL) { - return AccessResult::create()->allowIf($account->hasPermission('access content'))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission('access content'))->cachePerRole(); } /** 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 60ad45e..86fdbf1 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 @@ -164,7 +164,7 @@ function node_access_test_node_access(\Drupal\node\NodeInterface $node, $op, \Dr $secret_catalan = \Drupal::state()->get('node_access_test_secret_catalan') ?: 0; if ($secret_catalan && $langcode == 'ca') { // Make all Catalan content secret. - return AccessResult::create()->forbid()->setCacheable(FALSE); + return AccessResult::forbidden()->setCacheable(FALSE); } // No opinion. return AccessResult::create()->setCacheable(FALSE); diff --git a/core/modules/path/src/Plugin/Field/FieldType/PathFieldItemList.php b/core/modules/path/src/Plugin/Field/FieldType/PathFieldItemList.php index 7fd2fcf..20c3810 100644 --- a/core/modules/path/src/Plugin/Field/FieldType/PathFieldItemList.php +++ b/core/modules/path/src/Plugin/Field/FieldType/PathFieldItemList.php @@ -21,9 +21,9 @@ class PathFieldItemList extends FieldItemList { */ public function defaultAccess($operation = 'view', AccountInterface $account = NULL) { if ($operation == 'view') { - return AccessResult::create()->allow(); + return AccessResult::allowed(); } - return AccessResult::create()->allowIf($account->hasPermission('create url aliases') || $account->hasPermission('administer url aliases'))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission('create url aliases') || $account->hasPermission('administer url aliases'))->cachePerRole(); } } diff --git a/core/modules/quickedit/src/Access/EditEntityFieldAccessCheck.php b/core/modules/quickedit/src/Access/EditEntityFieldAccessCheck.php index a8e829d..d9f0b1e 100644 --- a/core/modules/quickedit/src/Access/EditEntityFieldAccessCheck.php +++ b/core/modules/quickedit/src/Access/EditEntityFieldAccessCheck.php @@ -36,7 +36,7 @@ class EditEntityFieldAccessCheck implements AccessInterface, EditEntityFieldAcce */ public function access(EntityInterface $entity, $field_name, $langcode, AccountInterface $account) { if (!$this->validateRequestAttributes($entity, $field_name, $langcode)) { - return AccessResult::create()->forbid(); + return AccessResult::forbidden(); } return $this->accessEditEntityField($entity, $field_name); diff --git a/core/modules/quickedit/tests/src/Access/EditEntityFieldAccessCheckTest.php b/core/modules/quickedit/tests/src/Access/EditEntityFieldAccessCheckTest.php index 0cfb596..cc37cf2 100644 --- a/core/modules/quickedit/tests/src/Access/EditEntityFieldAccessCheckTest.php +++ b/core/modules/quickedit/tests/src/Access/EditEntityFieldAccessCheckTest.php @@ -44,7 +44,7 @@ public function providerTestAccess() { $editable_entity = $this->createMockEntity(); $editable_entity->expects($this->any()) ->method('access') - ->will($this->returnValue(AccessResult::create()->allow()->cachePerRole())); + ->will($this->returnValue(AccessResult::allowed()->cachePerRole())); $non_editable_entity = $this->createMockEntity(); $non_editable_entity->expects($this->any()) @@ -56,7 +56,7 @@ public function providerTestAccess() { ->getMock(); $field_storage_with_access->expects($this->any()) ->method('access') - ->will($this->returnValue(AccessResult::create()->allow())); + ->will($this->returnValue(AccessResult::allowed())); $field_storage_without_access = $this->getMockBuilder('Drupal\field\Entity\FieldStorageConfig') ->disableOriginalConstructor() ->getMock(); @@ -65,7 +65,7 @@ public function providerTestAccess() { ->will($this->returnValue(AccessResult::create())); $data = array(); - $data[] = array($editable_entity, $field_storage_with_access, AccessResult::create()->allow()->cachePerRole()); + $data[] = array($editable_entity, $field_storage_with_access, AccessResult::allowed()->cachePerRole()); $data[] = array($non_editable_entity, $field_storage_with_access, AccessResult::create()->cachePerRole()); $data[] = array($editable_entity, $field_storage_without_access, AccessResult::create()->cachePerRole()); $data[] = array($non_editable_entity, $field_storage_without_access, AccessResult::create()->cachePerRole()); @@ -110,7 +110,7 @@ public function testAccess(EntityInterface $entity, FieldStorageConfigInterface public function testAccessKill($field_name, $langcode) { $account = $this->getMock('Drupal\Core\Session\AccountInterface'); $entity = $this->createMockEntity(); - $this->assertEquals(AccessResult::create()->forbid(), $this->editAccessCheck->access($entity, $field_name, $langcode, $account)); + $this->assertEquals(AccessResult::forbidden(), $this->editAccessCheck->access($entity, $field_name, $langcode, $account)); } /** diff --git a/core/modules/rest/src/Access/CSRFAccessCheck.php b/core/modules/rest/src/Access/CSRFAccessCheck.php index 4f4b243..563a0a4 100644 --- a/core/modules/rest/src/Access/CSRFAccessCheck.php +++ b/core/modules/rest/src/Access/CSRFAccessCheck.php @@ -66,10 +66,10 @@ public function access(Request $request, AccountInterface $account) { ) { $csrf_token = $request->headers->get('X-CSRF-Token'); if (!\Drupal::csrfToken()->validate($csrf_token, 'rest')) { - return AccessResult::create()->forbid()->setCacheable(FALSE); + return AccessResult::forbidden()->setCacheable(FALSE); } } // Let other access checkers decide if the request is legit. - return AccessResult::create()->allow()->setCacheable(FALSE); + return AccessResult::allowed()->setCacheable(FALSE); } } diff --git a/core/modules/search/src/SearchPageAccessControlHandler.php b/core/modules/search/src/SearchPageAccessControlHandler.php index 9ec5a42..0499dce 100644 --- a/core/modules/search/src/SearchPageAccessControlHandler.php +++ b/core/modules/search/src/SearchPageAccessControlHandler.php @@ -27,7 +27,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A /** @var $entity \Drupal\search\SearchPageInterface */ if (in_array($operation, array('delete', 'disable'))) { if ($entity->isDefaultSearch()) { - return AccessResult::create()->forbid()->cacheUntilEntityChanges($entity); + return AccessResult::forbidden()->cacheUntilEntityChanges($entity); } else { return parent::checkAccess($entity, $operation, $langcode, $account)->cacheUntilEntityChanges($entity); @@ -35,13 +35,13 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A } if ($operation == 'view') { if (!$entity->status()) { - return AccessResult::create()->forbid()->cacheUntilEntityChanges($entity); + return AccessResult::forbidden()->cacheUntilEntityChanges($entity); } $plugin = $entity->getPlugin(); if ($plugin instanceof AccessibleInterface) { return $plugin->access($operation, $account)->cacheUntilEntityChanges($entity); } - return AccessResult::create()->allow()->cacheUntilEntityChanges($entity); + return AccessResult::allowed()->cacheUntilEntityChanges($entity); } return parent::checkAccess($entity, $operation, $langcode, $account); } diff --git a/core/modules/shortcut/shortcut.module b/core/modules/shortcut/shortcut.module index 038c08e..6531e69 100644 --- a/core/modules/shortcut/shortcut.module +++ b/core/modules/shortcut/shortcut.module @@ -82,13 +82,13 @@ function shortcut_set_edit_access(ShortcutSetInterface $shortcut_set = NULL) { // Shortcut administrators can edit any set. if ($account->hasPermission('administer shortcuts')) { - return AccessResult::create()->allow()->cachePerRole(); + return AccessResult::allowed()->cachePerRole(); } // Sufficiently-privileged users can edit their currently displayed shortcut // set, but not other sets. They must also be able to access shortcuts. $may_edit_current_shortcut_set = $account->hasPermission('customize shortcut links') && (!isset($shortcut_set) || $shortcut_set == shortcut_current_displayed_set()) && $account->hasPermission('access shortcuts'); - return AccessResult::create()->allowIf($may_edit_current_shortcut_set)->cachePerRole(); + return AccessResult::allowedIf($may_edit_current_shortcut_set)->cachePerRole(); } /** @@ -107,7 +107,7 @@ function shortcut_set_switch_access($account = NULL) { if ($user->hasPermission('administer shortcuts')) { // Administrators can switch anyone's shortcut set. - return AccessResult::create()->allow()->cachePerRole(); + return AccessResult::allowed()->cachePerRole(); } if (!$user->hasPermission('access shortcuts')) { @@ -123,10 +123,10 @@ function shortcut_set_switch_access($account = NULL) { // Users with the 'switch shortcut sets' permission can switch their own // shortcuts sets. if (!isset($account)) { - return AccessResult::create()->allow()->cachePerRole(); + return AccessResult::allowed()->cachePerRole(); } else if ($user->id() == $account->id()) { - return AccessResult::create()->allow()->cachePerRole()->cachePerUser(); + return AccessResult::allowed()->cachePerRole()->cachePerUser(); } // No opinion. diff --git a/core/modules/shortcut/src/ShortcutSetAccessControlHandler.php b/core/modules/shortcut/src/ShortcutSetAccessControlHandler.php index f98e5bb..4968f04 100644 --- a/core/modules/shortcut/src/ShortcutSetAccessControlHandler.php +++ b/core/modules/shortcut/src/ShortcutSetAccessControlHandler.php @@ -26,15 +26,15 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A switch ($operation) { case 'update': if ($account->hasPermission('administer shortcuts')) { - return AccessResult::create()->allow()->cachePerRole(); + return AccessResult::allowed()->cachePerRole(); } if (!$account->hasPermission('access shortcuts')) { return AccessResult::create()->cachePerRole(); } - return AccessResult::create()->allowIf($account->hasPermission('customize shortcut links') && $entity == shortcut_current_displayed_set($account))->cachePerRole()->cacheUntilEntityChanges($entity); + return AccessResult::allowedIf($account->hasPermission('customize shortcut links') && $entity == shortcut_current_displayed_set($account))->cachePerRole()->cacheUntilEntityChanges($entity); case 'delete': - return AccessResult::create()->allowIf($account->hasPermission('administer shortcuts') && $entity->id() != 'default')->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission('administer shortcuts') && $entity->id() != 'default')->cachePerRole(); default: // No opinion. @@ -47,7 +47,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A */ protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { $condition = $account->hasPermission('administer shortcuts') || ($account->hasPermission('access shortcuts') && $account->hasPermission('customize shortcut links')); - return AccessResult::create()->allowIf($condition)->cachePerRole(); + return AccessResult::allowedIf($condition)->cachePerRole(); } } diff --git a/core/modules/system/entity.api.php b/core/modules/system/entity.api.php index 1fe7836..7a1d06f 100644 --- a/core/modules/system/entity.api.php +++ b/core/modules/system/entity.api.php @@ -1833,7 +1833,7 @@ function hook_entity_operation_alter(array &$operations, \Drupal\Core\Entity\Ent */ function hook_entity_field_access($operation, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, \Drupal\Core\Session\AccountInterface $account, \Drupal\Core\Field\FieldItemListInterface $items = NULL) { if ($field_definition->getName() == 'field_of_interest' && $operation == 'edit') { - return AccessResult::create()->allowIf($account->hasPermission('update field of interest'))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission('update field of interest'))->cachePerRole(); } } diff --git a/core/modules/system/src/Access/CronAccessCheck.php b/core/modules/system/src/Access/CronAccessCheck.php index 28e7861..acb1401 100644 --- a/core/modules/system/src/Access/CronAccessCheck.php +++ b/core/modules/system/src/Access/CronAccessCheck.php @@ -27,12 +27,12 @@ class CronAccessCheck implements AccessInterface { public function access($key) { if ($key != \Drupal::state()->get('system.cron_key')) { \Drupal::logger('cron')->notice('Cron could not run because an invalid key was used.'); - return AccessResult::create()->forbid()->setCacheable(FALSE); + return AccessResult::forbidden()->setCacheable(FALSE); } elseif (\Drupal::state()->get('system.maintenance_mode')) { \Drupal::logger('cron')->notice('Cron could not run because the site is in maintenance mode.'); - return AccessResult::create()->forbid()->setCacheable(FALSE); + return AccessResult::forbidden()->setCacheable(FALSE); } - return AccessResult::create()->allow()->setCacheable(FALSE); + return AccessResult::allowed()->setCacheable(FALSE); } } diff --git a/core/modules/system/src/DateFormatAccessControlHandler.php b/core/modules/system/src/DateFormatAccessControlHandler.php index 8ca220a..83009fc 100644 --- a/core/modules/system/src/DateFormatAccessControlHandler.php +++ b/core/modules/system/src/DateFormatAccessControlHandler.php @@ -25,12 +25,12 @@ class DateFormatAccessControlHandler extends EntityAccessControlHandler { protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { // There are no restrictions on viewing a date format. if ($operation == 'view') { - return AccessResult::create()->allow(); + return AccessResult::allowed(); } // Locked date formats cannot be updated or deleted. elseif (in_array($operation, array('update', 'delete'))) { if ($entity->isLocked()) { - return AccessResult::create()->forbid()->cacheUntilEntityChanges($entity); + return AccessResult::forbidden()->cacheUntilEntityChanges($entity); } else { return parent::checkAccess($entity, $operation, $langcode, $account)->cacheUntilEntityChanges($entity); diff --git a/core/modules/system/src/MenuAccessControlHandler.php b/core/modules/system/src/MenuAccessControlHandler.php index 37603a0..fba0183 100644 --- a/core/modules/system/src/MenuAccessControlHandler.php +++ b/core/modules/system/src/MenuAccessControlHandler.php @@ -24,12 +24,12 @@ class MenuAccessControlHandler extends EntityAccessControlHandler { */ protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { if ($operation === 'view') { - return AccessResult::create()->allow(); + return AccessResult::allowed(); } // Locked menus could not be deleted. elseif ($operation == 'delete') { if ($entity->isLocked()) { - return AccessResult::create()->forbid()->cacheUntilEntityChanges($entity); + return AccessResult::forbidden()->cacheUntilEntityChanges($entity); } else { return parent::checkAccess($entity, $operation, $langcode, $account)->cacheUntilEntityChanges($entity); diff --git a/core/modules/system/src/Tests/Entity/FieldAccessTest.php b/core/modules/system/src/Tests/Entity/FieldAccessTest.php index d55d1a0..5c66bd1 100644 --- a/core/modules/system/src/Tests/Entity/FieldAccessTest.php +++ b/core/modules/system/src/Tests/Entity/FieldAccessTest.php @@ -66,13 +66,13 @@ function testFieldAccess() { $values = array('name' => 'test'); $account = entity_create('user', $values); - $expected = AccessResult::create()->forbid()->cacheUntilEntityChanges($entity); + $expected = AccessResult::forbidden()->cacheUntilEntityChanges($entity); $this->assertEqual($expected, $entity->field_test_text->access('view', $account), 'Access to the field was denied.'); $entity->field_test_text = 'access alter value'; $this->assertEqual($expected, $entity->field_test_text->access('view', $account), 'Access to the field was denied.'); $entity->field_test_text = 'standard value'; - $this->assertEqual(AccessResult::create()->allow(), $entity->field_test_text->access('view', $account), 'Access to the field was granted.'); + $this->assertEqual(AccessResult::allowed(), $entity->field_test_text->access('view', $account), 'Access to the field was granted.'); } } diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index 24fa6fe..c623233 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -330,10 +330,10 @@ function entity_test_entity_field_access($operation, FieldDefinitionInterface $f if ($field_definition->getName() == 'field_test_text') { if ($items) { if ($items[0]->value == 'no access value') { - return AccessResult::create()->forbid()->cacheUntilEntityChanges($items->getEntity()); + return AccessResult::forbidden()->cacheUntilEntityChanges($items->getEntity()); } elseif ($operation == 'delete' && $items[0]->value == 'no delete access value') { - return AccessResult::create()->forbid()->cacheUntilEntityChanges($items->getEntity()); + return AccessResult::forbidden()->cacheUntilEntityChanges($items->getEntity()); } } } @@ -481,7 +481,7 @@ function entity_test_entity_access(EntityInterface $entity, $operation, AccountI // Uncacheable because the access result depends on a State key-value pair and // might therefore change at any time. $condition = \Drupal::state()->get("entity_test_entity_access.{$operation}." . $entity->id(), FALSE); - return AccessResult::create()->allowIf($condition)->setCacheable(FALSE); + return AccessResult::allowedIf($condition)->setCacheable(FALSE); } /** diff --git a/core/modules/system/tests/modules/entity_test/src/EntityTestAccessControlHandler.php b/core/modules/system/tests/modules/entity_test/src/EntityTestAccessControlHandler.php index 6d82b56..93d72dd 100644 --- a/core/modules/system/tests/modules/entity_test/src/EntityTestAccessControlHandler.php +++ b/core/modules/system/tests/modules/entity_test/src/EntityTestAccessControlHandler.php @@ -32,12 +32,12 @@ class EntityTestAccessControlHandler extends EntityAccessControlHandler { protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { if ($operation === 'view') { if ($langcode != LanguageInterface::LANGCODE_DEFAULT) { - return AccessResult::create()->allowIf($account->hasPermission('view test entity translations'))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission('view test entity translations'))->cachePerRole(); } - return AccessResult::create()->allowIf($account->hasPermission('view test entity'))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission('view test entity'))->cachePerRole(); } elseif (in_array($operation, array('update', 'delete'))) { - return AccessResult::create()->allowIf($account->hasPermission('administer entity_test content'))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission('administer entity_test content'))->cachePerRole(); } // No opinion. @@ -49,7 +49,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A * {@inheritdoc} */ protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { - return AccessResult::create()->allowIf($account->hasPermission('administer entity_test content'))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission('administer entity_test content'))->cachePerRole(); } } diff --git a/core/modules/system/tests/modules/router_test_directory/src/Access/DefinedTestAccessCheck.php b/core/modules/system/tests/modules/router_test_directory/src/Access/DefinedTestAccessCheck.php index d8b181b..b435a39 100644 --- a/core/modules/system/tests/modules/router_test_directory/src/Access/DefinedTestAccessCheck.php +++ b/core/modules/system/tests/modules/router_test_directory/src/Access/DefinedTestAccessCheck.php @@ -27,10 +27,10 @@ class DefinedTestAccessCheck implements AccessInterface { */ public function access(Route $route) { if ($route->getRequirement('_test_access') === 'TRUE') { - return AccessResult::create()->allow(); + return AccessResult::allowed(); } elseif ($route->getRequirement('_test_access') === 'FALSE') { - return AccessResult::create()->forbid(); + return AccessResult::forbidden(); } else { return AccessResult::create(); diff --git a/core/modules/system/tests/src/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php b/core/modules/system/tests/src/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php index ca8ef70..d5d33be 100644 --- a/core/modules/system/tests/src/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php +++ b/core/modules/system/tests/src/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php @@ -327,7 +327,7 @@ public function testBuildWithUserPath() { public function setupAccessManagerToAllow() { $this->accessManager->expects($this->any()) ->method('checkNamedRoute') - ->will($this->returnValue(AccessResult::create()->allow())); + ->will($this->returnValue(AccessResult::allowed())); } protected function setupStubPathProcessor() { diff --git a/core/modules/taxonomy/src/TermAccessControlHandler.php b/core/modules/taxonomy/src/TermAccessControlHandler.php index 49ad808..73fc39a 100644 --- a/core/modules/taxonomy/src/TermAccessControlHandler.php +++ b/core/modules/taxonomy/src/TermAccessControlHandler.php @@ -25,15 +25,15 @@ class TermAccessControlHandler extends EntityAccessControlHandler { protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { switch ($operation) { case 'view': - return AccessResult::create()->allowIf($account->hasPermission('access content'))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission('access content'))->cachePerRole(); break; case 'update': - return AccessResult::create()->allowIf($account->hasPermission("edit terms in {$entity->bundle()}") || $account->hasPermission('administer taxonomy'))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission("edit terms in {$entity->bundle()}") || $account->hasPermission('administer taxonomy'))->cachePerRole(); break; case 'delete': - return AccessResult::create()->allowIf($account->hasPermission("delete terms in {$entity->bundle()}") || $account->hasPermission('administer taxonomy'))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission("delete terms in {$entity->bundle()}") || $account->hasPermission('administer taxonomy'))->cachePerRole(); break; default: @@ -46,7 +46,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A * {@inheritdoc} */ protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { - return AccessResult::create()->allowIf($account->hasPermission('administer taxonomy'))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission('administer taxonomy'))->cachePerRole(); } } diff --git a/core/modules/toolbar/src/Controller/ToolbarController.php b/core/modules/toolbar/src/Controller/ToolbarController.php index 48087e0..2fe3ee1 100644 --- a/core/modules/toolbar/src/Controller/ToolbarController.php +++ b/core/modules/toolbar/src/Controller/ToolbarController.php @@ -44,7 +44,7 @@ public function subtreesJsonp() { */ public function checkSubTreeAccess(Request $request, $langcode) { $hash = $request->get('hash'); - return AccessResult::create()->allowIf($this->currentUser()->hasPermission('access toolbar') && $hash == _toolbar_get_subtrees_hash($langcode))->cachePerRole(); + return AccessResult::allowedIf($this->currentUser()->hasPermission('access toolbar') && $hash == _toolbar_get_subtrees_hash($langcode))->cachePerRole(); } } diff --git a/core/modules/tracker/src/Access/ViewOwnTrackerAccessCheck.php b/core/modules/tracker/src/Access/ViewOwnTrackerAccessCheck.php index 6eef52e..097627c 100644 --- a/core/modules/tracker/src/Access/ViewOwnTrackerAccessCheck.php +++ b/core/modules/tracker/src/Access/ViewOwnTrackerAccessCheck.php @@ -29,6 +29,6 @@ class ViewOwnTrackerAccessCheck implements AccessInterface { * The access result. */ public function access(AccountInterface $account, UserInterface $user) { - return AccessResult::create()->allowIf($user && $account->isAuthenticated() && ($user->id() == $account->id()))->cachePerUser(); + return AccessResult::allowedIf($user && $account->isAuthenticated() && ($user->id() == $account->id()))->cachePerUser(); } } diff --git a/core/modules/update/src/Access/UpdateManagerAccessCheck.php b/core/modules/update/src/Access/UpdateManagerAccessCheck.php index 482b15f..ebd0fab 100644 --- a/core/modules/update/src/Access/UpdateManagerAccessCheck.php +++ b/core/modules/update/src/Access/UpdateManagerAccessCheck.php @@ -42,7 +42,7 @@ public function __construct(Settings $settings) { public function access() { // Uncacheable because the access result depends on a Settings key-value // pair, and can therefore change at any time. - return AccessResult::create()->allowIf($this->settings->get('allow_authorize_operations', TRUE))->setCacheable(FALSE); + return AccessResult::allowedIf($this->settings->get('allow_authorize_operations', TRUE))->setCacheable(FALSE); } } diff --git a/core/modules/user/src/Access/LoginStatusCheck.php b/core/modules/user/src/Access/LoginStatusCheck.php index 5b05897..bd00173 100644 --- a/core/modules/user/src/Access/LoginStatusCheck.php +++ b/core/modules/user/src/Access/LoginStatusCheck.php @@ -29,7 +29,7 @@ class LoginStatusCheck implements AccessInterface { * The access result. */ public function access(Request $request, AccountInterface $account) { - return AccessResult::create()->allowIf($request->attributes->get('_menu_admin') || $account->isAuthenticated())->cachePerRole(); + return AccessResult::allowedIf($request->attributes->get('_menu_admin') || $account->isAuthenticated())->cachePerRole(); } } diff --git a/core/modules/user/src/Access/PermissionAccessCheck.php b/core/modules/user/src/Access/PermissionAccessCheck.php index 236135d..f26a6c7 100644 --- a/core/modules/user/src/Access/PermissionAccessCheck.php +++ b/core/modules/user/src/Access/PermissionAccessCheck.php @@ -30,6 +30,6 @@ class PermissionAccessCheck implements AccessInterface { */ public function access(Route $route, AccountInterface $account) { $permission = $route->getRequirement('_permission'); - return AccessResult::create()->allowIf($account->hasPermission($permission))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission($permission))->cachePerRole(); } } diff --git a/core/modules/user/src/Access/RegisterAccessCheck.php b/core/modules/user/src/Access/RegisterAccessCheck.php index db35767..3477a8a 100644 --- a/core/modules/user/src/Access/RegisterAccessCheck.php +++ b/core/modules/user/src/Access/RegisterAccessCheck.php @@ -29,6 +29,6 @@ class RegisterAccessCheck implements AccessInterface { * The access result. */ public function access(Request $request, AccountInterface $account) { - return AccessResult::create()->allowIf(($request->attributes->get('_menu_admin') || $account->isAnonymous()) && \Drupal::config('user.settings')->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY)->cachePerRole(); + return AccessResult::allowedIf(($request->attributes->get('_menu_admin') || $account->isAnonymous()) && \Drupal::config('user.settings')->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY)->cachePerRole(); } } diff --git a/core/modules/user/src/Access/RoleAccessCheck.php b/core/modules/user/src/Access/RoleAccessCheck.php index 05c9cef..ebfaa808 100644 --- a/core/modules/user/src/Access/RoleAccessCheck.php +++ b/core/modules/user/src/Access/RoleAccessCheck.php @@ -40,14 +40,14 @@ public function access(Route $route, AccountInterface $account) { if (count($explode_and) > 1) { $diff = array_diff($explode_and, $account->getRoles()); if (empty($diff)) { - return AccessResult::create()->allow()->cachePerRole(); + return AccessResult::allowed()->cachePerRole(); } } else { $explode_or = array_filter(array_map('trim', explode(',', $rid_string))); $intersection = array_intersect($explode_or, $account->getRoles()); if (!empty($intersection)) { - return AccessResult::create()->allow()->cachePerRole(); + return AccessResult::allowed()->cachePerRole(); } } diff --git a/core/modules/user/src/Plugin/Search/UserSearch.php b/core/modules/user/src/Plugin/Search/UserSearch.php index 32644f0..f336e6b 100644 --- a/core/modules/user/src/Plugin/Search/UserSearch.php +++ b/core/modules/user/src/Plugin/Search/UserSearch.php @@ -99,7 +99,7 @@ public function __construct(Connection $database, EntityManagerInterface $entity * {@inheritdoc} */ public function access($operation = 'view', AccountInterface $account = NULL) { - return AccessResult::create()->allowIf(!empty($account) && $account->hasPermission('access user profiles'))->cachePerRole(); + return AccessResult::allowedIf(!empty($account) && $account->hasPermission('access user profiles'))->cachePerRole(); } /** diff --git a/core/modules/user/src/RoleAccessControlHandler.php b/core/modules/user/src/RoleAccessControlHandler.php index aeb8388..52f590d 100644 --- a/core/modules/user/src/RoleAccessControlHandler.php +++ b/core/modules/user/src/RoleAccessControlHandler.php @@ -26,7 +26,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A switch ($operation) { case 'delete': if ($entity->id() == DRUPAL_ANONYMOUS_RID || $entity->id() == DRUPAL_AUTHENTICATED_RID) { - return AccessResult::create()->forbid(); + return AccessResult::forbidden(); } default: diff --git a/core/modules/user/src/UserAccessControlHandler.php b/core/modules/user/src/UserAccessControlHandler.php index fff45db..aab5f3b 100644 --- a/core/modules/user/src/UserAccessControlHandler.php +++ b/core/modules/user/src/UserAccessControlHandler.php @@ -27,33 +27,33 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A // The anonymous user's profile can neither be viewed, updated nor deleted. if ($entity->isAnonymous()) { - return AccessResult::create()->forbid(); + return AccessResult::forbidden(); } // Administrators can view/update/delete all user profiles. if ($account->hasPermission('administer users')) { - return AccessResult::create()->allow()->cachePerRole(); + return AccessResult::allowed()->cachePerRole(); } switch ($operation) { case 'view': // Only allow view access if the account is active. if ($account->hasPermission('access user profiles') && $entity->isActive()) { - return AccessResult::create()->allow()->cachePerRole()->cacheUntilEntityChanges($entity); + return AccessResult::allowed()->cachePerRole()->cacheUntilEntityChanges($entity); } // Users can view own profiles at all times. else if ($account->id() == $entity->id()) { - return AccessResult::create()->allow()->cachePerUser(); + return AccessResult::allowed()->cachePerUser(); } break; case 'update': // Users can always edit their own account. - return AccessResult::create()->allowIf($account->id() == $entity->id())->cachePerUser(); + return AccessResult::allowedIf($account->id() == $entity->id())->cachePerUser(); case 'delete': // Users with 'cancel account' permission can cancel their own account. - return AccessResult::create()->allowIf($account->id() == $entity->id() && $account->hasPermission('cancel account'))->cachePerRole()->cachePerUser(); + return AccessResult::allowedIf($account->id() == $entity->id() && $account->hasPermission('cancel account'))->cachePerRole()->cachePerUser(); } // No opinion. diff --git a/core/modules/views/src/ViewAccessControlHandler.php b/core/modules/views/src/ViewAccessControlHandler.php index 851e2b4..96d130e 100644 --- a/core/modules/views/src/ViewAccessControlHandler.php +++ b/core/modules/views/src/ViewAccessControlHandler.php @@ -24,7 +24,7 @@ class ViewAccessControlHandler extends EntityAccessControlHandler { */ public function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { if ($operation == 'view') { - return AccessResult::create()->allow(); + return AccessResult::allowed(); } else { return parent::checkAccess($entity, $operation, $langcode, $account); diff --git a/core/modules/views/src/ViewsAccessCheck.php b/core/modules/views/src/ViewsAccessCheck.php index fa69dd4..e239a1f 100644 --- a/core/modules/views/src/ViewsAccessCheck.php +++ b/core/modules/views/src/ViewsAccessCheck.php @@ -36,7 +36,7 @@ public function applies(Route $route) { * The access result. */ public function access(AccountInterface $account) { - return AccessResult::create()->allowIf($account->hasPermission('access all views'))->cachePerRole(); + return AccessResult::allowedIf($account->hasPermission('access all views'))->cachePerRole(); } } diff --git a/core/modules/views/tests/src/Plugin/argument_validator/EntityTest.php b/core/modules/views/tests/src/Plugin/argument_validator/EntityTest.php index 8397a1d..e4af2b3 100644 --- a/core/modules/views/tests/src/Plugin/argument_validator/EntityTest.php +++ b/core/modules/views/tests/src/Plugin/argument_validator/EntityTest.php @@ -53,8 +53,8 @@ protected function setUp() { $this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface'); - $access_allowed = AccessResult::create()->allow(); - $access_forbidden = AccessResult::create()->forbid(); + $access_allowed = AccessResult::allowed(); + $access_forbidden = AccessResult::forbidden(); $access_no_opinion = AccessResult::create(); $mock_entity = $this->getMockForAbstractClass('Drupal\Core\Entity\Entity', array(), '', FALSE, TRUE, TRUE, array('bundle', 'access')); diff --git a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php index 4755986..0c16d98 100644 --- a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php @@ -216,9 +216,9 @@ public function testCheck() { })); $this->assertEquals(AccessResult::create(), $this->accessManager->check($this->routeCollection->get('test_route_1'), $request, $this->account)); - $this->assertEquals(AccessResult::create()->allow(), $this->accessManager->check($this->routeCollection->get('test_route_2'), $request, $this->account)); - $this->assertEquals(AccessResult::create()->forbid(), $this->accessManager->check($this->routeCollection->get('test_route_3'), $request, $this->account)); - $this->assertEquals(AccessResult::create()->allow(), $this->accessManager->check($this->routeCollection->get('test_route_4'), $request, $this->account)); + $this->assertEquals(AccessResult::allowed(), $this->accessManager->check($this->routeCollection->get('test_route_2'), $request, $this->account)); + $this->assertEquals(AccessResult::forbidden(), $this->accessManager->check($this->routeCollection->get('test_route_3'), $request, $this->account)); + $this->assertEquals(AccessResult::allowed(), $this->accessManager->check($this->routeCollection->get('test_route_4'), $request, $this->account)); } /** @@ -230,9 +230,9 @@ public function testCheck() { * @see \Drupal\Tests\Core\Access\AccessManagerTest::testCheckConjunctions() */ public function providerTestCheckConjunctions() { - $access_allow = AccessResult::create()->allow(); + $access_allow = AccessResult::allowed(); $access_deny = AccessResult::create(); - $access_kill = AccessResult::create()->forbid(); + $access_kill = AccessResult::forbidden(); $access_configurations = array(); $access_configurations[] = array( @@ -413,14 +413,14 @@ public function testCheckNamedRoute() { // Tests the access with routes without parameters. $request = new Request(); - $this->assertEquals(AccessResult::create()->allow(), $this->accessManager->checkNamedRoute('test_route_2', array(), $this->account, $request)); - $this->assertEquals(AccessResult::create()->forbid(), $this->accessManager->checkNamedRoute('test_route_3', array(), $this->account, $request)); + $this->assertEquals(AccessResult::allowed(), $this->accessManager->checkNamedRoute('test_route_2', array(), $this->account, $request)); + $this->assertEquals(AccessResult::forbidden(), $this->accessManager->checkNamedRoute('test_route_3', array(), $this->account, $request)); // Tests the access with routes with parameters with given request. $request = new Request(); $request->attributes->set('value', 'example'); $request->attributes->set('value2', 'example2'); - $this->assertEquals(AccessResult::create()->allow(), $this->accessManager->checkNamedRoute('test_route_4', array(), $this->account, $request)); + $this->assertEquals(AccessResult::allowed(), $this->accessManager->checkNamedRoute('test_route_4', array(), $this->account, $request)); // Tests the access with routes without given request. $this->requestStack->push(new Request()); @@ -436,8 +436,8 @@ public function testCheckNamedRoute() { ->will($this->returnValue(array('value' => 'example'))); // Tests the access with routes with parameters without given request. - $this->assertEquals(AccessResult::create()->allow(), $this->accessManager->checkNamedRoute('test_route_2', array(), $this->account)); - $this->assertEquals(AccessResult::create()->allow(), $this->accessManager->checkNamedRoute('test_route_4', array('value' => 'example'), $this->account)); + $this->assertEquals(AccessResult::allowed(), $this->accessManager->checkNamedRoute('test_route_2', array(), $this->account)); + $this->assertEquals(AccessResult::allowed(), $this->accessManager->checkNamedRoute('test_route_4', array('value' => 'example'), $this->account)); } /** @@ -488,7 +488,7 @@ public function testCheckNamedRouteWithUpcastedValues() { ->will($this->returnValue(TRUE)); $access_check->expects($this->atLeastOnce()) ->method('access') - ->will($this->returnValue(AccessResult::create()->forbid())); + ->will($this->returnValue(AccessResult::forbidden())); $subrequest->attributes->set('value', 'upcasted_value'); $this->container->set('test_access', $access_check); @@ -496,7 +496,7 @@ public function testCheckNamedRouteWithUpcastedValues() { $this->accessManager->addCheckService('test_access', 'access'); $this->accessManager->setChecks($this->routeCollection); - $this->assertEquals(AccessResult::create()->forbid(), $this->accessManager->checkNamedRoute('test_route_1', array('value' => 'example'), $this->account)); + $this->assertEquals(AccessResult::forbidden(), $this->accessManager->checkNamedRoute('test_route_1', array('value' => 'example'), $this->account)); } /** @@ -548,7 +548,7 @@ public function testCheckNamedRouteWithDefaultValue() { ->will($this->returnValue(TRUE)); $access_check->expects($this->atLeastOnce()) ->method('access') - ->will($this->returnValue(AccessResult::create()->forbid())); + ->will($this->returnValue(AccessResult::forbidden())); $subrequest->attributes->set('value', 'upcasted_value'); $this->container->set('test_access', $access_check); @@ -556,7 +556,7 @@ public function testCheckNamedRouteWithDefaultValue() { $this->accessManager->addCheckService('test_access', 'access'); $this->accessManager->setChecks($this->routeCollection); - $this->assertEquals(AccessResult::create()->forbid(), $this->accessManager->checkNamedRoute('test_route_1', array(), $this->account)); + $this->assertEquals(AccessResult::forbidden(), $this->accessManager->checkNamedRoute('test_route_1', array(), $this->account)); } /** @@ -571,7 +571,7 @@ public function testCheckNamedRouteWithNonExistingRoute() { $this->setupAccessChecker(); - $this->assertEquals(AccessResult::create()->forbid()->addCacheTags(array('extension' => TRUE)), $this->accessManager->checkNamedRoute('test_route_1', array(), $this->account), 'A non existing route lead to access.'); + $this->assertEquals(AccessResult::forbidden()->addCacheTags(array('extension' => TRUE)), $this->accessManager->checkNamedRoute('test_route_1', array(), $this->account), 'A non existing route lead to access.'); } /** diff --git a/core/tests/Drupal/Tests/Core/Access/CsrfAccessCheckTest.php b/core/tests/Drupal/Tests/Core/Access/CsrfAccessCheckTest.php index 5ce3432..2a2822e 100644 --- a/core/tests/Drupal/Tests/Core/Access/CsrfAccessCheckTest.php +++ b/core/tests/Drupal/Tests/Core/Access/CsrfAccessCheckTest.php @@ -66,7 +66,7 @@ public function testAccessTokenPass() { // Set the _controller_request flag so tokens are validated. $request->attributes->set('_controller_request', TRUE); - $this->assertEquals(AccessResult::create()->allow()->setCacheable(FALSE), $this->accessCheck->access($route, $request, $this->account)); + $this->assertEquals(AccessResult::allowed()->setCacheable(FALSE), $this->accessCheck->access($route, $request, $this->account)); } /** @@ -84,7 +84,7 @@ public function testAccessTokenFail() { // Set the _controller_request flag so tokens are validated. $request->attributes->set('_controller_request', TRUE); - $this->assertEquals(AccessResult::create()->forbid()->setCacheable(FALSE), $this->accessCheck->access($route, $request, $this->account)); + $this->assertEquals(AccessResult::forbidden()->setCacheable(FALSE), $this->accessCheck->access($route, $request, $this->account)); } /** @@ -122,7 +122,7 @@ public function testAccessTokenMissAll() { 'token' => 'test_query', )); - $this->assertEquals(AccessResult::create()->allow()->setCacheable(FALSE), $this->accessCheck->access($route, $request, $this->account)); + $this->assertEquals(AccessResult::allowed()->setCacheable(FALSE), $this->accessCheck->access($route, $request, $this->account)); } } diff --git a/core/tests/Drupal/Tests/Core/Access/DefaultAccessCheckTest.php b/core/tests/Drupal/Tests/Core/Access/DefaultAccessCheckTest.php index 2c6b445..c7bc1df 100644 --- a/core/tests/Drupal/Tests/Core/Access/DefaultAccessCheckTest.php +++ b/core/tests/Drupal/Tests/Core/Access/DefaultAccessCheckTest.php @@ -53,10 +53,10 @@ public function testAccess() { $this->assertEquals(AccessResult::create(), $this->accessChecker->access($route, $request, $this->account)); $route = new Route('/test-route', array(), array('_access' => 'FALSE')); - $this->assertEquals(AccessResult::create()->forbid(), $this->accessChecker->access($route, $request, $this->account)); + $this->assertEquals(AccessResult::forbidden(), $this->accessChecker->access($route, $request, $this->account)); $route = new Route('/test-route', array(), array('_access' => 'TRUE')); - $this->assertEquals(AccessResult::create()->allow(), $this->accessChecker->access($route, $request, $this->account)); + $this->assertEquals(AccessResult::allowed(), $this->accessChecker->access($route, $request, $this->account)); } } diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php index 7cf2087..a6438a1 100644 --- a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php @@ -375,15 +375,15 @@ public function testAccess() { $access->expects($this->at(0)) ->method('access') ->with($this->entity, $operation) - ->will($this->returnValue(AccessResult::create()->allow())); + ->will($this->returnValue(AccessResult::allowed())); $access->expects($this->at(1)) ->method('createAccess') - ->will($this->returnValue(AccessResult::create()->allow())); + ->will($this->returnValue(AccessResult::allowed())); $this->entityManager->expects($this->exactly(2)) ->method('getAccessControlHandler') ->will($this->returnValue($access)); - $this->assertEquals(AccessResult::create()->allow(), $this->entity->access($operation)); - $this->assertEquals(AccessResult::create()->allow(), $this->entity->access('create')); + $this->assertEquals(AccessResult::allowed(), $this->entity->access($operation)); + $this->assertEquals(AccessResult::allowed(), $this->entity->access('create')); } /** diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityAccessCheckTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityAccessCheckTest.php index 3e2cc46..32388f5 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityAccessCheckTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityAccessCheckTest.php @@ -32,12 +32,12 @@ public function testAccess() { ->getMock(); $node->expects($this->any()) ->method('access') - ->will($this->returnValue(AccessResult::create()->allow()->cachePerRole())); + ->will($this->returnValue(AccessResult::allowed()->cachePerRole())); $access_check = new EntityAccessCheck(); $request->attributes->set('node', $node); $account = $this->getMock('Drupal\Core\Session\AccountInterface'); $access = $access_check->access($route, $request, $account); - $this->assertEquals(AccessResult::create()->allow()->cachePerRole(), $access); + $this->assertEquals(AccessResult::allowed()->cachePerRole(), $access); } } diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityCreateAccessCheckTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityCreateAccessCheckTest.php index 9cb41d9..f64b04a 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityCreateAccessCheckTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityCreateAccessCheckTest.php @@ -42,7 +42,7 @@ protected function setUp() { */ public function providerTestAccess() { $no_access = AccessResult::create()->cachePerRole(); - $access = AccessResult::create()->allow()->cachePerRole(); + $access = AccessResult::allowed()->cachePerRole(); $no_access_due_to_errors = AccessResult::create(); return array( diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php index d722484..7e2fce4 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php @@ -107,7 +107,7 @@ public function testGetOperations() { $this->role->expects($this->any()) ->method('access') - ->will($this->returnValue(AccessResult::create()->allow())); + ->will($this->returnValue(AccessResult::allowed())); $this->role->expects($this->any()) ->method('hasLinkTemplate') ->will($this->returnValue(TRUE)); diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php index 6f6afe4..4913446 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php @@ -215,15 +215,15 @@ public function testAccess() { $access->expects($this->at(0)) ->method('access') ->with($this->entity, $operation) - ->will($this->returnValue(AccessResult::create()->allow())); + ->will($this->returnValue(AccessResult::allowed())); $access->expects($this->at(1)) ->method('createAccess') - ->will($this->returnValue(AccessResult::create()->allow())); + ->will($this->returnValue(AccessResult::allowed())); $this->entityManager->expects($this->exactly(2)) ->method('getAccessControlHandler') ->will($this->returnValue($access)); - $this->assertEquals(AccessResult::create()->allow(), $this->entity->access($operation)); - $this->assertEquals(AccessResult::create()->allow(), $this->entity->access('create')); + $this->assertEquals(AccessResult::allowed(), $this->entity->access($operation)); + $this->assertEquals(AccessResult::allowed(), $this->entity->access('create')); } /** diff --git a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php index 577caa0..2f5242c 100644 --- a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php @@ -271,7 +271,7 @@ public function testGetContextualLinksArrayByGroup() { $this->accessManager->expects($this->any()) ->method('checkNamedRoute') - ->will($this->returnValue(AccessResult::create()->allow())); + ->will($this->returnValue(AccessResult::allowed())); // Set up mocking of the plugin factory. $map = array(); @@ -343,7 +343,7 @@ public function testGetContextualLinksArrayByGroupAccessCheck() { $this->accessManager->expects($this->any()) ->method('checkNamedRoute') ->will($this->returnValueMap(array( - array('test_route', array('key' => 'value'), $this->account, NULL, AccessResult::create()->allow()), + array('test_route', array('key' => 'value'), $this->account, NULL, AccessResult::allowed()), array('test_route2', array('key' => 'value'), $this->account, NULL, AccessResult::create()), ))); diff --git a/core/tests/Drupal/Tests/Core/Menu/DefaultMenuLinkTreeManipulatorsTest.php b/core/tests/Drupal/Tests/Core/Menu/DefaultMenuLinkTreeManipulatorsTest.php index 7f951c9..df6821a 100644 --- a/core/tests/Drupal/Tests/Core/Menu/DefaultMenuLinkTreeManipulatorsTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/DefaultMenuLinkTreeManipulatorsTest.php @@ -145,9 +145,9 @@ public function testCheckAccess() { ->method('checkNamedRoute') ->will($this->returnValueMap(array( array('example1', array(), $this->currentUser, NULL, AccessResult::create()), - array('example2', array('foo' => 'bar'), $this->currentUser, NULL, AccessResult::create()->allow()), + array('example2', array('foo' => 'bar'), $this->currentUser, NULL, AccessResult::allowed()), array('example3', array('baz' => 'qux'), $this->currentUser, NULL, AccessResult::create()), - array('example5', array(), $this->currentUser, NULL, AccessResult::create()->allow()), + array('example5', array(), $this->currentUser, NULL, AccessResult::allowed()), ))); $this->mockTree(); diff --git a/core/tests/Drupal/Tests/Core/Route/RoleAccessCheckTest.php b/core/tests/Drupal/Tests/Core/Route/RoleAccessCheckTest.php index 71ebb96..5fc7123 100644 --- a/core/tests/Drupal/Tests/Core/Route/RoleAccessCheckTest.php +++ b/core/tests/Drupal/Tests/Core/Route/RoleAccessCheckTest.php @@ -148,7 +148,7 @@ public function testRoleAccess($path, $grant_accounts, $deny_accounts) { foreach ($grant_accounts as $account) { $message = sprintf('Access granted for user with the roles %s on path: %s', implode(', ', $account->getRoles()), $path); - $this->assertEquals(AccessResult::create()->allow()->cachePerRole(), $role_access_check->access($collection->get($path), $account), $message); + $this->assertEquals(AccessResult::allowed()->cachePerRole(), $role_access_check->access($collection->get($path), $account), $message); } // Check all users which don't have access. diff --git a/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php b/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php index 2395ee4..94f0226 100644 --- a/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php @@ -75,7 +75,7 @@ public function testMatchRequestAllowed() { $this->setupRouter(); $this->accessManager->expects($this->once()) ->method('check') - ->will($this->returnValue(AccessResult::create()->allow())); + ->will($this->returnValue(AccessResult::allowed())); $request = new Request(); $parameters = $this->router->matchRequest($request); $this->assertSame($request->attributes->all(), array(RouteObjectInterface::ROUTE_OBJECT => $this->route)); @@ -91,7 +91,7 @@ public function testMatchRequestDenied() { $this->setupRouter(); $this->accessManager->expects($this->once()) ->method('check') - ->will($this->returnValue(AccessResult::create()->forbid())); + ->will($this->returnValue(AccessResult::forbidden())); $this->router->matchRequest(new Request()); }