diff --git a/core/lib/Drupal/Core/Entity/EntityAccessCheck.php b/core/lib/Drupal/Core/Entity/EntityAccessCheck.php index 029d6e1..ec85c70 100644 --- a/core/lib/Drupal/Core/Entity/EntityAccessCheck.php +++ b/core/lib/Drupal/Core/Entity/EntityAccessCheck.php @@ -7,10 +7,11 @@ namespace Drupal\Core\Entity; -use Drupal\Core\Access\AccessCheckInterface; +use Drupal\Core\TypedData\AccessibleInterface; use Drupal\Core\Entity\EntityInterface; use Symfony\Component\Routing\Route; use Symfony\Component\HttpFoundation\Request; +use Drupal\Core\Access\AccessCheckInterface; /** * Provides a generic access checker for entities. @@ -37,17 +38,19 @@ public function applies(Route $route) { * @endcode */ public function access(Route $route, Request $request) { - $requirements = $route->getRequirements(); // Split the slug and the operation. - list($slug, $operation) = $route->getRequirement('_entity_access'); - + $requirement = $route->getRequirement('_entity_access'); + list($slug, $operation) = explode('.', $requirement); // If this slug is in the request, and it is an entity, check its access. if ($request->attributes->has($slug)) { $entity = $request->attributes->get($slug); - if ($entity instanceof EntityInterface) { + if ($entity instanceof AccessibleInterface) { return $entity->access($operation); } } + // No opinion, so other access checks should decide if access should be + // allowed or not. + return NULL; } } diff --git a/core/modules/system/tests/modules/entity_test/entity_test.routing.yml b/core/modules/system/tests/modules/entity_test/entity_test.routing.yml deleted file mode 100644 index 8088f69..0000000 --- a/core/modules/system/tests/modules/entity_test/entity_test.routing.yml +++ /dev/null @@ -1,6 +0,0 @@ -entity_test_access: - pattern: '/entity_test/{entity_test}/delete' - defaults: - _content: 'Drupal\entity_test\Controller\EntityTestController::deletePage' - requirements: - _entity_access: 'entity_test.delete' diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityAccessCheckTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityAccessCheckTest.php index 2510c45..85b9347 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityAccessCheckTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityAccessCheckTest.php @@ -11,6 +11,7 @@ use Symfony\Component\Routing\Route; use Drupal\Core\Entity\EntityAccessCheck; use Drupal\Tests\UnitTestCase; +use Drupal\node\Plugin\Core\Entity\Node; /** * Tests the entity access controller. @@ -56,12 +57,17 @@ public function testApplies() { * Tests the method for checking access to routes. */ public function testAccess() { - $route = new Route('/foo', array(), array('_entity_access: node.update')); - $request = new Request; - $request->attributes = 'node'; + $route = new Route('/foo', array(), array('_entity_access' => 'node.update')); + $request = new Request(); + $node = $this->getMockBuilder('Drupal\node\Plugin\Core\Entity\Node') + ->disableOriginalConstructor() + ->getMock(); + $node->expects($this->any()) + ->method('access') + ->will($this->returnValue(TRUE)); $access_check = new EntityAccessCheck(); + $request->attributes->set('node', $node); $access = $access_check->access($route, $request); $this->assertEquals(TRUE, $access); } } -