Commit 34efb126 authored by alexpott's avatar alexpott

Issue #2419649 by plach, David Latapie: Content translation schema updates are...

Issue #2419649 by plach, David Latapie: Content translation schema updates are not triggered consistently
parent 5f5fa3b7
...@@ -293,6 +293,10 @@ function content_translation_form_language_content_settings_submit(array $form, ...@@ -293,6 +293,10 @@ function content_translation_form_language_content_settings_submit(array $form,
$entity_types = $form_state->getValue('entity_types'); $entity_types = $form_state->getValue('entity_types');
$settings = &$form_state->getValue('settings'); $settings = &$form_state->getValue('settings');
// Ensure entity and menu router information are correctly rebuilt.
\Drupal::entityManager()->clearCachedDefinitions();
\Drupal::service('router.builder_indicator')->setRebuildNeeded();
// If an entity type is not translatable all its bundles and fields must be // 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 // marked as non-translatable. Similarly, if a bundle is made non-translatable
// all of its fields will be not translatable. // all of its fields will be not translatable.
...@@ -340,9 +344,4 @@ function content_translation_form_language_content_settings_submit(array $form, ...@@ -340,9 +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_indicator')->setRebuildNeeded();
\Drupal::service('content_translation.updates_manager')->updateDefinitions($entity_types);
} }
...@@ -23,7 +23,7 @@ services: ...@@ -23,7 +23,7 @@ services:
content_translation.manager: content_translation.manager:
class: Drupal\content_translation\ContentTranslationManager class: Drupal\content_translation\ContentTranslationManager
arguments: ['@entity.manager'] arguments: ['@entity.manager', '@content_translation.updates_manager']
content_translation.updates_manager: content_translation.updates_manager:
class: Drupal\content_translation\ContentTranslationUpdatesManager class: Drupal\content_translation\ContentTranslationUpdatesManager
......
...@@ -24,14 +24,24 @@ class ContentTranslationManager implements ContentTranslationManagerInterface { ...@@ -24,14 +24,24 @@ class ContentTranslationManager implements ContentTranslationManagerInterface {
*/ */
protected $entityManager; protected $entityManager;
/**
* The updates manager.
*
* @var \Drupal\content_translation\ContentTranslationUpdatesManager
*/
protected $updatesManager;
/** /**
* Constructs a ContentTranslationManageAccessCheck object. * Constructs a ContentTranslationManageAccessCheck object.
* *
* @param \Drupal\Core\Entity\EntityManagerInterface $manager * @param \Drupal\Core\Entity\EntityManagerInterface $manager
* The entity type manager. * The entity type manager.
* @param \Drupal\content_translation\ContentTranslationUpdatesManager $updates_manager
* The updates manager.
*/ */
public function __construct(EntityManagerInterface $manager) { public function __construct(EntityManagerInterface $manager, ContentTranslationUpdatesManager $updates_manager) {
$this->entityManager = $manager; $this->entityManager = $manager;
$this->updatesManager = $updates_manager;
} }
/** /**
...@@ -78,6 +88,8 @@ public function getSupportedEntityTypes() { ...@@ -78,6 +88,8 @@ public function getSupportedEntityTypes() {
public function setEnabled($entity_type_id, $bundle, $value) { public function setEnabled($entity_type_id, $bundle, $value) {
$config = $this->loadContentLanguageSettings($entity_type_id, $bundle); $config = $this->loadContentLanguageSettings($entity_type_id, $bundle);
$config->setThirdPartySetting('content_translation', 'enabled', $value)->save(); $config->setThirdPartySetting('content_translation', 'enabled', $value)->save();
$entity_type = $this->entityManager->getDefinition($entity_type_id);
$this->updatesManager->updateDefinitions(array($entity_type_id => $entity_type));
} }
/** /**
......
<?php
/**
* @file
* Contains Drupal\content_translation\Tests\ContentTranslationSettingsApiTest.
*/
namespace Drupal\content_translation\Tests;
use Drupal\simpletest\KernelTestBase;
/**
* Tests the content translation settings API.
*
* @group content_translation
*/
class ContentTranslationSettingsApiTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('language', 'content_translation', 'user', 'entity_test');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('entity_test_mul');
}
/**
* Tests that enabling translation via the API triggers schema updates.
*/
function testSettingsApi() {
$this->container->get('content_translation.manager')->setEnabled('entity_test_mul', 'entity_test_mul', TRUE);
$result =
db_field_exists('entity_test_mul_property_data', 'content_translation_source') &&
db_field_exists('entity_test_mul_property_data', 'content_translation_outdated');
$this->assertTrue($result, 'Schema updates correctly performed.');
}
}
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