Unverified Commit efefc923 authored by alexpott's avatar alexpott

Issue #3017812 by ibustos, joachim: Language selector is immune to...

Issue #3017812 by ibustos, joachim: Language selector is immune to hook_entity_field_access in entity forms

(cherry picked from commit f6674fa4)
parent c66a0b71
......@@ -381,7 +381,7 @@ function language_form_alter(&$form, FormStateInterface $form_state) {
$entity = $form_object->getEntity();
$entity_type = $entity->getEntityType();
$langcode_key = $entity_type->getKey('langcode');
if (isset($form[$langcode_key])) {
if (isset($form[$langcode_key]) && $form[$langcode_key]['#access'] !== FALSE) {
$language_configuration = ContentLanguageSettings::loadByEntityTypeBundle($entity->getEntityTypeId(), $entity->bundle());
$form[$langcode_key]['#access'] = $language_configuration->isLanguageAlterable();
}
......
langcode: en
status: true
dependencies:
config:
- node.type.page
id: node.page
target_entity_type_id: node
target_bundle: page
default_langcode: site_default
language_alterable: true
langcode: en
status: true
dependencies: { }
name: page
type: page
description: ''
help: ''
new_revision: false
preview_mode: 1
display_submitted: false
name: 'Language entity field access test'
type: module
description: 'Support module for verifying entity field access and the language selector.'
core: 8.x
package: Testing
version: VERSION
dependencies:
- drupal:node
- drupal:text
- drupal:field
- drupal:filter
- drupal:language
<?php
/**
* @file
* Hook implementations for language_entity_field_access_test.
*/
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Session\AccountInterface;
/**
* Implements hook_entity_field_access().
*/
function language_entity_field_access_test_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
return AccessResult::forbidden();
}
<?php
namespace Drupal\Tests\language\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests language picker compatibility with hook_entity_field_access.
*
* @group language
*/
class LanguageEntityFieldAccessHookTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'node',
'text',
'field',
'filter',
'language',
'language_entity_field_access_test',
];
/**
* Tests compatibility with hook_entity_field_access().
*/
public function testHookEntityFieldAccess() {
// Create an admin user and do the login.
$user = $this->drupalCreateUser([], NULL, TRUE);
$this->drupalLogin($user);
// Assess the field is not visible.
$this->drupalGet('node/add/page');
$this->assertSession()->fieldNotExists('langcode[0][value]');
$this->drupalLogout();
}
}
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