You are here

public function FieldCollection::defineValueProcessPipeline in Paragraphs 8

Apply any custom processing to the field bundle migrations.

Parameters

\Drupal\migrate\Plugin\MigrationInterface $migration: The migration entity.

string $field_name: The field name we're processing the value for.

array $data: The array of field data from FieldValues::fieldData().

Overrides FieldPluginBase::defineValueProcessPipeline

File

src/Plugin/migrate/field/FieldCollection.php, line 31

Class

FieldCollection
Field Plugin for field collection 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' => 'Field Collection Content',
          'source' => 'value',
        ],
        [
          'plugin' => 'extract',
          'index' => [
            'id',
          ],
        ],
      ],
      'target_revision_id' => [
        [
          'plugin' => 'paragraphs_lookup',
          'tags' => [
            'Field Collection Revisions Content',
            'Field Collection Content',
          ],
          'tag_ids' => [
            'Field Collection Revisions Content' => [
              'revision_id',
            ],
            'Field Collection Content' => [
              'value',
            ],
          ],
        ],
        [
          'plugin' => 'extract',
          'index' => [
            'revision_id',
          ],
        ],
      ],
    ],
  ];
  $migration
    ->setProcessOfProperty($field_name, $process);

  // Add the respective field collection migration as a dependency.
  $migration_dependency = 'd7_field_collection:' . substr($field_name, static::FIELD_COLLECTION_PREFIX_LENGTH);
  $migration_rev_dependency = 'd7_field_collection_revisions:' . substr($field_name, static::FIELD_COLLECTION_PREFIX_LENGTH);
  $dependencies = $migration
    ->getMigrationDependencies() + [
    'required' => [],
  ];
  $dependencies['required'] = array_unique(array_merge(array_values($dependencies['required']), [
    $migration_dependency,
  ]));
  $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']), [
      $migration_rev_dependency,
    ]));
    $migration
      ->set('migration_dependencies', $dependencies);
  }
}