Chris@0: keyValue = $key_value; Chris@0: $this->state = $state; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Helper method to check if we are migrating translated nodes. Chris@0: * Chris@0: * @param \Drupal\migrate\Event\EventBase $event Chris@0: * The migrate event. Chris@0: * Chris@0: * @return bool Chris@0: * True if we are migrating translated nodes, false otherwise. Chris@0: */ Chris@0: protected function isNodeTranslationsMigration(EventBase $event) { Chris@0: $migration = $event->getMigration(); Chris@0: $source_configuration = $migration->getSourceConfiguration(); Chris@0: $destination_configuration = $migration->getDestinationConfiguration(); Chris@0: return !empty($source_configuration['translations']) && $destination_configuration['plugin'] === 'entity:node'; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Maps the old nid to the new one in the key value collection. Chris@0: * Chris@0: * @param \Drupal\migrate\Event\MigratePostRowSaveEvent $event Chris@0: * The migrate post row save event. Chris@0: */ Chris@0: public function onPostRowSave(MigratePostRowSaveEvent $event) { Chris@0: if ($this->isNodeTranslationsMigration($event)) { Chris@0: $row = $event->getRow(); Chris@0: $source = $row->getSource(); Chris@0: $destination = $row->getDestination(); Chris@0: $collection = $this->keyValue->get('node_translation_redirect'); Chris@0: $collection->set($source['nid'], [$destination['nid'], $destination['langcode']]); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Set the node_translation_redirect state to enable the redirections. Chris@0: * Chris@0: * @param \Drupal\migrate\Event\MigrateImportEvent $event Chris@0: * The migrate import event. Chris@0: */ Chris@0: public function onPostImport(MigrateImportEvent $event) { Chris@0: if ($this->isNodeTranslationsMigration($event)) { Chris@0: $this->state->set('node_translation_redirect', TRUE); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function getSubscribedEvents() { Chris@0: $events = []; Chris@0: Chris@0: $events[MigrateEvents::POST_ROW_SAVE] = ['onPostRowSave']; Chris@0: $events[MigrateEvents::POST_IMPORT] = ['onPostImport']; Chris@0: Chris@0: return $events; Chris@0: } Chris@0: Chris@0: }