From 1b3d229a93f4e16d7dff27d126a3cd942607dbbf Mon Sep 17 00:00:00 2001 From: Dries Date: Tue, 12 Mar 2013 22:08:28 -0700 Subject: [PATCH] Issue #1935762 by plach: Remove entity_load_unchanged() call from FieldTranslationSynchronizer::synchronizeFields(). --- .../FieldTranslationSynchronizer.php | 22 ++++++++++++++++--- .../Tests/EntityTranslationSyncUnitTest.php | 2 +- .../TranslationEntityBundle.php | 3 ++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/FieldTranslationSynchronizer.php b/core/modules/translation_entity/lib/Drupal/translation_entity/FieldTranslationSynchronizer.php index 281b82fbad0..261dfe1da6d 100644 --- a/core/modules/translation_entity/lib/Drupal/translation_entity/FieldTranslationSynchronizer.php +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/FieldTranslationSynchronizer.php @@ -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; } diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSyncUnitTest.php b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSyncUnitTest.php index a6400a5038b..3a77d95e7e5 100644 --- a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSyncUnitTest.php +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSyncUnitTest.php @@ -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'); diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/TranslationEntityBundle.php b/core/modules/translation_entity/lib/Drupal/translation_entity/TranslationEntityBundle.php index 617014b0155..f36e7026546 100644 --- a/core/modules/translation_entity/lib/Drupal/translation_entity/TranslationEntityBundle.php +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/TranslationEntityBundle.php @@ -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')); } }