diff -u b/core/modules/edit/lib/Drupal/edit/Access/EditEntityFieldAccessCheck.php b/core/modules/edit/lib/Drupal/edit/Access/EditEntityFieldAccessCheck.php --- b/core/modules/edit/lib/Drupal/edit/Access/EditEntityFieldAccessCheck.php +++ b/core/modules/edit/lib/Drupal/edit/Access/EditEntityFieldAccessCheck.php @@ -13,7 +13,6 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Drupal\Core\Entity\EntityInterface; -use Drupal\field\FieldInfo; use Drupal\Core\Entity\EntityManager; /** @@ -29,23 +28,13 @@ protected $entityManager; /** - * The field info. - * - * @var \Drupal\field\FieldInfo - */ - protected $fieldInfo; - - /** * Constructs a EditEntityFieldAccessCheck object. * * @param \Drupal\Core\Entity\EntityManager $entity_manager * The entity manager. - * @param \Drupal\field\FieldInfo $field_info - * The field info. */ - public function __construct(EntityManager $entity_manager, FieldInfo $field_info) { + public function __construct(EntityManager $entity_manager) { $this->entityManager = $entity_manager; - $this->fieldInfo = $field_info; } /** @@ -94,14 +83,11 @@ // Validate the field name and language. $field_name = $request->attributes->get('field_name'); - if (!$field_name) { + if (!$field_name || !$entity->getPropertyDefinition($field_name)) { throw new NotFoundHttpException(); } $langcode = $request->attributes->get('langcode'); - if (!$langcode || (field_valid_language($langcode) !== $langcode) || !$entity->hasTranslation($langcode)) { - throw new NotFoundHttpException(); - } - if (!($field_definition = $entity->getTranslation($langcode)->get($field_name)->getFieldDefinition())) { + if (!$langcode || (field_valid_language($langcode) !== $langcode)) { throw new NotFoundHttpException(); } } only in patch2: unchanged: --- a/core/modules/edit/edit.services.yml +++ b/core/modules/edit/edit.services.yml @@ -4,7 +4,7 @@ services: arguments: ['@container.namespaces'] access_check.edit.entity_field: class: Drupal\edit\Access\EditEntityFieldAccessCheck - arguments: ['@entity.manager', '@field.info'] + arguments: ['@entity.manager'] tags: - { name: access_check } access_check.edit.entity: only in patch2: unchanged: --- a/core/modules/edit/tests/Drupal/edit/Tests/Access/EditEntityFieldAccessCheckTest.php +++ b/core/modules/edit/tests/Drupal/edit/Tests/Access/EditEntityFieldAccessCheckTest.php @@ -41,13 +41,6 @@ class EditEntityFieldAccessCheckTest extends UnitTestCase { protected $entityManager; /** - * The mocked field info. - * - * @var \Drupal\field\FieldInfo|\PHPUnit_Framework_MockObject_MockObject - */ - protected $fieldInfo; - - /** * The mocked entity storage controller. * * @var \Drupal\Core\Entity\EntityStorageControllerInterface|\PHPUnit_Framework_MockObject_MockObject @@ -73,11 +66,7 @@ protected function setUp() { ->method('getStorageController') ->will($this->returnValue($this->entityStorageController)); - $this->fieldInfo = $this->getMockBuilder('Drupal\field\FieldInfo') - ->disableOriginalConstructor() - ->getMock(); - - $this->editAccessCheck = new EditEntityFieldAccessCheck($this->entityManager, $this->fieldInfo); + $this->editAccessCheck = new EditEntityFieldAccessCheck($this->entityManager); } /** @@ -149,6 +138,12 @@ public function testAccess(EntityInterface $entity, FieldInterface $field = NULL $entity_with_field->expects($this->any()) ->method('get') ->will($this->returnValue($field)); + $entity_with_field->expects($this->any()) + ->method('getPropertyDefinition') + ->with('example') + ->will($this->returnValue(array( + 'field_name' => 'example', + ))); // Prepare the request to be valid. $request->attributes->set('entity', $entity_with_field); @@ -156,14 +151,6 @@ public function testAccess(EntityInterface $entity, FieldInterface $field = NULL $request->attributes->set('field_name', 'example'); $request->attributes->set('langcode', Language::LANGCODE_NOT_SPECIFIED); - $this->fieldInfo->expects($this->any()) - ->method('getInstance') - ->will($this->returnValue(array( - 'example' => array( - 'field_name' => 'example', - ) - ))); - $access = $this->editAccessCheck->access($route, $request); $this->assertSame($expected_result, $access); } @@ -243,20 +230,13 @@ public function testAccessWithNonExistingField() { ->disableOriginalConstructor() ->getMock(); $entity->expects($this->any()) - ->method('entityType') - ->will($this->returnValue('entity_test')); - $entity->expects($this->any()) - ->method('bundle') - ->will($this->returnValue('test_bundle')); + ->method('getPropertyDefinition') + ->with('not_valid') + ->will($this->returnValue(FALSE)); $request->attributes->set('entity', $entity); $request->attributes->set('field_name', 'not_valid'); - $this->fieldInfo->expects($this->once()) - ->method('getInstance') - ->with('entity_test', 'test_bundle', 'not_valid') - ->will($this->returnValue(NULL)); - $this->editAccessCheck->access($route, $request); } @@ -273,6 +253,12 @@ public function testAccessWithNotPassedLanguage() { $entity = $this->getMockBuilder('Drupal\entity_test\Entity\EntityTest') ->disableOriginalConstructor() ->getMock(); + $entity->expects($this->any()) + ->method('getPropertyDefinition') + ->with('valid') + ->will($this->returnValue(array( + 'field_name' => 'valid', + ))); $request->attributes->set('entity', $entity); $request->attributes->set('field_name', 'valid'); @@ -281,10 +267,6 @@ public function testAccessWithNotPassedLanguage() { ->disableOriginalConstructor() ->getMock(); - $this->fieldInfo->expects($this->once()) - ->method('getInstance') - ->will($this->returnValue($field)); - $this->editAccessCheck->access($route, $request); } @@ -301,6 +283,12 @@ public function testAccessWithInvalidLanguage() { $entity = $this->getMockBuilder('Drupal\entity_test\Entity\EntityTest') ->disableOriginalConstructor() ->getMock(); + $entity->expects($this->any()) + ->method('getPropertyDefinition') + ->with('valid') + ->will($this->returnValue(array( + 'field_name' => 'valid', + ))); $request->attributes->set('entity', $entity); $request->attributes->set('field_name', 'valid'); @@ -310,10 +298,6 @@ public function testAccessWithInvalidLanguage() { ->disableOriginalConstructor() ->getMock(); - $this->fieldInfo->expects($this->once()) - ->method('getInstance') - ->will($this->returnValue($field)); - $this->editAccessCheck->access($route, $request); }