diff --git a/core/modules/edit/lib/Drupal/edit/Access/EditEntityFieldAccessCheck.php b/core/modules/edit/lib/Drupal/edit/Access/EditEntityFieldAccessCheck.php index 2c5dd92bcce..2dbfc45c733 100644 --- a/core/modules/edit/lib/Drupal/edit/Access/EditEntityFieldAccessCheck.php +++ b/core/modules/edit/lib/Drupal/edit/Access/EditEntityFieldAccessCheck.php @@ -88,7 +88,7 @@ class EditEntityFieldAccessCheck implements StaticAccessCheckInterface, EditEnti throw new NotFoundHttpException(); } $langcode = $request->attributes->get('langcode'); - if (!$langcode || (field_valid_language($langcode) !== $langcode)) { + if (!$langcode || !$entity->hasTranslation($langcode)) { throw new NotFoundHttpException(); } } diff --git a/core/modules/edit/lib/Drupal/edit/EditController.php b/core/modules/edit/lib/Drupal/edit/EditController.php index 412c16a7d96..2c140416bcf 100644 --- a/core/modules/edit/lib/Drupal/edit/EditController.php +++ b/core/modules/edit/lib/Drupal/edit/EditController.php @@ -149,7 +149,7 @@ class EditController extends ContainerAware implements ContainerInjectionInterfa if (!$field_name || !$entity->hasField($field_name)) { throw new NotFoundHttpException(); } - if (!$langcode || (field_valid_language($langcode) !== $langcode)) { + if (!$langcode || !$entity->hasTranslation($langcode)) { throw new NotFoundHttpException(); } diff --git a/core/modules/edit/tests/Drupal/edit/Tests/Access/EditEntityFieldAccessCheckTest.php b/core/modules/edit/tests/Drupal/edit/Tests/Access/EditEntityFieldAccessCheckTest.php index a7451483448..ba2e038f2af 100644 --- a/core/modules/edit/tests/Drupal/edit/Tests/Access/EditEntityFieldAccessCheckTest.php +++ b/core/modules/edit/tests/Drupal/edit/Tests/Access/EditEntityFieldAccessCheckTest.php @@ -5,7 +5,7 @@ * Contains \Drupal\edit\Tests\Access\EditEntityFieldAccessCheckTest. */ -namespace Drupal\edit\Tests\Access { +namespace Drupal\edit\Tests\Access; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; @@ -133,6 +133,10 @@ class EditEntityFieldAccessCheckTest extends UnitTestCase { ->method('get') ->with('valid') ->will($this->returnValue($field)); + $entity_with_field->expects($this->once()) + ->method('hasTranslation') + ->with(Language::LANGCODE_NOT_SPECIFIED) + ->will($this->returnValue(TRUE)); // Prepare the request to be valid. $request->attributes->set('entity_type', 'test_entity'); @@ -242,10 +246,16 @@ class EditEntityFieldAccessCheckTest extends UnitTestCase { * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ public function testAccessWithInvalidLanguage() { + $entity = $this->createMockEntity(); + $entity->expects($this->once()) + ->method('hasTranslation') + ->with('xx-lolspeak') + ->will($this->returnValue(FALSE)); + $route = new Route('/edit/form/test_entity/1/body/und/full', array(), array('_access_edit_entity_field' => 'TRUE')); $request = new Request(); $request->attributes->set('entity_type', 'entity_test'); - $request->attributes->set('entity', $this->createMockEntity()); + $request->attributes->set('entity', $entity); $request->attributes->set('field_name', 'valid'); $request->attributes->set('langcode', 'xx-lolspeak'); @@ -272,18 +282,3 @@ class EditEntityFieldAccessCheckTest extends UnitTestCase { } } - -} - -// @todo remove once field_access() and field_valid_language() can be injected. -namespace { - - use Drupal\Core\Language\Language; - - if (!function_exists('field_valid_language')) { - function field_valid_language($langcode, $default = TRUE) { - return $langcode == Language::LANGCODE_NOT_SPECIFIED ? Language::LANGCODE_NOT_SPECIFIED : 'en'; - } - } - -}