Commit bc1fc2f7 authored by effulgentsia's avatar effulgentsia
Browse files

Issue #2939909 by plach, xjm, Wim Leers: Ensure that hook_bundle_info_alter()...

Issue #2939909 by plach, xjm, Wim Leers: Ensure that hook_bundle_info_alter() implementations know whether bundles are translatable
parent cc2c9555
......@@ -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;
}
}
......
......@@ -7,6 +7,15 @@
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_entity_bundle_info_alter().
*/
function content_translation_test_entity_bundle_info_alter(&$bundles) {
// Store the initial status of the "translatable" property for the
// "entity_test_mul" bundle.
\Drupal::state()->set('content_translation_test.translatable', !empty($bundles['entity_test_mul']['entity_test_mul']['translatable']));
}
/**
* Implements hook_form_BASE_FORM_ID_alter().
*
......
<?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', '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();
// Verify that the test module comes first in the module list, which would
// normally make its hook implementation to be invoked first.
/** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */
$module_handler = $this->container->get('module_handler');
$module_list = $module_handler->getModuleList();
$expected_modules = [
'content_translation_test',
'content_translation',
];
$actual_modules = array_keys(array_intersect_key($module_list, array_flip($expected_modules)));
$this->assertEquals($expected_modules, $actual_modules);
// Check that the "content_translation_test" hook implementation has access
// to the "translatable" bundle info property.
/** @var \Drupal\Core\State\StateInterface $state */
$state = $this->container->get('state');
$this->assertTrue($state->get('content_translation_test.translatable'));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment