Issue #2155665 by Wim Leers | yched: Update field_valid_language() calls in edit.module.
parent
5e4fb4fcd5
commit
bd01bba52c
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue