public function Paragraphs::defineValueProcessPipeline

File

paragraphs/src/Plugin/migrate/field/Paragraphs.php, line 26

Class

Paragraphs
Field Plugin for paragraphs migrations.

Namespace

Drupal\paragraphs\Plugin\migrate\field

Code

public function defineValueProcessPipeline(MigrationInterface $migration, $field_name, $data) {
  $process = [
    'plugin' => 'sub_process',
    'source' => $field_name,
    'process' => [
      'target_id' => [
        [
          'plugin' => 'paragraphs_lookup',
          'tags' => 'Paragraphs Content',
          'source' => 'value',
        ],
        [
          'plugin' => 'extract',
          'index' => [
            'id',
          ],
        ],
      ],
      'target_revision_id' => [
        [
          'plugin' => 'paragraphs_lookup',
          'tags' => [
            'Paragraphs Revisions Content',
            'Paragraphs Content',
          ],
          'tag_ids' => [
            'Paragraphs Revisions Content' => [
              'revision_id',
            ],
            'Paragraphs Content' => [
              'value',
            ],
          ],
          // D8.4 Does not like an empty source value, Even when using ids.
          'source' => 'value',
        ],
        [
          'plugin' => 'extract',
          'index' => [
            'revision_id',
          ],
        ],
      ],
    ],
  ];
  $migration
    ->setProcessOfProperty($field_name, $process);

  // Add paragraphs migration as a dependency (if this is not a paragraph
  // migration).
  // @todo: This is a great example why we should consider derive paragraph
  // migrations based on parent entity type (and bundle).
  if (!in_array('Paragraphs Content', $migration
    ->getMigrationTags(), TRUE)) {
    $dependencies = $migration
      ->getMigrationDependencies() + [
      'required' => [],
    ];
    $dependencies['required'] = array_unique(array_merge(array_values($dependencies['required']), [
      'd7_paragraphs',
    ]));
    $migration
      ->set('migration_dependencies', $dependencies);
    if (strpos($migration
      ->getDestinationPlugin()
      ->getPluginId(), 'entity_revision:') === 0 || strpos($migration
      ->getDestinationPlugin()
      ->getPluginId(), 'entity_complete:') === 0) {
      $dependencies['required'] = array_unique(array_merge(array_values($dependencies['required']), [
        'd7_paragraphs_revisions',
      ]));
      $migration
        ->set('migration_dependencies', $dependencies);
    }
  }
}