From 4a45c16b0aa2125580f768e4dd05dad7695c309f Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Tue, 29 Jul 2014 09:48:31 +0100 Subject: [PATCH] Issue #2310705 by lokeoke, tim.plunkett, dawehner: AccessManager should introduce constants for 'ANY' / 'ALL'. --- .../Core/Access/AccessArgumentsResolver.php | 4 +- core/lib/Drupal/Core/Access/AccessManager.php | 54 ++--------- .../Core/Access/AccessManagerInterface.php | 96 +++++++++++++++++++ .../Drupal/Core/Access/CsrfAccessCheck.php | 4 +- .../EventSubscriber/AccessRouteSubscriber.php | 8 +- .../Core/EventSubscriber/AccessSubscriber.php | 8 +- .../Core/Menu/ContextualLinkManager.php | 8 +- .../Menu/DefaultMenuLinkTreeManipulators.php | 8 +- .../Drupal/Core/Menu/LocalActionManager.php | 8 +- .../lib/Drupal/Core/Menu/LocalTaskManager.php | 8 +- core/lib/Drupal/Core/Path/PathValidator.php | 8 +- .../book/src/BookBreadcrumbBuilder.php | 8 +- .../ConfigTranslationController.php | 8 +- .../src/Plugin/views/field/ContactLink.php | 8 +- .../ContentTranslationRouteSubscriber.php | 9 +- .../src/Form/MenuLinkContentForm.php | 8 +- .../src/MenuLinkContentAccessController.php | 8 +- .../src/Plugin/views/area/ListingEmpty.php | 8 +- core/modules/rest/src/Plugin/ResourceBase.php | 3 +- .../system/src/Form/ModulesListForm.php | 6 +- .../system/src/PathBasedBreadcrumbBuilder.php | 8 +- core/modules/system/system.module | 2 +- .../PathBasedBreadcrumbBuilderTest.php | 5 +- .../Plugin/views/display/PathPluginBase.php | 3 +- .../Tests/Core/Access/AccessManagerTest.php | 45 ++++----- .../Tests/Core/Access/CsrfAccessCheckTest.php | 11 ++- .../EventSubscriber/AccessSubscriberTest.php | 7 +- .../Core/Menu/ContextualLinkManagerTest.php | 6 +- .../DefaultMenuLinkTreeManipulatorsTest.php | 5 +- .../Core/Menu/LocalActionManagerTest.php | 10 +- .../Core/Menu/LocalTaskIntegrationTest.php | 5 +- .../Tests/Core/Menu/LocalTaskManagerTest.php | 6 +- 32 files changed, 224 insertions(+), 169 deletions(-) create mode 100644 core/lib/Drupal/Core/Access/AccessManagerInterface.php diff --git a/core/lib/Drupal/Core/Access/AccessArgumentsResolver.php b/core/lib/Drupal/Core/Access/AccessArgumentsResolver.php index 4c61fac30058..b2c5285a9b23 100644 --- a/core/lib/Drupal/Core/Access/AccessArgumentsResolver.php +++ b/core/lib/Drupal/Core/Access/AccessArgumentsResolver.php @@ -51,8 +51,8 @@ protected function getArgument(\ReflectionParameter $parameter, Route $route, Re $parameter_type_hint = $parameter->getClass(); $parameter_name = $parameter->getName(); - // @todo Remove this once AccessManager::checkNamedRoute() is fixed to not - // leak _raw_variables from the request being duplicated. + // @todo Remove this once AccessManagerInterface::checkNamedRoute() is fixed + // to not leak _raw_variables from the request being duplicated. // @see https://drupal.org/node/2265939 $raw_route_arguments += $upcasted_route_arguments; diff --git a/core/lib/Drupal/Core/Access/AccessManager.php b/core/lib/Drupal/Core/Access/AccessManager.php index 21185c1b8ada..0e9ac6bc3574 100644 --- a/core/lib/Drupal/Core/Access/AccessManager.php +++ b/core/lib/Drupal/Core/Access/AccessManager.php @@ -27,7 +27,7 @@ * * @see \Drupal\Tests\Core\Access\AccessManagerTest */ -class AccessManager implements ContainerAwareInterface { +class AccessManager implements ContainerAwareInterface, AccessManagerInterface { use ContainerAwareTrait; @@ -124,15 +124,7 @@ public function __construct(RouteProviderInterface $route_provider, UrlGenerator } /** - * Registers a new AccessCheck by service ID. - * - * @param string $service_id - * The ID of the service in the Container that provides a check. - * @param string $service_method - * The method to invoke on the service object for performing the check. - * @param array $applies_checks - * (optional) An array of route requirement keys the checker service applies - * to. + * {@inheritdoc} */ public function addCheckService($service_id, $service_method, array $applies_checks = array()) { $this->checkIds[] = $service_id; @@ -143,10 +135,7 @@ public function addCheckService($service_id, $service_method, array $applies_che } /** - * For each route, saves a list of applicable access checks to the route. - * - * @param \Symfony\Component\Routing\RouteCollection $routes - * A collection of routes to apply checks to. + * {@inheritdoc} */ public function setChecks(RouteCollection $routes) { $this->loadDynamicRequirementMap(); @@ -190,22 +179,7 @@ protected function applies(Route $route) { } /** - * Checks a named route with parameters against applicable access check services. - * - * Determines whether the route is accessible or not. - * - * @param string $route_name - * The route to check access to. - * @param array $parameters - * Optional array of values to substitute into the route path patern. - * @param \Drupal\Core\Session\AccountInterface $account - * The current user. - * @param \Symfony\Component\HttpFoundation\Request $route_request - * Optional incoming request object. If not provided, one will be built - * using the route information and the current request from the container. - * - * @return bool - * Returns TRUE if the user has access to the route, otherwise FALSE. + * {@inheritdoc} */ public function checkNamedRoute($route_name, array $parameters = array(), AccountInterface $account, Request $route_request = NULL) { try { @@ -228,25 +202,13 @@ public function checkNamedRoute($route_name, array $parameters = array(), Accoun } /** - * Checks a route against applicable access check services. - * - * Determines whether the route is accessible or not. - * - * @param \Symfony\Component\Routing\Route $route - * The route to check access to. - * @param \Symfony\Component\HttpFoundation\Request $request - * The incoming request object. - * @param \Drupal\Core\Session\AccountInterface $account - * The current account. - * - * @return bool - * Returns TRUE if the user has access to the route, otherwise FALSE. + * {@inheritdoc} */ public function check(Route $route, Request $request, AccountInterface $account) { $checks = $route->getOption('_access_checks') ?: array(); - $conjunction = $route->getOption('_access_mode') ?: 'ALL'; + $conjunction = $route->getOption('_access_mode') ?: static::ACCESS_MODE_ALL; - if ($conjunction == 'ALL') { + if ($conjunction == static::ACCESS_MODE_ALL) { return $this->checkAll($checks, $route, $request, $account); } else { @@ -390,7 +352,7 @@ protected function loadCheck($service_id) { /** * Compiles a mapping of requirement keys to access checker service IDs. */ - public function loadDynamicRequirementMap() { + protected function loadDynamicRequirementMap() { if (isset($this->dynamicRequirementMap)) { return; } diff --git a/core/lib/Drupal/Core/Access/AccessManagerInterface.php b/core/lib/Drupal/Core/Access/AccessManagerInterface.php new file mode 100644 index 000000000000..df88ba6e8204 --- /dev/null +++ b/core/lib/Drupal/Core/Access/AccessManagerInterface.php @@ -0,0 +1,96 @@ +<?php + +/** + * @file + * Contains \Drupal\Core\Access\AccessManagerInterface. + */ + +namespace Drupal\Core\Access; + +use Symfony\Component\Routing\Route; +use Symfony\Component\Routing\RouteCollection; +use Symfony\Component\HttpFoundation\Request; +use Drupal\Core\Session\AccountInterface; + +/** + * Provides an interface for attaching and running access check services. + */ +interface AccessManagerInterface { + + /** + * All access checkers have to return AccessInterface::ALLOW. + * + * self::ACCESS_MODE_ALL is the default behavior. + * + * @see \Drupal\Core\Access\AccessInterface::ALLOW + */ + const ACCESS_MODE_ALL = 'ALL'; + + /** + * At least one access checker has to return AccessInterface::ALLOW + * and none should return AccessInterface::KILL. + * + * @see \Drupal\Core\Access\AccessInterface::ALLOW + * @see \Drupal\Core\Access\AccessInterface::KILL + */ + const ACCESS_MODE_ANY = 'ANY'; + + /** + * Checks a named route with parameters against applicable access check services. + * + * Determines whether the route is accessible or not. + * + * @param string $route_name + * The route to check access to. + * @param array $parameters + * Optional array of values to substitute into the route path patern. + * @param \Drupal\Core\Session\AccountInterface $account + * The current user. + * @param \Symfony\Component\HttpFoundation\Request $route_request + * Optional incoming request object. If not provided, one will be built + * using the route information and the current request from the container. + * + * @return bool + * Returns TRUE if the user has access to the route, otherwise FALSE. + */ + public function checkNamedRoute($route_name, array $parameters = array(), AccountInterface $account, Request $route_request = NULL); + + /** + * For each route, saves a list of applicable access checks to the route. + * + * @param \Symfony\Component\Routing\RouteCollection $routes + * A collection of routes to apply checks to. + */ + public function setChecks(RouteCollection $routes); + + /** + * Registers a new AccessCheck by service ID. + * + * @param string $service_id + * The ID of the service in the Container that provides a check. + * @param string $service_method + * The method to invoke on the service object for performing the check. + * @param array $applies_checks + * (optional) An array of route requirement keys the checker service applies + * to. + */ + public function addCheckService($service_id, $service_method, array $applies_checks = array()); + + /** + * Checks a route against applicable access check services. + * + * Determines whether the route is accessible or not. + * + * @param \Symfony\Component\Routing\Route $route + * The route to check access to. + * @param \Symfony\Component\HttpFoundation\Request $request + * The incoming request object. + * @param \Drupal\Core\Session\AccountInterface $account + * The current account. + * + * @return bool + * Returns TRUE if the user has access to the route, otherwise FALSE. + */ + public function check(Route $route, Request $request, AccountInterface $account); + +} diff --git a/core/lib/Drupal/Core/Access/CsrfAccessCheck.php b/core/lib/Drupal/Core/Access/CsrfAccessCheck.php index 64c732879b34..f6b60d3dc82f 100644 --- a/core/lib/Drupal/Core/Access/CsrfAccessCheck.php +++ b/core/lib/Drupal/Core/Access/CsrfAccessCheck.php @@ -58,9 +58,9 @@ public function access(Route $route, Request $request) { // Otherwise, this could be another requested access check that we don't // want to check CSRF tokens on. - $conjunction = $route->getOption('_access_mode') ?: 'ANY'; + $conjunction = $route->getOption('_access_mode') ?: AccessManagerInterface::ACCESS_MODE_ANY; // Return ALLOW if all access checks are needed. - if ($conjunction == 'ALL') { + if ($conjunction == AccessManagerInterface::ACCESS_MODE_ALL) { return static::ALLOW; } // Return DENY otherwise, as another access checker should grant access diff --git a/core/lib/Drupal/Core/EventSubscriber/AccessRouteSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/AccessRouteSubscriber.php index dee7d3202b32..240073b82713 100644 --- a/core/lib/Drupal/Core/EventSubscriber/AccessRouteSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/AccessRouteSubscriber.php @@ -7,7 +7,7 @@ namespace Drupal\Core\EventSubscriber; -use Drupal\Core\Access\AccessManager; +use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Routing\RouteBuildEvent; use Drupal\Core\Routing\RoutingEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -20,18 +20,18 @@ class AccessRouteSubscriber implements EventSubscriberInterface { /** * The access manager. * - * @var \Drupal\Core\Access\AccessManager + * @var \Drupal\Core\Access\AccessManagerInterface */ protected $accessManager; /** * Constructs a new AccessSubscriber. * - * @param \Drupal\Core\Access\AccessManager $access_manager + * @param \Drupal\Core\Access\AccessManagerInterface $access_manager * The access check manager that will be responsible for applying * AccessCheckers against routes. */ - public function __construct(AccessManager $access_manager) { + public function __construct(AccessManagerInterface $access_manager) { $this->accessManager = $access_manager; } diff --git a/core/lib/Drupal/Core/EventSubscriber/AccessSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/AccessSubscriber.php index 0c319994395b..02a65edbae90 100644 --- a/core/lib/Drupal/Core/EventSubscriber/AccessSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/AccessSubscriber.php @@ -7,7 +7,7 @@ namespace Drupal\Core\EventSubscriber; -use Drupal\Core\Access\AccessManager; +use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Session\AccountInterface; use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\HttpKernel\KernelEvents; @@ -31,20 +31,20 @@ class AccessSubscriber implements EventSubscriberInterface { /** * The access manager. * - * @var \Drupal\Core\Access\AccessManager + * @var \Drupal\Core\Access\AccessManagerInterface */ protected $accessManager; /** * Constructs a new AccessSubscriber. * - * @param \Drupal\Core\Access\AccessManager $access_manager + * @param \Drupal\Core\Access\AccessManagerInterface $access_manager * The access check manager that will be responsible for applying * AccessCheckers against routes. * @param \Drupal\Core\Session\AccountInterface $current_user * The current user. */ - public function __construct(AccessManager $access_manager, AccountInterface $current_user) { + public function __construct(AccessManagerInterface $access_manager, AccountInterface $current_user) { $this->accessManager = $access_manager; $this->currentUser = $current_user; } diff --git a/core/lib/Drupal/Core/Menu/ContextualLinkManager.php b/core/lib/Drupal/Core/Menu/ContextualLinkManager.php index 64c8f30d810a..cbbf4e4c54c7 100644 --- a/core/lib/Drupal/Core/Menu/ContextualLinkManager.php +++ b/core/lib/Drupal/Core/Menu/ContextualLinkManager.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Menu; use Drupal\Component\Plugin\Exception\PluginException; -use Drupal\Core\Access\AccessManager; +use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Controller\ControllerResolverInterface; use Drupal\Core\Extension\ModuleHandlerInterface; @@ -59,7 +59,7 @@ class ContextualLinkManager extends DefaultPluginManager implements ContextualLi /** * The access manager. * - * @var \Drupal\Core\Access\AccessManager + * @var \Drupal\Core\Access\AccessManagerInterface */ protected $accessManager; @@ -95,14 +95,14 @@ class ContextualLinkManager extends DefaultPluginManager implements ContextualLi * The cache backend. * @param \Drupal\Core\Language\LanguageManager $language_manager * The language manager. - * @param \Drupal\Core\Access\AccessManager $access_manager + * @param \Drupal\Core\Access\AccessManagerInterface $access_manager * The access manager. * @param \Drupal\Core\Session\AccountInterface $account * The current user. * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack * The request stack. */ - public function __construct(ControllerResolverInterface $controller_resolver, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend, LanguageManager $language_manager, AccessManager $access_manager, AccountInterface $account, RequestStack $request_stack) { + public function __construct(ControllerResolverInterface $controller_resolver, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend, LanguageManager $language_manager, AccessManagerInterface $access_manager, AccountInterface $account, RequestStack $request_stack) { $this->discovery = new YamlDiscovery('links.contextual', $module_handler->getModuleDirectories()); $this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery); $this->factory = new ContainerFactory($this); diff --git a/core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php b/core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php index 33ae97b42bfc..ae5b285c5094 100644 --- a/core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php +++ b/core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Menu; -use Drupal\Core\Access\AccessManager; +use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Session\AccountInterface; /** @@ -24,7 +24,7 @@ class DefaultMenuLinkTreeManipulators { /** * The access manager. * - * @var \Drupal\Core\Access\AccessManager + * @var \Drupal\Core\Access\AccessManagerInterface */ protected $accessManager; @@ -38,12 +38,12 @@ class DefaultMenuLinkTreeManipulators { /** * Constructs a \Drupal\Core\Menu\DefaultMenuLinkTreeManipulators object. * - * @param \Drupal\Core\Access\AccessManager $access_manager + * @param \Drupal\Core\Access\AccessManagerInterface $access_manager * The access manager. * @param \Drupal\Core\Session\AccountInterface $account * The current user. */ - public function __construct(AccessManager $access_manager, AccountInterface $account) { + public function __construct(AccessManagerInterface $access_manager, AccountInterface $account) { $this->accessManager = $access_manager; $this->account = $account; } diff --git a/core/lib/Drupal/Core/Menu/LocalActionManager.php b/core/lib/Drupal/Core/Menu/LocalActionManager.php index 456b749ebcff..1167357345ed 100644 --- a/core/lib/Drupal/Core/Menu/LocalActionManager.php +++ b/core/lib/Drupal/Core/Menu/LocalActionManager.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Menu; -use Drupal\Core\Access\AccessManager; +use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\LanguageManagerInterface; @@ -78,7 +78,7 @@ class LocalActionManager extends DefaultPluginManager { /** * The access manager. * - * @var \Drupal\Core\Access\AccessManager + * @var \Drupal\Core\Access\AccessManagerInterface */ protected $accessManager; @@ -111,12 +111,12 @@ class LocalActionManager extends DefaultPluginManager { * Cache backend instance to use. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. - * @param \Drupal\Core\Access\AccessManager $access_manager + * @param \Drupal\Core\Access\AccessManagerInterface $access_manager * The access manager. * @param \Drupal\Core\Session\AccountInterface $account * The current user. */ - public function __construct(ControllerResolverInterface $controller_resolver, RequestStack $request_stack, RouteProviderInterface $route_provider, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager, AccessManager $access_manager, AccountInterface $account) { + public function __construct(ControllerResolverInterface $controller_resolver, RequestStack $request_stack, RouteProviderInterface $route_provider, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager, AccessManagerInterface $access_manager, AccountInterface $account) { // Skip calling the parent constructor, since that assumes annotation-based // discovery. $this->discovery = new YamlDiscovery('links.action', $module_handler->getModuleDirectories()); diff --git a/core/lib/Drupal/Core/Menu/LocalTaskManager.php b/core/lib/Drupal/Core/Menu/LocalTaskManager.php index ff9b52a5d94b..839ef32b4e77 100644 --- a/core/lib/Drupal/Core/Menu/LocalTaskManager.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskManager.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Menu; use Drupal\Component\Plugin\Exception\PluginException; -use Drupal\Core\Access\AccessManager; +use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Controller\ControllerResolverInterface; @@ -94,7 +94,7 @@ class LocalTaskManager extends DefaultPluginManager { /** * The access manager. * - * @var \Drupal\Core\Access\AccessManager + * @var \Drupal\Core\Access\AccessManagerInterface */ protected $accessManager; @@ -122,12 +122,12 @@ class LocalTaskManager extends DefaultPluginManager { * The cache backend. * @param \Drupal\Core\Language\LanguageManager $language_manager * The language manager. - * @param \Drupal\Core\Access\AccessManager $access_manager + * @param \Drupal\Core\Access\AccessManagerInterface $access_manager * The access manager. * @param \Drupal\Core\Session\AccountInterface $account * The current user. */ - public function __construct(ControllerResolverInterface $controller_resolver, RequestStack $request_stack, RouteProviderInterface $route_provider, RouteBuilderInterface $route_builder, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManager $language_manager, AccessManager $access_manager, AccountInterface $account) { + public function __construct(ControllerResolverInterface $controller_resolver, RequestStack $request_stack, RouteProviderInterface $route_provider, RouteBuilderInterface $route_builder, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManager $language_manager, AccessManagerInterface $access_manager, AccountInterface $account) { $this->discovery = new YamlDiscovery('links.task', $module_handler->getModuleDirectories()); $this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery); $this->factory = new ContainerFactory($this); diff --git a/core/lib/Drupal/Core/Path/PathValidator.php b/core/lib/Drupal/Core/Path/PathValidator.php index 3d658d44e3e9..a90148b6960c 100644 --- a/core/lib/Drupal/Core/Path/PathValidator.php +++ b/core/lib/Drupal/Core/Path/PathValidator.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Path; use Drupal\Component\Utility\UrlHelper; -use Drupal\Core\Access\AccessManager; +use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\ParamConverter\ParamNotConvertedException; use Drupal\Core\Routing\RequestHelper; use Drupal\Core\Routing\RouteProviderInterface; @@ -45,7 +45,7 @@ class PathValidator implements PathValidatorInterface { /** * The access manager. * - * @var \Drupal\Core\Access\AccessManager + * @var \Drupal\Core\Access\AccessManagerInterface */ protected $accessManager; @@ -65,12 +65,12 @@ class PathValidator implements PathValidatorInterface { * The route provider. * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack * The request stack. - * @param \Drupal\Core\Access\AccessManager $access_manager + * @param \Drupal\Core\Access\AccessManagerInterface $access_manager * The access manager. * @param \Drupal\Core\Session\AccountInterface $account * The user account. */ - public function __construct(RequestMatcherInterface $request_matcher, RouteProviderInterface $route_provider, RequestStack $request_stack, AccessManager $access_manager, AccountInterface $account) { + public function __construct(RequestMatcherInterface $request_matcher, RouteProviderInterface $route_provider, RequestStack $request_stack, AccessManagerInterface $access_manager, AccountInterface $account) { $this->requestMatcher = $request_matcher; $this->routeProvider = $route_provider; $this->requestStack = $request_stack; diff --git a/core/modules/book/src/BookBreadcrumbBuilder.php b/core/modules/book/src/BookBreadcrumbBuilder.php index fc48f9024d9c..bcdb593a80d5 100644 --- a/core/modules/book/src/BookBreadcrumbBuilder.php +++ b/core/modules/book/src/BookBreadcrumbBuilder.php @@ -7,7 +7,7 @@ namespace Drupal\book; -use Drupal\Core\Access\AccessManager; +use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Routing\LinkGeneratorTrait; @@ -33,7 +33,7 @@ class BookBreadcrumbBuilder implements BreadcrumbBuilderInterface { /** * The access manager. * - * @var \Drupal\Core\Access\AccessManager + * @var \Drupal\Core\Access\AccessManagerInterface */ protected $accessManager; @@ -49,12 +49,12 @@ class BookBreadcrumbBuilder implements BreadcrumbBuilderInterface { * * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager service. - * @param \Drupal\Core\Access\AccessManager $access_manager + * @param \Drupal\Core\Access\AccessManagerInterface $access_manager * The access manager. * @param \Drupal\Core\Session\AccountInterface $account * The current user account. */ - public function __construct(EntityManagerInterface $entity_manager, AccessManager $access_manager, AccountInterface $account) { + public function __construct(EntityManagerInterface $entity_manager, AccessManagerInterface $access_manager, AccountInterface $account) { $this->nodeStorage = $entity_manager->getStorage('node'); $this->accessManager = $access_manager; $this->account = $account; diff --git a/core/modules/config_translation/src/Controller/ConfigTranslationController.php b/core/modules/config_translation/src/Controller/ConfigTranslationController.php index 827b99ee7c91..cb7f6b792ab7 100644 --- a/core/modules/config_translation/src/Controller/ConfigTranslationController.php +++ b/core/modules/config_translation/src/Controller/ConfigTranslationController.php @@ -8,7 +8,7 @@ namespace Drupal\config_translation\Controller; use Drupal\config_translation\ConfigMapperManagerInterface; -use Drupal\Core\Access\AccessManager; +use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageManagerInterface; @@ -36,7 +36,7 @@ class ConfigTranslationController extends ControllerBase { /** * The menu link access service. * - * @var \Drupal\Core\Access\AccessManager + * @var \Drupal\Core\Access\AccessManagerInterface */ protected $accessManager; @@ -73,7 +73,7 @@ class ConfigTranslationController extends ControllerBase { * * @param \Drupal\config_translation\ConfigMapperManagerInterface $config_mapper_manager * The configuration mapper manager. - * @param \Drupal\Core\Access\AccessManager $access_manager + * @param \Drupal\Core\Access\AccessManagerInterface $access_manager * The menu link access service. * @param \Symfony\Component\Routing\Matcher\RequestMatcherInterface $router * The dynamic router service. @@ -84,7 +84,7 @@ class ConfigTranslationController extends ControllerBase { * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. */ - public function __construct(ConfigMapperManagerInterface $config_mapper_manager, AccessManager $access_manager, RequestMatcherInterface $router, InboundPathProcessorInterface $path_processor, AccountInterface $account, LanguageManagerInterface $language_manager) { + public function __construct(ConfigMapperManagerInterface $config_mapper_manager, AccessManagerInterface $access_manager, RequestMatcherInterface $router, InboundPathProcessorInterface $path_processor, AccountInterface $account, LanguageManagerInterface $language_manager) { $this->configMapperManager = $config_mapper_manager; $this->accessManager = $access_manager; $this->router = $router; diff --git a/core/modules/contact/src/Plugin/views/field/ContactLink.php b/core/modules/contact/src/Plugin/views/field/ContactLink.php index e0daca3bc473..15313e0089cb 100644 --- a/core/modules/contact/src/Plugin/views/field/ContactLink.php +++ b/core/modules/contact/src/Plugin/views/field/ContactLink.php @@ -7,7 +7,7 @@ namespace Drupal\contact\Plugin\views\field; -use Drupal\Core\Access\AccessManager; +use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Session\AccountInterface; use Drupal\user\Plugin\views\field\Link; @@ -26,7 +26,7 @@ class ContactLink extends Link { /** * The access manager. * - * @var \Drupal\Core\Access\AccessManager + * @var \Drupal\Core\Access\AccessManagerInterface */ protected $accessManager; @@ -61,10 +61,10 @@ protected function currentUser() { * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. - * @param \Drupal\Core\Access\AccessManager $access_manager + * @param \Drupal\Core\Access\AccessManagerInterface $access_manager * The access manager. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, AccessManager $access_manager) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, AccessManagerInterface $access_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->accessManager = $access_manager; } diff --git a/core/modules/content_translation/src/Routing/ContentTranslationRouteSubscriber.php b/core/modules/content_translation/src/Routing/ContentTranslationRouteSubscriber.php index 62b81fd9027a..aa9f346cadeb 100644 --- a/core/modules/content_translation/src/Routing/ContentTranslationRouteSubscriber.php +++ b/core/modules/content_translation/src/Routing/ContentTranslationRouteSubscriber.php @@ -8,6 +8,7 @@ namespace Drupal\content_translation\Routing; use Drupal\content_translation\ContentTranslationManagerInterface; +use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Routing\RouteSubscriberBase; use Drupal\Core\Routing\RoutingEvents; use Symfony\Component\Routing\Route; @@ -63,7 +64,7 @@ protected function alterRoutes(RouteCollection $collection) { '_permission' => 'translate any entity', ), array( - '_access_mode' => 'ANY', + '_access_mode' => AccessManagerInterface::ACCESS_MODE_ANY, 'parameters' => array( 'entity' => array( 'type' => 'entity:' . $entity_type_id, @@ -92,7 +93,7 @@ protected function alterRoutes(RouteCollection $collection) { '_access_content_translation_manage' => 'create', ), array( - '_access_mode' => 'ANY', + '_access_mode' => AccessManagerInterface::ACCESS_MODE_ANY, 'parameters' => array( 'entity' => array( 'type' => 'entity:' . $entity_type_id, @@ -119,7 +120,7 @@ protected function alterRoutes(RouteCollection $collection) { '_access_content_translation_manage' => 'update', ), array( - '_access_mode' => 'ANY', + '_access_mode' => AccessManagerInterface::ACCESS_MODE_ANY, 'parameters' => array( 'entity' => array( 'type' => 'entity:' . $entity_type_id, @@ -154,7 +155,7 @@ protected function alterRoutes(RouteCollection $collection) { 'type' => 'entity:' . $entity_type_id, ), ), - '_access_mode' => 'ANY', + '_access_mode' => AccessManagerInterface::ACCESS_MODE_ANY, '_admin_route' => $is_admin, ) ); diff --git a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php index efbc76cef5f4..c3f63956253f 100644 --- a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php +++ b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php @@ -8,7 +8,7 @@ namespace Drupal\menu_link_content\Form; use Drupal\Component\Utility\UrlHelper; -use Drupal\Core\Access\AccessManager; +use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Entity\ContentEntityForm; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; @@ -65,7 +65,7 @@ class MenuLinkContentForm extends ContentEntityForm implements MenuLinkFormInter /** * The access manager. * - * @var \Drupal\Core\Access\AccessManager + * @var \Drupal\Core\Access\AccessManagerInterface */ protected $accessManager; @@ -91,12 +91,12 @@ class MenuLinkContentForm extends ContentEntityForm implements MenuLinkFormInter * The request context. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. - * @param \Drupal\Core\Access\AccessManager $access_manager + * @param \Drupal\Core\Access\AccessManagerInterface $access_manager * The access manager. * @param \Drupal\Core\Session\AccountInterface $account * The current user. */ - public function __construct(EntityManagerInterface $entity_manager, MenuParentFormSelectorInterface $menu_parent_selector, AliasManagerInterface $alias_manager, ModuleHandlerInterface $module_handler, RequestContext $request_context, LanguageManagerInterface $language_manager, AccessManager $access_manager, AccountInterface $account) { + public function __construct(EntityManagerInterface $entity_manager, MenuParentFormSelectorInterface $menu_parent_selector, AliasManagerInterface $alias_manager, ModuleHandlerInterface $module_handler, RequestContext $request_context, LanguageManagerInterface $language_manager, AccessManagerInterface $access_manager, AccountInterface $account) { parent::__construct($entity_manager, $language_manager); $this->menuParentSelector = $menu_parent_selector; $this->pathAliasManager = $alias_manager; diff --git a/core/modules/menu_link_content/src/MenuLinkContentAccessController.php b/core/modules/menu_link_content/src/MenuLinkContentAccessController.php index c99109e40621..ad36c1998b61 100644 --- a/core/modules/menu_link_content/src/MenuLinkContentAccessController.php +++ b/core/modules/menu_link_content/src/MenuLinkContentAccessController.php @@ -6,7 +6,7 @@ namespace Drupal\menu_link_content; -use Drupal\Core\Access\AccessManager; +use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Entity\EntityControllerInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityAccessController; @@ -22,7 +22,7 @@ class MenuLinkContentAccessController extends EntityAccessController implements /** * The access manager to check routes by name. * - * @var \Drupal\Core\Access\AccessManager + * @var \Drupal\Core\Access\AccessManagerInterface */ protected $accessManager; @@ -31,10 +31,10 @@ class MenuLinkContentAccessController extends EntityAccessController implements * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type definition. - * @param \Drupal\Core\Access\AccessManager $access_manager + * @param \Drupal\Core\Access\AccessManagerInterface $access_manager * The access manager to check routes by name. */ - public function __construct(EntityTypeInterface $entity_type, AccessManager $access_manager) { + public function __construct(EntityTypeInterface $entity_type, AccessManagerInterface $access_manager) { parent::__construct($entity_type); $this->accessManager = $access_manager; diff --git a/core/modules/node/src/Plugin/views/area/ListingEmpty.php b/core/modules/node/src/Plugin/views/area/ListingEmpty.php index dbb6765d9206..cba41c288c7f 100644 --- a/core/modules/node/src/Plugin/views/area/ListingEmpty.php +++ b/core/modules/node/src/Plugin/views/area/ListingEmpty.php @@ -7,7 +7,7 @@ namespace Drupal\node\Plugin\views\area; -use Drupal\Core\Access\AccessManager; +use Drupal\Core\Access\AccessManagerInterface; use Drupal\views\Plugin\views\area\AreaPluginBase; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -23,7 +23,7 @@ class ListingEmpty extends AreaPluginBase { /** * The access manager. * - * @var \Drupal\Core\Access\AccessManager + * @var \Drupal\Core\Access\AccessManagerInterface */ protected $accessManager; @@ -36,10 +36,10 @@ class ListingEmpty extends AreaPluginBase { * The plugin ID for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. - * @param \Drupal\Core\Access\AccessManager $access_manager + * @param \Drupal\Core\Access\AccessManagerInterface $access_manager * The access manager. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, AccessManager $access_manager) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, AccessManagerInterface $access_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->accessManager = $access_manager; diff --git a/core/modules/rest/src/Plugin/ResourceBase.php b/core/modules/rest/src/Plugin/ResourceBase.php index 54308fc2e0d5..cab3b59b7fd4 100644 --- a/core/modules/rest/src/Plugin/ResourceBase.php +++ b/core/modules/rest/src/Plugin/ResourceBase.php @@ -7,6 +7,7 @@ namespace Drupal\rest\Plugin; +use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\PluginBase; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -194,7 +195,7 @@ protected function getBaseRoute($canonical_path, $method) { '_method' => $method, '_permission' => "restful $lower_method $this->pluginId", ), array( - '_access_mode' => 'ANY', + '_access_mode' => AccessManagerInterface::ACCESS_MODE_ANY, )); return $route; } diff --git a/core/modules/system/src/Form/ModulesListForm.php b/core/modules/system/src/Form/ModulesListForm.php index da1ecd05bbc7..e25070f9f570 100644 --- a/core/modules/system/src/Form/ModulesListForm.php +++ b/core/modules/system/src/Form/ModulesListForm.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\String; use Drupal\Component\Utility\Unicode; +use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Entity\Query\QueryFactoryInterface; @@ -20,7 +21,6 @@ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -use Drupal\Core\Access\AccessManager; /** * Provides module installation interface. @@ -96,7 +96,7 @@ public static function create(ContainerInterface $container) { * The module handler. * @param \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface $key_value_expirable * The key value expirable factory. - * @param \Drupal\Core\Access\AccessManager $access_manager + * @param \Drupal\Core\Access\AccessManagerInterface $access_manager * Access manager. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. @@ -107,7 +107,7 @@ public static function create(ContainerInterface $container) { * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The current route match. */ - public function __construct(ModuleHandlerInterface $module_handler, KeyValueStoreExpirableInterface $key_value_expirable, AccessManager $access_manager, EntityManagerInterface $entity_manager, QueryFactory $query_factory, AccountInterface $current_user, RouteMatchInterface $route_match) { + public function __construct(ModuleHandlerInterface $module_handler, KeyValueStoreExpirableInterface $key_value_expirable, AccessManagerInterface $access_manager, EntityManagerInterface $entity_manager, QueryFactory $query_factory, AccountInterface $current_user, RouteMatchInterface $route_match) { $this->moduleHandler = $module_handler; $this->keyValueExpirable = $key_value_expirable; $this->accessManager = $access_manager; diff --git a/core/modules/system/src/PathBasedBreadcrumbBuilder.php b/core/modules/system/src/PathBasedBreadcrumbBuilder.php index 68bf38bb78ea..c2765aa02bce 100644 --- a/core/modules/system/src/PathBasedBreadcrumbBuilder.php +++ b/core/modules/system/src/PathBasedBreadcrumbBuilder.php @@ -7,10 +7,10 @@ namespace Drupal\system; +use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Controller\TitleResolverInterface; -use Drupal\Core\Access\AccessManager; use Drupal\Core\ParamConverter\ParamNotConvertedException; use Drupal\Core\PathProcessor\InboundPathProcessorInterface; use Drupal\Core\Routing\RouteMatchInterface; @@ -42,7 +42,7 @@ class PathBasedBreadcrumbBuilder implements BreadcrumbBuilderInterface { /** * The menu link access service. * - * @var \Drupal\Core\Access\AccessManager + * @var \Drupal\Core\Access\AccessManagerInterface */ protected $accessManager; @@ -86,7 +86,7 @@ class PathBasedBreadcrumbBuilder implements BreadcrumbBuilderInterface { * * @param \Symfony\Component\Routing\RequestContext $context * The router request context. - * @param \Drupal\Core\Access\AccessManager $access_manager + * @param \Drupal\Core\Access\AccessManagerInterface $access_manager * The menu link access service. * @param \Symfony\Component\Routing\Matcher\RequestMatcherInterface $router * The dynamic router service. @@ -99,7 +99,7 @@ class PathBasedBreadcrumbBuilder implements BreadcrumbBuilderInterface { * @param \Drupal\Core\Session\AccountInterface $current_user * The current user object. */ - public function __construct(RequestContext $context, AccessManager $access_manager, RequestMatcherInterface $router, InboundPathProcessorInterface $path_processor, ConfigFactoryInterface $config_factory, TitleResolverInterface $title_resolver, AccountInterface $current_user) { + public function __construct(RequestContext $context, AccessManagerInterface $access_manager, RequestMatcherInterface $router, InboundPathProcessorInterface $path_processor, ConfigFactoryInterface $config_factory, TitleResolverInterface $title_resolver, AccountInterface $current_user) { $this->context = $context; $this->accessManager = $access_manager; $this->router = $router; diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 117dc49a7fd4..fc2c63f84ccf 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1508,7 +1508,7 @@ function system_get_module_admin_tasks($module, array $info) { // Append link for permissions. if (\Drupal::moduleHandler()->implementsHook($module, 'permission')) { - /** @var \Drupal\Core\Access\AccessManager $access_manager */ + /** @var \Drupal\Core\Access\AccessManagerInterface $access_manager */ $access_manager = \Drupal::service('access_manager'); /** @var \Drupal\menu_link\MenuLinkStorageInterface $menu_link_storage */ $menu_link_storage = \Drupal::entityManager() diff --git a/core/modules/system/tests/src/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php b/core/modules/system/tests/src/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php index 81edaa28ecaa..4d12b9ec84fc 100644 --- a/core/modules/system/tests/src/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php +++ b/core/modules/system/tests/src/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php @@ -41,7 +41,7 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase { /** * The mocked access manager. * - * @var \Drupal\Core\Access\AccessManager|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Access\AccessManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $accessManager; @@ -95,8 +95,7 @@ public function setUp() { $this->pathProcessor = $this->getMock('\Drupal\Core\PathProcessor\InboundPathProcessorInterface'); $this->context = $this->getMock('\Symfony\Component\Routing\RequestContext'); - $this->accessManager = $this->getMockBuilder('\Drupal\Core\Access\AccessManager') - ->disableOriginalConstructor()->getMock(); + $this->accessManager = $this->getMock('\Drupal\Core\Access\AccessManagerInterface'); $this->titleResolver = $this->getMock('\Drupal\Core\Controller\TitleResolverInterface'); $this->currentUser = $this->getMock('Drupal\Core\Session\AccountInterface'); $this->builder = new TestPathBasedBreadcrumbBuilder( diff --git a/core/modules/views/src/Plugin/views/display/PathPluginBase.php b/core/modules/views/src/Plugin/views/display/PathPluginBase.php index 44127ec061b8..45756785a5e9 100644 --- a/core/modules/views/src/Plugin/views/display/PathPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/PathPluginBase.php @@ -7,6 +7,7 @@ namespace Drupal\views\Plugin\views\display; +use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Form\FormErrorInterface; use Drupal\Core\State\StateInterface; use Drupal\Core\Routing\RouteCompiler; @@ -206,7 +207,7 @@ protected function getRoute($view_id, $display_id) { $access_plugin->alterRouteDefinition($route); // @todo Figure out whether _access_mode ANY is the proper one. This is // particular important for altering routes. - $route->setOption('_access_mode', 'ANY'); + $route->setOption('_access_mode', AccessManagerInterface::ACCESS_MODE_ANY); // Set the argument map, in order to support named parameters. $route->setOption('_view_argument_map', $argument_map); diff --git a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php index 5508fe0e2fb7..2c657216b04e 100644 --- a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php @@ -8,6 +8,7 @@ namespace Drupal\Tests\Core\Access; use Drupal\Core\Access\AccessCheckInterface; +use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Routing\Access\AccessInterface; use Drupal\Core\Access\AccessManager; use Drupal\Core\Access\DefaultAccessCheck; @@ -229,7 +230,7 @@ public function testCheck() { public function providerTestCheckConjunctions() { $access_configurations = array(); $access_configurations[] = array( - 'conjunction' => 'ALL', + 'conjunction' => AccessManagerInterface::ACCESS_MODE_ALL, 'name' => 'test_route_4', 'condition_one' => AccessCheckInterface::ALLOW, 'condition_two' => AccessCheckInterface::KILL, @@ -243,7 +244,7 @@ public function providerTestCheckConjunctions() { 'expected' => FALSE, ); $access_configurations[] = array( - 'conjunction' => 'ALL', + 'conjunction' => AccessManagerInterface::ACCESS_MODE_ALL, 'name' => 'test_route_5', 'condition_one' => AccessCheckInterface::ALLOW, 'condition_two' => AccessCheckInterface::DENY, @@ -257,7 +258,7 @@ public function providerTestCheckConjunctions() { 'expected' => FALSE, ); $access_configurations[] = array( - 'conjunction' => 'ALL', + 'conjunction' => AccessManagerInterface::ACCESS_MODE_ALL, 'name' => 'test_route_6', 'condition_one' => AccessCheckInterface::KILL, 'condition_two' => AccessCheckInterface::DENY, @@ -271,7 +272,7 @@ public function providerTestCheckConjunctions() { 'expected' => FALSE, ); $access_configurations[] = array( - 'conjunction' => 'ALL', + 'conjunction' => AccessManagerInterface::ACCESS_MODE_ALL, 'name' => 'test_route_7', 'condition_one' => AccessCheckInterface::ALLOW, 'condition_two' => AccessCheckInterface::ALLOW, @@ -285,7 +286,7 @@ public function providerTestCheckConjunctions() { 'expected' => TRUE, ); $access_configurations[] = array( - 'conjunction' => 'ALL', + 'conjunction' => AccessManagerInterface::ACCESS_MODE_ALL, 'name' => 'test_route_8', 'condition_one' => AccessCheckInterface::KILL, 'condition_two' => AccessCheckInterface::KILL, @@ -299,7 +300,7 @@ public function providerTestCheckConjunctions() { 'expected' => FALSE, ); $access_configurations[] = array( - 'conjunction' => 'ALL', + 'conjunction' => AccessManagerInterface::ACCESS_MODE_ALL, 'name' => 'test_route_9', 'condition_one' => AccessCheckInterface::DENY, 'condition_two' => AccessCheckInterface::DENY, @@ -313,42 +314,42 @@ public function providerTestCheckConjunctions() { 'expected' => FALSE, ); $access_configurations[] = array( - 'conjunction' => 'ANY', + 'conjunction' => AccessManagerInterface::ACCESS_MODE_ANY, 'name' => 'test_route_10', 'condition_one' => AccessCheckInterface::ALLOW, 'condition_two' => AccessCheckInterface::KILL, 'expected' => FALSE, ); $access_configurations[] = array( - 'conjunction' => 'ANY', + 'conjunction' => AccessManagerInterface::ACCESS_MODE_ANY, 'name' => 'test_route_11', 'condition_one' => AccessCheckInterface::ALLOW, 'condition_two' => AccessCheckInterface::DENY, 'expected' => TRUE, ); $access_configurations[] = array( - 'conjunction' => 'ANY', + 'conjunction' => AccessManagerInterface::ACCESS_MODE_ANY, 'name' => 'test_route_12', 'condition_one' => AccessCheckInterface::KILL, 'condition_two' => AccessCheckInterface::DENY, 'expected' => FALSE, ); $access_configurations[] = array( - 'conjunction' => 'ANY', + 'conjunction' => AccessManagerInterface::ACCESS_MODE_ANY, 'name' => 'test_route_13', 'condition_one' => AccessCheckInterface::ALLOW, 'condition_two' => AccessCheckInterface::ALLOW, 'expected' => TRUE, ); $access_configurations[] = array( - 'conjunction' => 'ANY', + 'conjunction' => AccessManagerInterface::ACCESS_MODE_ANY, 'name' => 'test_route_14', 'condition_one' => AccessCheckInterface::KILL, 'condition_two' => AccessCheckInterface::KILL, 'expected' => FALSE, ); $access_configurations[] = array( - 'conjunction' => 'ANY', + 'conjunction' => AccessManagerInterface::ACCESS_MODE_ANY, 'name' => 'test_route_15', 'condition_one' => AccessCheckInterface::DENY, 'condition_two' => AccessCheckInterface::DENY, @@ -609,16 +610,16 @@ public function testCheckException($return_value, $access_mode) { */ public function providerCheckException() { return array( - array(array(), 'ALL'), - array(array(), 'ANY'), - array(array(1), 'ALL'), - array(array(1), 'ANY'), - array('string', 'ALL'), - array('string', 'ANY'), - array(0, 'ALL'), - array(0, 'ANY'), - array(1, 'ALL'), - array(1, 'ANY'), + array(array(), AccessManagerInterface::ACCESS_MODE_ALL), + array(array(), AccessManagerInterface::ACCESS_MODE_ANY), + array(array(1), AccessManagerInterface::ACCESS_MODE_ALL), + array(array(1), AccessManagerInterface::ACCESS_MODE_ANY), + array('string', AccessManagerInterface::ACCESS_MODE_ALL), + array('string', AccessManagerInterface::ACCESS_MODE_ANY), + array(0, AccessManagerInterface::ACCESS_MODE_ALL), + array(0, AccessManagerInterface::ACCESS_MODE_ANY), + array(1, AccessManagerInterface::ACCESS_MODE_ALL), + array(1, AccessManagerInterface::ACCESS_MODE_ANY), ); } diff --git a/core/tests/Drupal/Tests/Core/Access/CsrfAccessCheckTest.php b/core/tests/Drupal/Tests/Core/Access/CsrfAccessCheckTest.php index a4319db8b968..3501b87a0e60 100644 --- a/core/tests/Drupal/Tests/Core/Access/CsrfAccessCheckTest.php +++ b/core/tests/Drupal/Tests/Core/Access/CsrfAccessCheckTest.php @@ -7,6 +7,7 @@ namespace Drupal\Tests\Core\Access; +use Drupal\Core\Access\AccessManagerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; use Drupal\Core\Access\CsrfAccessCheck; @@ -89,7 +90,9 @@ public function testAccessTokenFail() { /** * Tests the access() method with no _controller_request attribute set. * - * This will default to the 'ANY' access conjunction. + * This will default to the AccessManagerInterface::ACCESS_MODE_ANY access conjunction. + * + * @see Drupal\Core\Access\AccessManagerInterface::ACCESS_MODE_ANY */ public function testAccessTokenMissAny() { $this->csrfToken->expects($this->never()) @@ -106,13 +109,15 @@ public function testAccessTokenMissAny() { /** * Tests the access() method with no _controller_request attribute set. * - * This will use the 'ALL' access conjunction. + * This will use the AccessManagerInterface::ACCESS_MODE_ALL access conjunction. + * + * @see Drupal\Core\Access\AccessManagerInterface::ACCESS_MODE_ALL */ public function testAccessTokenMissAll() { $this->csrfToken->expects($this->never()) ->method('validate'); - $route = new Route('/test-path', array(), array('_csrf_token' => 'TRUE'), array('_access_mode' => 'ALL')); + $route = new Route('/test-path', array(), array('_csrf_token' => 'TRUE'), array('_access_mode' => AccessManagerInterface::ACCESS_MODE_ALL)); $request = new Request(array( 'token' => 'test_query', )); diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/AccessSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/AccessSubscriberTest.php index 46022ea7fcfa..2d23bc433532 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/AccessSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/AccessSubscriberTest.php @@ -7,7 +7,6 @@ namespace Drupal\Tests\Core\EventSubscriber; -use Drupal\Core\Access\AccessManager; use Drupal\Core\EventSubscriber\AccessSubscriber; use Drupal\Core\Session\AccountInterface; use Drupal\Tests\UnitTestCase; @@ -46,7 +45,7 @@ class AccessSubscriberTest extends UnitTestCase { protected $route; /** - * @var Drupal\Core\Access\AccessManager|PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Access\AccessManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $accessManager; @@ -81,9 +80,7 @@ public function setUp() { ->method('getRequest') ->will($this->returnValue($this->request)); - $this->accessManager = $this->getMockBuilder('Drupal\Core\Access\AccessManager') - ->disableOriginalConstructor() - ->getMock(); + $this->accessManager = $this->getMock('Drupal\Core\Access\AccessManagerInterface'); $this->currentUser = $this->getMockBuilder('Drupal\Core\Session\AccountInterface') ->disableOriginalConstructor() diff --git a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php index 0858c1400320..edd14ecf57ca 100644 --- a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php @@ -62,7 +62,7 @@ class ContextualLinkManagerTest extends UnitTestCase { /** * The mocked access manager. * - * @var \Drupal\Core\Access\AccessManager|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Access\AccessManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $accessManager; @@ -78,9 +78,7 @@ protected function setUp() { $this->factory = $this->getMock('Drupal\Component\Plugin\Factory\FactoryInterface'); $this->cacheBackend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); $this->moduleHandler = $this->getMock('\Drupal\Core\Extension\ModuleHandlerInterface'); - $this->accessManager = $this->getMockBuilder('Drupal\Core\Access\AccessManager') - ->disableOriginalConstructor() - ->getMock(); + $this->accessManager = $this->getMock('Drupal\Core\Access\AccessManagerInterface'); $this->account = $this->getMock('Drupal\Core\Session\AccountInterface'); $property = new \ReflectionProperty('Drupal\Core\Menu\ContextualLinkManager', 'controllerResolver'); diff --git a/core/tests/Drupal/Tests/Core/Menu/DefaultMenuLinkTreeManipulatorsTest.php b/core/tests/Drupal/Tests/Core/Menu/DefaultMenuLinkTreeManipulatorsTest.php index c2308ddea337..4309a4ef5315 100644 --- a/core/tests/Drupal/Tests/Core/Menu/DefaultMenuLinkTreeManipulatorsTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/DefaultMenuLinkTreeManipulatorsTest.php @@ -23,7 +23,7 @@ class DefaultMenuLinkTreeManipulatorsTest extends UnitTestCase { /** * The mocked access manager. * - * @var \Drupal\Core\Access\AccessManager|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Access\AccessManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $accessManager; @@ -61,8 +61,7 @@ class DefaultMenuLinkTreeManipulatorsTest extends UnitTestCase { protected function setUp() { parent::setUp(); - $this->accessManager = $this->getMockBuilder('\Drupal\Core\Access\AccessManager') - ->disableOriginalConstructor()->getMock(); + $this->accessManager = $this->getMock('\Drupal\Core\Access\AccessManagerInterface'); $this->currentUser = $this->getMock('Drupal\Core\Session\AccountInterface'); $this->defaultMenuTreeManipulators = new DefaultMenuLinkTreeManipulators($this->accessManager, $this->currentUser); diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php index 0f67a1d70388..f92711ad0949 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php @@ -9,7 +9,7 @@ use Drupal\Component\Plugin\Discovery\DiscoveryInterface; use Drupal\Component\Plugin\Factory\FactoryInterface; -use Drupal\Core\Access\AccessManager; +use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\Language; @@ -65,7 +65,7 @@ class LocalActionManagerTest extends UnitTestCase { /** * The mocked access manager. * - * @var \Drupal\Core\Access\AccessManager|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Access\AccessManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $accessManager; @@ -107,9 +107,7 @@ protected function setUp() { $this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); $this->cacheBackend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); - $this->accessManager = $this->getMockBuilder('Drupal\Core\Access\AccessManager') - ->disableOriginalConstructor() - ->getMock(); + $this->accessManager = $this->getMock('Drupal\Core\Access\AccessManagerInterface'); $this->account = $this->getMock('Drupal\Core\Session\AccountInterface'); $this->discovery = $this->getMock('Drupal\Component\Plugin\Discovery\DiscoveryInterface'); $this->factory = $this->getMock('Drupal\Component\Plugin\Factory\FactoryInterface'); @@ -343,7 +341,7 @@ public function getActionsForRouteProvider() { class TestLocalActionManager extends LocalActionManager { - public function __construct(ControllerResolverInterface $controller_resolver, Request $request, RouteProviderInterface $route_provider, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend, AccessManager $access_manager, AccountInterface $account, DiscoveryInterface $discovery, FactoryInterface $factory) { + public function __construct(ControllerResolverInterface $controller_resolver, Request $request, RouteProviderInterface $route_provider, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend, AccessManagerInterface $access_manager, AccountInterface $account, DiscoveryInterface $discovery, FactoryInterface $factory) { $this->discovery = $discovery; $this->factory = $factory; $this->routeProvider = $route_provider; diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskIntegrationTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskIntegrationTest.php index 1a176f6dcb34..0c337c7188c7 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskIntegrationTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskIntegrationTest.php @@ -79,9 +79,8 @@ protected function getLocalTaskManager($module_dirs, $route_name, $route_params) $property->setAccessible(TRUE); $property->setValue($manager, $request_stack); - $accessManager = $this->getMockBuilder('Drupal\Core\Access\AccessManager') - ->disableOriginalConstructor() - ->getMock(); $property = new \ReflectionProperty('Drupal\Core\Menu\LocalTaskManager', 'accessManager'); + $accessManager = $this->getMock('Drupal\Core\Access\AccessManagerInterface'); + $property = new \ReflectionProperty('Drupal\Core\Menu\LocalTaskManager', 'accessManager'); $property->setAccessible(TRUE); $property->setValue($manager, $accessManager); diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php index 5966e51696e8..c1dba2ed6f88 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php @@ -79,7 +79,7 @@ class LocalTaskManagerTest extends UnitTestCase { /** * The mocked access manager. * - * @var \Drupal\Core\Access\AccessManager|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Access\AccessManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $accessManager; @@ -96,9 +96,7 @@ protected function setUp() { $this->pluginDiscovery = $this->getMock('Drupal\Component\Plugin\Discovery\DiscoveryInterface'); $this->factory = $this->getMock('Drupal\Component\Plugin\Factory\FactoryInterface'); $this->cacheBackend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); - $this->accessManager = $this->getMockBuilder('Drupal\Core\Access\AccessManager') - ->disableOriginalConstructor() - ->getMock(); + $this->accessManager = $this->getMock('Drupal\Core\Access\AccessManagerInterface'); $this->setupLocalTaskManager(); } -- GitLab