Skip to content
Snippets Groups Projects
Unverified Commit f6674fa4 authored by Alex Pott's avatar Alex Pott
Browse files

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
parent 6429dc64
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment