You are here

protected function MigrationDefinitionCreator::setLanguageDefinitions in GatherContent 8.5

Set migration language dependencies.

2 calls to MigrationDefinitionCreator::setLanguageDefinitions()
MigrationDefinitionCreator::createMigrationDefinition in src/MigrationDefinitionCreator.php
Create migration definitions.
MigrationDefinitionCreator::setReferenceDependencies in src/MigrationDefinitionCreator.php
Set reference migration dependencies and processes.

File

src/MigrationDefinitionCreator.php, line 686

Class

MigrationDefinitionCreator
Create dynamic migration definitions.

Namespace

Drupal\gathercontent

Code

protected function setLanguageDefinitions(&$definitions) {
  $defaultLangMigrationId = $this
    ->getDefaultMigrationId($definitions);
  foreach ($definitions as $definitionId => $definition) {
    if ($definition['langcode'] != $this->siteDefaultLangCode && $definition['langcode'] != 'und') {
      $plugin = explode(':', $definition['destination']['plugin']);
      $entityDefinition = $this->entityTypeManager
        ->getDefinition($plugin[1]);
      $definitions[$definitionId]['destination']['translations'] = TRUE;
      if ($plugin[0] == 'entity_reference_revisions') {
        $element = $entityDefinition
          ->getKey('id');
        $definitions[$definitionId]['process']['collect_' . $defaultLangMigrationId] = [
          'plugin' => 'migration_lookup',
          'source' => 'id',
          'migration' => $defaultLangMigrationId,
        ];
        $definitions[$definitionId]['process']['get_collected_' . $element] = [
          'plugin' => 'get',
          'source' => [
            '@collect_' . $defaultLangMigrationId,
          ],
        ];
        $definitions[$definitionId]['process'][$element] = [
          'plugin' => 'extract',
          'source' => '@get_collected_' . $element,
          'index' => [
            0,
            0,
          ],
        ];
      }
      else {
        $definitions[$definitionId]['process'][$entityDefinition
          ->getKey('id')] = [
          'plugin' => 'migration_lookup',
          'source' => 'id',
          'migration' => $defaultLangMigrationId,
        ];
      }
      $definitions[$definitionId]['process']['langcode'] = [
        'plugin' => 'default_value',
        'default_value' => $definition['langcode'],
      ];
      $definitions[$definitionId]['migration_dependencies']['optional'][] = $defaultLangMigrationId;
    }
  }
}