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

Issue #2408439 by zuuperman, askibinski: Language / Translation settings are...

Issue #2408439 by zuuperman, askibinski: Language / Translation settings are not saved when adding a new bundle
parent 112ed4ff
Branches
Tags
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
...@@ -433,7 +433,8 @@ function content_translation_language_configuration_element_process(array $eleme ...@@ -433,7 +433,8 @@ function content_translation_language_configuration_element_process(array $eleme
'#prefix' => '<label>' . t('Translation') . '</label>', '#prefix' => '<label>' . t('Translation') . '</label>',
); );
$form['actions']['submit']['#submit'][] = 'content_translation_language_configuration_element_submit'; $submit_name = isset($form['actions']['save_continue']) ? 'save_continue' : 'submit';
$form['actions'][$submit_name]['#submit'][] = 'content_translation_language_configuration_element_submit';
} }
return $element; return $element;
} }
......
...@@ -38,6 +38,19 @@ public function testContentTypeUI() { ...@@ -38,6 +38,19 @@ public function testContentTypeUI() {
// content type. // content type.
$this->drupalGet('admin/structure/types/add'); $this->drupalGet('admin/structure/types/add');
$this->assertNoFieldChecked('edit-language-configuration-content-translation'); $this->assertNoFieldChecked('edit-language-configuration-content-translation');
// Create second content type and set content translation.
$edit = array(
'name' => 'Page',
'type' => 'page',
'language_configuration[content_translation]' => TRUE,
);
$this->drupalPostForm('admin/structure/types/add', $edit, 'Save and manage fields');
// Make sure the settings are saved when creating the content type.
$this->drupalGet('admin/structure/types/manage/page');
$this->assertFieldChecked('edit-language-configuration-content-translation');
} }
} }
...@@ -209,17 +209,21 @@ function language_configuration_element_submit(&$form, FormStateInterface $form_ ...@@ -209,17 +209,21 @@ function language_configuration_element_submit(&$form, FormStateInterface $form_
$entity_type_id = $values['entity_type']; $entity_type_id = $values['entity_type'];
$bundle = $values['bundle']; $bundle = $values['bundle'];
$form_object = $form_state->getFormObject(); $form_object = $form_state->getFormObject();
if ($form_object instanceof EntityFormInterface && !$form_object->getEntity()->isNew() && in_array($form_object->getOperation(), ['default', 'edit'])) { if ($form_object instanceof EntityFormInterface) {
/** @var EntityFormInterface $form_object */ /** @var EntityFormInterface $form_object */
$entity = $form_object->getEntity(); $entity = $form_object->getEntity();
if ($entity->getEntityType()->getBundleOf()) { if ($entity->getEntityType()->getBundleOf()) {
$bundle = $entity->id(); $bundle = $entity->id();
$language[$element_name]['bundle'] = $bundle;
} }
} }
$config = ContentLanguageSettings::loadByEntityTypeBundle($entity_type_id, $bundle); $config = ContentLanguageSettings::loadByEntityTypeBundle($entity_type_id, $bundle);
$config->setDefaultLangcode($form_state->getValue(array($element_name, 'langcode'))); $config->setDefaultLangcode($form_state->getValue(array($element_name, 'langcode')));
$config->setLanguageAlterable($form_state->getValue(array($element_name, 'language_alterable'))); $config->setLanguageAlterable($form_state->getValue(array($element_name, 'language_alterable')));
$config->save(); $config->save();
// Set the form_state languaged with the updated bundle.
$form_state->set('language', $language);
} }
} }
} }
......
...@@ -77,8 +77,9 @@ public static function processLanguageConfiguration(&$element, FormStateInterfac ...@@ -77,8 +77,9 @@ public static function processLanguageConfiguration(&$element, FormStateInterfac
// handler. // handler.
// @todo Form API: Allow form widgets/sections to declare #submit // @todo Form API: Allow form widgets/sections to declare #submit
// handlers. // handlers.
if (isset($form['actions']['submit']['#submit']) && array_search('language_configuration_element_submit', $form['actions']['submit']['#submit']) === FALSE) { $submit_name = isset($form['actions']['save_continue']) ? 'save_continue' : 'submit';
$form['actions']['submit']['#submit'][] = 'language_configuration_element_submit'; if (isset($form['actions'][$submit_name]['#submit']) && array_search('language_configuration_element_submit', $form['actions'][$submit_name]['#submit']) === FALSE) {
$form['actions'][$submit_name]['#submit'][] = 'language_configuration_element_submit';
} }
elseif (array_search('language_configuration_element_submit', $form['#submit']) === FALSE) { elseif (array_search('language_configuration_element_submit', $form['#submit']) === FALSE) {
$form['#submit'][] = 'language_configuration_element_submit'; $form['#submit'][] = 'language_configuration_element_submit';
......
...@@ -24,7 +24,13 @@ class LanguageConfigurationElementTest extends WebTestBase { ...@@ -24,7 +24,13 @@ class LanguageConfigurationElementTest extends WebTestBase {
* *
* @var array * @var array
*/ */
public static $modules = array('taxonomy', 'node', 'language', 'language_elements_test'); public static $modules = array('taxonomy', 'node', 'language', 'language_elements_test', 'field_ui');
protected function setUp() {
parent::setUp();
$user = $this->drupalCreateUser(array('access administration pages', 'administer languages', 'administer content types'));
$this->drupalLogin($user);
}
/** /**
* Tests the language settings have been saved. * Tests the language settings have been saved.
...@@ -56,6 +62,21 @@ public function testLanguageConfigurationElement() { ...@@ -56,6 +62,21 @@ public function testLanguageConfigurationElement() {
$this->drupalGet('language-tests/language_configuration_element'); $this->drupalGet('language-tests/language_configuration_element');
$this->assertOptionSelected('edit-lang-configuration-langcode', 'authors_default'); $this->assertOptionSelected('edit-lang-configuration-langcode', 'authors_default');
$this->assertFieldChecked('edit-lang-configuration-language-alterable'); $this->assertFieldChecked('edit-lang-configuration-language-alterable');
// Test if content type settings have been saved.
$edit = array(
'name' => 'Page',
'type' => 'page',
'language_configuration[langcode]' => 'authors_default',
'language_configuration[language_alterable]' => TRUE,
);
$this->drupalPostForm('admin/structure/types/add', $edit, 'Save and manage fields');
// Make sure the settings are saved when creating the content type.
$this->drupalGet('admin/structure/types/manage/page');
$this->assertOptionSelected('edit-language-configuration-langcode', 'authors_default');
$this->assertFieldChecked('edit-language-configuration-language-alterable');
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment