Commit f1766f96 authored by alexpott's avatar alexpott

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
......@@ -433,7 +433,8 @@ function content_translation_language_configuration_element_process(array $eleme
'#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;
}
......
......@@ -38,6 +38,19 @@ public function testContentTypeUI() {
// content type.
$this->drupalGet('admin/structure/types/add');
$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_
$entity_type_id = $values['entity_type'];
$bundle = $values['bundle'];
$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 */
$entity = $form_object->getEntity();
if ($entity->getEntityType()->getBundleOf()) {
$bundle = $entity->id();
$language[$element_name]['bundle'] = $bundle;
}
}
$config = ContentLanguageSettings::loadByEntityTypeBundle($entity_type_id, $bundle);
$config->setDefaultLangcode($form_state->getValue(array($element_name, 'langcode')));
$config->setLanguageAlterable($form_state->getValue(array($element_name, 'language_alterable')));
$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
// handler.
// @todo Form API: Allow form widgets/sections to declare #submit
// handlers.
if (isset($form['actions']['submit']['#submit']) && array_search('language_configuration_element_submit', $form['actions']['submit']['#submit']) === FALSE) {
$form['actions']['submit']['#submit'][] = 'language_configuration_element_submit';
$submit_name = isset($form['actions']['save_continue']) ? 'save_continue' : '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) {
$form['#submit'][] = 'language_configuration_element_submit';
......
......@@ -24,7 +24,13 @@ class LanguageConfigurationElementTest extends WebTestBase {
*
* @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.
......@@ -56,6 +62,21 @@ public function testLanguageConfigurationElement() {
$this->drupalGet('language-tests/language_configuration_element');
$this->assertOptionSelected('edit-lang-configuration-langcode', 'authors_default');
$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');
}
/**
......
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