Commit bd1964cb authored by alexpott's avatar alexpott

Issue #2533964 by edurenye, Berdir, Gábor Hojtsy: Langcode widget visibility...

Issue #2533964 by edurenye, Berdir, Gábor Hojtsy: Langcode widget visibility settings from language.module are not applied consistently
parent 1569740d
......@@ -29,7 +29,8 @@
* admin_permission = "administer contact forms",
* entity_keys = {
* "bundle" = "contact_form",
* "uuid" = "uuid"
* "uuid" = "uuid",
* "langcode" = "langcode"
* },
* bundle_entity_type = "contact_form",
* field_ui_base_route = "entity.contact_form.edit_form",
......
<?php
/**
* @file
* Contains \Drupal\contact\Tests\ContactLanguageTest.
*/
namespace Drupal\contact\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests contact messages with language module.
*
* This is to ensure that a contact form by default does not show the language
* select, but it does so when it's enabled from the content language settings
* page.
*
* @group contact
*/
class ContactLanguageTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array(
'contact',
'language',
'contact_test',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create and login administrative user.
$admin_user = $this->drupalCreateUser(array(
'access site-wide contact form',
'administer languages',
));
$this->drupalLogin($admin_user);
}
/**
* Tests configuration options with language enabled.
*/
public function testContactLanguage() {
// Ensure that contact form by default does not show the language select.
$this->drupalGet('contact');
$this->assertResponse(200, 'The page exists');
$this->assertNoField('edit-langcode-0-value');
// Enable language select from content language settings page.
$settings_path = 'admin/config/regional/content-language';
$edit['entity_types[contact_message]'] = TRUE;
$edit['settings[contact_message][feedback][settings][language][language_alterable]'] = TRUE;
$this->drupalPostForm($settings_path, $edit, t('Save configuration'));
// Ensure that contact form now shows the language select.
$this->drupalGet('contact');
$this->assertResponse(200, 'The page exists');
$this->assertField('edit-langcode-0-value');
}
}
......@@ -427,12 +427,12 @@ function language_form_alter(&$form, FormStateInterface $form_state) {
// Content entity forms may have added a langcode field. But content language
// configuration should decide if it should be exposed or not in the forms.
$form_object = $form_state->getFormObject();
if ($form_object instanceof ContentEntityFormInterface) {
if ($form_object instanceof ContentEntityFormInterface && $form_object->getEntity()->getEntityType()->hasKey('langcode')) {
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $form_object->getEntity();
$entity_type = $entity->getEntityType();
$langcode_key = $entity_type->getKey('langcode');
if (isset($form[$langcode_key]) && $entity_type->isTranslatable()) {
if (isset($form[$langcode_key])) {
$language_configuration = ContentLanguageSettings::loadByEntityTypeBundle($entity->getEntityTypeId(), $entity->bundle());
$form[$langcode_key]['#access'] = $language_configuration->isLanguageAlterable();
}
......
<?php
/**
* @file
* Contains \Drupal\language\Tests\EntityTypeWithoutLanguageFormTest.
*/
namespace Drupal\language\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests entity type without language support.
*
* This is to ensure that an entity type without language support can not
* enable the language select from the content language settings page.
*
* @group language
*/
class EntityTypeWithoutLanguageFormTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array(
'language',
'language_test',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create and login administrative user.
$admin_user = $this->drupalCreateUser(array(
'administer languages',
));
$this->drupalLogin($admin_user);
}
/**
* Tests configuration options with an entity without language definition.
*/
public function testEmptyLangcode() {
// Assert that we can not enable language select from
// content language settings page.
$this->drupalGet('admin/config/regional/content-language');
$this->assertNoField('entity_types[no_language_entity_test]');
}
}
<?php
/**
* @file
* Contains \Drupal\language_test\Entity\NoLanguageEntityTest.
*/
namespace Drupal\language_test\Entity;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
/**
* Defines the test entity class.
*
* @ContentEntityType(
* id = "no_language_entity_test",
* label = @Translation("Test entity without language support"),
* base_table = "no_language_entity_test",
* persistent_cache = FALSE,
* entity_keys = {
* "id" = "id",
* "uuid" = "uuid",
* },
* )
*/
class NoLanguageEntityTest extends ContentEntityBase {
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('ID'))
->setDescription(t('The ID of the test entity.'))
->setReadOnly(TRUE)
->setSetting('unsigned', TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The UUID of the test entity.'))
->setReadOnly(TRUE);
return $fields;
}
}
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