diff --git a/core/modules/language/language.module b/core/modules/language/language.module index f196969..83c6d5b 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -267,6 +267,8 @@ function language_configuration_element_process($element, &$form_state, &$form) if (!isset($form_state['language'])) { $form_state['language'] = array(); } + // @todo On bundle create $element['#entity_information']['bundle'] is empty. + // http://drupal.org/node/2015615 $form_state['language'] += array( $element['#name'] => array( 'entity_type' => $element['#entity_information']['entity_type'], @@ -349,7 +351,7 @@ function language_get_default_configuration($entity_type, $bundle) { * A string representing the bundle. */ function language_clear_default_configuration($entity_type, $bundle) { - \Drupal::config('language.settings')->clear(language_get_default_configuration_settings_key($entity_type, $bundle))->save(); + \Drupal::config('language.settings')->clear(language_get_default_configuration_bundle_key($entity_type, $bundle))->save(); } /** @@ -367,10 +369,26 @@ function language_clear_default_configuration($entity_type, $bundle) { * The root name of the variables. */ function language_get_default_configuration_settings_key($entity_type, $bundle) { - // Replace all the characters that are not letters, numbers or "_" with "_". + return language_get_default_configuration_bundle_key($entity_type, $bundle) . '.language.default_configuration'; +} + +/** + * Returns the bundle name part of variables used to store the configuration. + * + * Replace all the characters that are not letters, numbers or "_" with "_". + * + * @param string $entity_type + * A string representing the entity type. + * @param string $bundle + * A string representing the bundle. + * + * @return string + * The bundle name part of the variables. + */ +function language_get_default_configuration_bundle_key($entity_type, $bundle) { $entity_type = preg_replace('/[^0-9a-zA-Z_]/', "_", $entity_type); $bundle = preg_replace('/[^0-9a-zA-Z_]/', "_", $bundle); - return $entity_type . '.' . $bundle . '.language.default_configuration'; + return $entity_type . '.' . $bundle; } /** @@ -384,6 +402,13 @@ function language_node_type_update(NodeTypeInterface $type) { } /** + * Implements hook_entity_bundle_delete(). + */ +function language_entity_bundle_delete($entity_type, $bundle) { + language_clear_default_configuration($entity_type, $bundle); +} + +/** * Returns the default language code assigned to an entity type and a bundle. * * @param string $entity_type diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationElementTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationElementTest.php index adab4ca..9cb7971 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationElementTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationElementTest.php @@ -137,4 +137,30 @@ public function testNodeTypeUpdate() { $configuration = language_get_default_configuration('node', 'article_2'); $this->assertEqual($configuration, array('langcode' => 'current_interface', 'language_show' => TRUE), 'The default language configuration has been kept on the new Article content type.'); } + + /** + * Tests the language setting are deleted from config file on bundle delete. + */ + public function testLanguageConfigurationElementDelete() { + $this->drupalGet('language-tests/language_configuration_element'); + $edit['lang_configuration[langcode]'] = 'current_interface'; + $edit['lang_configuration[language_show]'] = FALSE; + $this->drupalPostForm(NULL, $edit, t('Save')); + $lang_conf = language_get_default_configuration('some_custom_type', 'some_bundle'); + + // Check that the settings have been saved. + $this->assertEqual($lang_conf['langcode'], 'current_interface'); + $this->assertFalse($lang_conf['language_show']); + $this->drupalGet('language-tests/language_configuration_element'); + $this->assertOptionSelected('edit-lang-configuration-langcode', 'current_interface'); + $this->assertNoFieldChecked('edit-lang-configuration-language-show'); + + // Delete the bundle. + // ... how? + + // Check that the settings have been deleted. + $settings = \Drupal::config('language.settings')->get(language_get_default_configuration_settings_key('some_custom_type', 'some_bundle')); + $this->assertNull($settings, 'The old settings were deleted.'); + } + }