diff --git a/core/modules/node/src/EventSubscriber/NodeTranslationRedirectSubscriber.php b/core/modules/node/src/EventSubscriber/NodeTranslationRedirectSubscriber.php index 7f37883..a9613d6 100644 --- a/core/modules/node/src/EventSubscriber/NodeTranslationRedirectSubscriber.php +++ b/core/modules/node/src/EventSubscriber/NodeTranslationRedirectSubscriber.php @@ -5,6 +5,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleInstallerInterface; use Drupal\Core\KeyValueStore\KeyValueFactoryInterface; +use Drupal\migrate\Event\EventBase; use Drupal\migrate\Event\MigrateEvents; use Drupal\migrate\Event\MigrateImportEvent; use Drupal\migrate\Event\MigratePostRowSaveEvent; @@ -53,14 +54,29 @@ public function __construct(KeyValueFactoryInterface $key_value, ModuleHandlerIn } /** + * Helper method to check if we are migrating translated nodes. + * + * @param \Drupal\migrate\Event\EventBase $event + * The migrate event. + * + * @return bool + * True if we are migrating translated nodes, false otherwise. + */ + protected function isNodeTranslationsMigration(EventBase $event) { + $migration = $event->getMigration(); + $source_configuration = $migration->getSourceConfiguration(); + $destination_configuration = $migration->getDestinationConfiguration(); + return !empty($source_configuration['translations']) && $destination_configuration['plugin'] == 'entity:node'; + } + + /** * Maps the old nid to the new one in the key value collection. * * @param \Drupal\migrate\Event\MigratePostRowSaveEvent $event * The migrate post row save event. */ public function onPostRowSave(MigratePostRowSaveEvent $event) { - $configuration = $event->getMigration()->getDestinationConfiguration(); - if ($configuration['plugin'] == 'entity:node' && !empty($configuration['translations'])) { + if ($this->isNodeTranslationsMigration($event)) { $row = $event->getRow(); $source = $row->getSource(); $destination = $row->getDestination(); @@ -76,7 +92,7 @@ public function onPostRowSave(MigratePostRowSaveEvent $event) { * The migrate import event. */ public function onPostImport(MigrateImportEvent $event) { - if (substr($event->getMigration()->getPluginId(), 2, 17) == '_node_translation') { + if ($this->isNodeTranslationsMigration($event)) { if (!$this->moduleHandler->moduleExists('node_translation_redirect')) { $this->moduleInstaller->install(['node_translation_redirect']); }