diff --git a/core/modules/language/language.module b/core/modules/language/language.module index 67356bea2c5..5b2099e29a5 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -237,6 +237,17 @@ function language_entity_bundle_rename($entity_type_id, $bundle_old, $bundle_new ->save(); } +/** + * Implements hook_entity_bundle_delete(). + */ +function language_entity_bundle_delete($entity_type_id, $bundle) { + // Remove the content language settings associated with the bundle. + $settings = ContentLanguageSettings::loadByEntityTypeBundle($entity_type_id, $bundle); + if (!$settings->isNew()) { + $settings->delete(); + } +} + /** * Returns the default language code assigned to an entity type and a bundle. * diff --git a/core/modules/language/src/Tests/LanguageConfigurationElementTest.php b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php index 59e03987dc5..f4e1378b729 100644 --- a/core/modules/language/src/Tests/LanguageConfigurationElementTest.php +++ b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php @@ -184,6 +184,41 @@ class LanguageConfigurationElementTest extends WebTestBase { $this->assertEqual($configuration->uuid(), $uuid, 'The language configuration uuid has been kept on the new Article content type.'); } + /** + * Tests the language settings are deleted on bundle delete. + */ + public function testNodeTypeDelete() { + // Create the article content type first if the profile used is not the + // standard one. + if ($this->profile != 'standard') { + $this->drupalCreateContentType(array( + 'type' => 'article', + 'name' => 'Article' + )); + } + $admin_user = $this->drupalCreateUser(array('administer content types')); + $this->drupalLogin($admin_user); + + // Create language configuration for the articles. + $edit = array( + 'language_configuration[langcode]' => 'authors_default', + 'language_configuration[language_alterable]' => TRUE, + ); + $this->drupalPostForm('admin/structure/types/manage/article', $edit, t('Save content type')); + + // Check the language default configuration for articles is present. + $configuration = \Drupal::entityManager()->getStorage('language_content_settings')->load('node.article'); + $this->assertTrue($configuration, 'The language configuration is present.'); + + // Delete 'article' bundle. + $this->drupalPostForm('admin/structure/types/manage/article/delete', array(), t('Delete')); + + // Check that the language configuration has been deleted. + \Drupal::entityManager()->getStorage('language_content_settings')->resetCache(); + $configuration = \Drupal::entityManager()->getStorage('language_content_settings')->load('node.article'); + $this->assertFalse($configuration, 'The language configuration was deleted after bundle was deleted.'); + } + /** * Tests that the configuration is updated when a vocabulary is changed. */