diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index 2f3bc0a..f529e4d 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -293,6 +293,10 @@ function content_translation_form_language_content_settings_submit(array $form, $entity_types = $form_state->getValue('entity_types'); $settings = &$form_state->getValue('settings'); + // Ensure entity and menu router information are correctly rebuilt. + \Drupal::entityManager()->clearCachedDefinitions(); + \Drupal::service('router.builder')->setRebuildNeeded(); + // If an entity type is not translatable all its bundles and fields must be // marked as non-translatable. Similarly, if a bundle is made non-translatable // all of its fields will be not translatable. @@ -340,8 +344,4 @@ function content_translation_form_language_content_settings_submit(array $form, } } } - // Ensure entity and menu router information are correctly rebuilt. - \Drupal::entityManager()->clearCachedDefinitions(); - \Drupal::service('router.builder')->setRebuildNeeded(); - } diff --git a/core/modules/content_translation/src/Tests/ContentTranslationContextualLinksTest.php b/core/modules/content_translation/src/Tests/ContentTranslationContextualLinksTest.php index 36a0d20..196fa25 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationContextualLinksTest.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationContextualLinksTest.php @@ -9,6 +9,7 @@ use Drupal\Component\Serialization\Json; use Drupal\language\Entity\ConfigurableLanguage; +use Drupal\language\Entity\ContentLanguageSettings; use Drupal\node\Entity\NodeType; use Drupal\simpletest\WebTestBase; @@ -71,14 +72,20 @@ protected function setUp() { $this->bundle = $this->randomMachineName(); $this->contentType = $this->drupalCreateContentType(array('type' => $this->bundle)); - // Add a field to the content type. This will be made translatable by the - // test through the UI. This is important because it tests that caches are - // cleared as expected when doing this. + // Enable translation for the current entity type and ensure the change is + // picked up. + \Drupal::service('content_translation.manager')->setEnabled('node', $this->bundle, TRUE); + drupal_static_reset(); + \Drupal::entityManager()->clearCachedBundles(); + \Drupal::service('router.builder')->rebuild(); + + // Add a translatable field to the content type. entity_create('field_storage_config', array( 'field_name' => 'field_test_text', 'entity_type' => 'node', 'type' => 'text', 'cardinality' => 1, + 'translatable' => TRUE, ))->save(); entity_create('field_config', array( 'entity_type' => 'node', @@ -93,6 +100,11 @@ protected function setUp() { )) ->save(); + // Enable content translation. + ContentLanguageSettings::loadByEntityTypeBundle('node', $this->bundle) + ->setLanguageAlterable(TRUE) + ->setDefaultLangcode(\Drupal::languageManager()->getDefaultLanguage()->getId()) + ->save(); // Create a translator user. $permissions = array( 'access contextual links', @@ -112,17 +124,6 @@ public function testContentTranslationContextualLinks() { $this->drupalCreateNode(array('type' => $this->bundle, 'title' => $title, 'langcode' => 'en')); $node = $this->drupalGetNodeByTitle($title); - // Set up the node type and field to be translatable through the UI. - $this->drupalLogin($this->rootUser); - $edit = array( - 'entity_types[node]' => TRUE, - 'settings[node][' . $this->bundle . '][settings][language][language_alterable]' => TRUE, - 'settings[node][' . $this->bundle . '][translatable]' => TRUE, - 'settings[node][' . $this->bundle . '][fields][field_test_text]' => TRUE, - ); - $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration')); - $this->drupalLogout(); - // Check that the translate link appears on the node page. $this->drupalLogin($this->translator); $translate_link = 'node/' . $node->id() . '/translations';