Commit bd01bba5 authored by webchick's avatar webchick

Issue #2155665 by Wim Leers | yched: Update field_valid_language() calls in edit.module.

parent 5e4fb4fc
......@@ -88,7 +88,7 @@ protected function validateAndUpcastRequestAttributes(Request $request) {
throw new NotFoundHttpException();
}
$langcode = $request->attributes->get('langcode');
if (!$langcode || (field_valid_language($langcode) !== $langcode)) {
if (!$langcode || !$entity->hasTranslation($langcode)) {
throw new NotFoundHttpException();
}
}
......
......@@ -149,7 +149,7 @@ public function metadata(Request $request) {
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();
}
......
......@@ -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 @@ public function testAccess(EntityInterface $entity, FieldInterface $field = NULL
->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 @@ public function testAccessWithNotPassedLanguage() {
* @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 @@ protected function createMockEntity() {
}
}
}
// @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';
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment