diff --git a/core/modules/language/language.module b/core/modules/language/language.module index 00b92c3..46ee053 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -7,6 +7,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Entity\ContentEntityType; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityForm; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; @@ -16,7 +17,6 @@ use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrlFallback; -use Drupal\node\NodeTypeInterface; /** * Implements hook_help(). @@ -185,9 +185,7 @@ function language_configuration_element_submit(&$form, FormStateInterface $form_ $entityType = $values['entity_type']; $bundle = $values['bundle']; // In case we are editing a bundle, we must check the new bundle name, - // because e.g. language_node_type_update fired before. - // A way of checking if the form is an edit form is checking for the - // delete action presence. + // because e.g. hook_ENTITY_update fired before. $form_object = $form_state->getFormObject(); if ($form_object instanceof EntityForm && $form_object->getOperation() === 'edit') { /** @var EntityForm $form_object */ @@ -277,14 +275,12 @@ function language_clear_default_configuration($entity_type, $bundle) { } /** - * Implements hook_ENTITY_TYPE_update() for node_type entities. + * Implements hook_entity_bundle_rename(). */ -function language_node_type_update(NodeTypeInterface $type) { - if ($type->getOriginalId() != $type->id()) { - $config = ContentLanguageSettings::loadByEntityTypeBundle('node', $type->getOriginalId()); - $config->setTargetBundle($type->id()); - $config->save(); - } +function language_entity_bundle_rename($entity_type_id, $bundle_old, $bundle_new) { + $config = ContentLanguageSettings::loadByEntityTypeBundle($entity_type_id, $bundle_old); + $config->setTargetBundle($bundle_new); + $config->save(); } /** diff --git a/core/modules/language/src/Tests/LanguageConfigurationElementTest.php b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php index e736066..2a3b75b 100644 --- a/core/modules/language/src/Tests/LanguageConfigurationElementTest.php +++ b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php @@ -24,7 +24,7 @@ class LanguageConfigurationElementTest extends WebTestBase { * * @var array */ - public static $modules = array('node', 'language', 'language_elements_test'); + public static $modules = array('taxonomy', 'node', 'language', 'language_elements_test'); /** * Tests the language settings have been saved. @@ -143,4 +143,38 @@ public function testNodeTypeUpdate() { $this->assertEqual($configuration, array('langcode' => 'current_interface', 'language_alterable' => TRUE), 'The default language configuration has been kept on the new Article content type.'); $this->assertEqual(ContentLanguageSettings::loadByEntityTypeBundle('node', 'article_2')->uuid(), $uuid, 'The language configuration uuid has been kept on the new Article content type.'); } + + /** + * Tests that the configuration is updated when a vocabulary is changed. + */ + public function testTaxonomyVocabularyUpdate() { + $vocabulary = entity_create('taxonomy_vocabulary', array( + 'name' => 'Country', + 'vid' => 'country', + )); + $vocabulary->save(); + + $admin_user = $this->drupalCreateUser(array('administer taxonomy')); + $this->drupalLogin($admin_user); + $edit = array( + 'default_language[langcode]' => 'current_interface', + 'default_language[language_alterable]' => TRUE, + ); + $this->drupalPostForm('admin/structure/taxonomy/manage/country', $edit, t('Save')); + + // Check the language default configuration . + $configuration = language_get_default_configuration('taxonomy_term', 'country'); + $uuid = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', 'country')->uuid(); + $this->assertEqual($configuration, array('langcode' => 'current_interface', 'language_alterable' => TRUE), 'The default language configuration has been saved on the Country vocabulary.'); + // Rename the vocabulary. + $edit = array( + 'vid' => 'nation' + ); + $this->drupalPostForm('admin/structure/taxonomy/manage/country', $edit, t('Save')); + // Check that we still have the settings for the new vocabulary. + $configuration = language_get_default_configuration('taxonomy_term', 'nation'); + $this->assertEqual($configuration, array('langcode' => 'current_interface', 'language_alterable' => TRUE), 'The default language configuration has been kept on the new Country vocabulary.'); + $this->assertEqual(ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', 'nation')->uuid(), $uuid, 'The language configuration uuid has been kept on the new Country vocabulary.'); + } + } diff --git a/core/modules/taxonomy/src/Entity/Vocabulary.php b/core/modules/taxonomy/src/Entity/Vocabulary.php index e650551..b783383 100644 --- a/core/modules/taxonomy/src/Entity/Vocabulary.php +++ b/core/modules/taxonomy/src/Entity/Vocabulary.php @@ -23,6 +23,7 @@ * "list_builder" = "Drupal\taxonomy\VocabularyListBuilder", * "form" = { * "default" = "Drupal\taxonomy\VocabularyForm", + * "edit" = "Drupal\taxonomy\VocabularyForm", * "reset" = "Drupal\taxonomy\Form\VocabularyResetForm", * "delete" = "Drupal\taxonomy\Form\VocabularyDeleteForm" * } diff --git a/core/modules/taxonomy/src/VocabularyForm.php b/core/modules/taxonomy/src/VocabularyForm.php index 42f8a76..08bf93b 100644 --- a/core/modules/taxonomy/src/VocabularyForm.php +++ b/core/modules/taxonomy/src/VocabularyForm.php @@ -93,12 +93,6 @@ protected function actions(array $form, FormStateInterface $form_state) { // If we are displaying the delete confirmation skip the regular actions. if (!$form_state->get('confirm_delete')) { $actions = parent::actions($form, $form_state); - // Add the language configuration submit handler. This is needed because - // the submit button has custom submit handlers. - if ($this->moduleHandler->moduleExists('language')) { - $actions['submit']['#submit'][] = 'language_configuration_element_submit'; - array_unshift($actions['submit']['#submit'], '::languageConfigurationSubmit'); - } // We cannot leverage the regular submit handler definition because we // have button-specific ones here. Hence we need to explicitly set it for // the submit action, otherwise it would be ignored. @@ -113,22 +107,6 @@ protected function actions(array $form, FormStateInterface $form_state) { } /** - * Submit handler to update the bundle for the default language configuration. - */ - public function languageConfigurationSubmit(array &$form, FormStateInterface $form_state) { - $vocabulary = $this->entity; - // Delete the old language settings for the vocabulary, if the machine name - // is changed. - if ($vocabulary && $vocabulary->id() && $vocabulary->id() != $form_state->getValue('vid')) { - language_clear_default_configuration('taxonomy_term', $vocabulary->id()); - } - // Since the machine name is not known yet, and it can be changed anytime, - // we have to also update the bundle property for the default language - // configuration in order to have the correct bundle value. - $form_state->set(['language', 'default_language', 'bundle'], $form_state->getValue('vid')); - } - - /** * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { diff --git a/core/modules/taxonomy/taxonomy.routing.yml b/core/modules/taxonomy/taxonomy.routing.yml index 6fa970f..8eb35ea 100644 --- a/core/modules/taxonomy/taxonomy.routing.yml +++ b/core/modules/taxonomy/taxonomy.routing.yml @@ -45,7 +45,7 @@ entity.taxonomy_vocabulary.add_form: entity.taxonomy_vocabulary.edit_form: path: '/admin/structure/taxonomy/manage/{taxonomy_vocabulary}' defaults: - _entity_form: 'taxonomy_vocabulary.default' + _entity_form: 'taxonomy_vocabulary.edit' _title_callback: '\Drupal\taxonomy\Controller\TaxonomyController::vocabularyTitle' requirements: _entity_access: 'taxonomy_vocabulary.update'