diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 48feccc6cd252b72ada4d346fe79ff63e6685b5a..b7bd079dcc345d67c754af2cc0dd212521cc1180 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -60,6 +60,14 @@ function content_translation_module_implements_alter(&$implementations, $hook) { unset($implementations['content_translation']); $implementations['content_translation'] = $group; break; + + // Move our hook_entity_bundle_info_alter() implementation to the top of the + // list, so that any other hook implementation can rely on bundles being + // correctly marked as translatable. + case 'entity_bundle_info_alter': + $group = $implementations['content_translation']; + $implementations = ['content_translation' => $group] + $implementations; + break; } } diff --git a/core/modules/content_translation/tests/modules/a_content_translation_test/a_content_translation_test.info.yml b/core/modules/content_translation/tests/modules/a_content_translation_test/a_content_translation_test.info.yml new file mode 100644 index 0000000000000000000000000000000000000000..f2df57c31cb18615e2a063eb08c69278c3bf6d8a --- /dev/null +++ b/core/modules/content_translation/tests/modules/a_content_translation_test/a_content_translation_test.info.yml @@ -0,0 +1,10 @@ +name: 'A content translation test module' +type: module +description: 'Helper module to test hook invocation order.' +package: Testing +version: VERSION +core: 8.x +dependencies: + - content_translation + - entity_test + diff --git a/core/modules/content_translation/tests/modules/a_content_translation_test/a_content_translation_test.module b/core/modules/content_translation/tests/modules/a_content_translation_test/a_content_translation_test.module new file mode 100644 index 0000000000000000000000000000000000000000..b89e16037aec6076cd3ce2bcf7d635579854037a --- /dev/null +++ b/core/modules/content_translation/tests/modules/a_content_translation_test/a_content_translation_test.module @@ -0,0 +1,13 @@ +<?php + +/** + * @file + * Helper module for the Content Translation tests. + */ + +/** + * Implements hook_entity_bundle_info_alter(). + */ +function a_content_translation_test_entity_bundle_info_alter(&$bundles) { + \Drupal::state()->set('a_content_translation_test.translatable', !empty($bundles['entity_test_mul']['entity_test_mul']['translatable'])); +} diff --git a/core/modules/content_translation/tests/src/Kernel/ContentTranslationEntityBundleInfoTest.php b/core/modules/content_translation/tests/src/Kernel/ContentTranslationEntityBundleInfoTest.php new file mode 100644 index 0000000000000000000000000000000000000000..1fa3a91c8bce8ed329e73a28bf3ad379f24b9667 --- /dev/null +++ b/core/modules/content_translation/tests/src/Kernel/ContentTranslationEntityBundleInfoTest.php @@ -0,0 +1,61 @@ +<?php + +namespace Drupal\Tests\content_translation\Kernel; + +use Drupal\KernelTests\KernelTestBase; + +/** + * Tests the Content Translation bundle info logic. + * + * @group content_translation + */ +class ContentTranslationEntityBundleInfoTest extends KernelTestBase { + + /** + * {@inheritdoc} + */ + public static $modules = ['user', 'language', 'a_content_translation_test', 'content_translation', 'entity_test']; + + /** + * The content translation manager. + * + * @var \Drupal\content_translation\ContentTranslationManagerInterface + */ + protected $contentTranslationManager; + + /** + * The bundle info service. + * + * @var \Drupal\Core\Entity\EntityTypeBundleInfo + */ + protected $bundleInfo; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + + $this->contentTranslationManager = $this->container->get('content_translation.manager'); + $this->bundleInfo = $this->container->get('entity_type.bundle.info'); + + $this->installEntitySchema('entity_test_mul'); + } + + /** + * Tests that modules can know whether bundles are translatable. + */ + public function testHookInvocationOrder() { + $this->contentTranslationManager->setEnabled('entity_test_mul', 'entity_test_mul', TRUE); + $this->bundleInfo->clearCachedBundles(); + $this->bundleInfo->getAllBundleInfo(); + + // Check that, although the "a_content_translation_test" hook implementation + // by default would be invoked first, it still has access to the + // "translatable" bundle info property. + /** @var \Drupal\Core\State\StateInterface $state */ + $state = $this->container->get('state'); + $this->assertTrue($state->get('a_content_translation_test.translatable')); + } + +}