Issue #1935762 by plach: Remove entity_load_unchanged() call from FieldTranslationSynchronizer::synchronizeFields().
parent
8da0812745
commit
1b3d229a93
|
@ -8,12 +8,30 @@
|
|||
namespace Drupal\translation_entity;
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityManager;
|
||||
|
||||
/**
|
||||
* Provides field translation synchronization capabilities.
|
||||
*/
|
||||
class FieldTranslationSynchronizer implements FieldTranslationSynchronizerInterface {
|
||||
|
||||
/**
|
||||
* The entity manager to use to load unchanged entities.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManager
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* Constructs a FieldTranslationSynchronizer object.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityManager $entityManager
|
||||
* The entity manager.
|
||||
*/
|
||||
public function __construct(EntityManager $entityManager) {
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\translation_entity\FieldTranslationSynchronizerInterface::synchronizeFields().
|
||||
*/
|
||||
|
@ -29,9 +47,7 @@ class FieldTranslationSynchronizer implements FieldTranslationSynchronizerInterf
|
|||
|
||||
// If the entity language is being changed there is nothing to synchronize.
|
||||
$entity_type = $entity->entityType();
|
||||
// @todo Use the entity storage controller directly to avoid accessing the
|
||||
// global scope.
|
||||
$entity_unchanged = isset($entity->original) ? $entity->original : entity_load_unchanged($entity_type, $entity->id());
|
||||
$entity_unchanged = isset($entity->original) ? $entity->original : $this->entityManager->getStorageController($entity_type)->loadUnchanged($entity->id());
|
||||
if ($entity->language()->langcode != $entity_unchanged->language()->langcode) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ class EntityTranslationSyncUnitTest extends DrupalUnitTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->synchronizer = new FieldTranslationSynchronizer();
|
||||
$this->synchronizer = new FieldTranslationSynchronizer($this->container->get('plugin.manager.entity'));
|
||||
$this->synchronized = array('sync1', 'sync2');
|
||||
$this->columns = array_merge($this->synchronized, array('var1', 'var2'));
|
||||
$this->langcodes = array('en', 'it', 'fr', 'de', 'es');
|
||||
|
|
|
@ -20,7 +20,8 @@ class TranslationEntityBundle extends Bundle {
|
|||
* Implements \Symfony\Component\HttpKernel\Bundle\BundleInterface::build().
|
||||
*/
|
||||
public function build(ContainerBuilder $container) {
|
||||
$container->register('translation_entity.synchronizer', 'Drupal\translation_entity\FieldTranslationSynchronizer');
|
||||
$container->register('translation_entity.synchronizer', 'Drupal\translation_entity\FieldTranslationSynchronizer')
|
||||
->addArgument(new Reference('plugin.manager.entity'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue