View source
<?php
namespace Drupal\paragraphs\Plugin\migrate\field;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
class Paragraphs extends FieldPluginBase {
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',
],
],
'source' => 'value',
],
[
'plugin' => 'extract',
'index' => [
'revision_id',
],
],
],
],
];
$migration
->setProcessOfProperty($field_name, $process);
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);
}
}
}
public function alterFieldWidgetMigration(MigrationInterface $migration) {
parent::alterFieldWidgetMigration($migration);
$this
->paragraphAlterFieldWidgetMigration($migration);
}
public function alterFieldFormatterMigration(MigrationInterface $migration) {
$this
->addViewModeProcess($migration);
parent::alterFieldFormatterMigration($migration);
}
public function getFieldFormatterMap() {
return [
'paragraphs_view' => 'entity_reference_revisions_entity_view',
] + parent::getFieldFormatterMap();
}
public function getFieldWidgetMap() {
return [
'paragraphs_embed' => 'entity_reference_paragraphs',
] + parent::getFieldWidgetMap();
}
public function alterFieldMigration(MigrationInterface $migration) {
$settings = [
'paragraphs' => [
'plugin' => 'paragraphs_field_settings',
],
];
$migration
->mergeProcessOfProperty('settings', $settings);
}
public function alterFieldInstanceMigration(MigrationInterface $migration) {
$settings = [
'paragraphs' => [
'plugin' => 'paragraphs_field_instance_settings',
],
];
$migration
->mergeProcessOfProperty('settings', $settings);
}
protected function addViewModeProcess(MigrationInterface $migration) {
$view_mode = [
'paragraphs' => [
'plugin' => 'paragraphs_process_on_value',
'source_value' => 'type',
'expected_value' => 'paragraphs',
'process' => [
'plugin' => 'get',
'source' => 'formatter/settings/view_mode',
],
],
];
$migration
->mergeProcessOfProperty('options/settings/view_mode', $view_mode);
}
protected function paragraphAlterFieldWidgetMigration(MigrationInterface $migration) {
$title = [
'paragraphs' => [
'plugin' => 'paragraphs_process_on_value',
'source_value' => 'type',
'expected_value' => 'paragraphs',
'process' => [
'plugin' => 'get',
'source' => 'settings/title',
],
],
];
$title_plural = [
'paragraphs' => [
'plugin' => 'paragraphs_process_on_value',
'source_value' => 'type',
'expected_value' => 'paragraphs',
'process' => [
'plugin' => 'get',
'source' => 'settings/title_multiple',
],
],
];
$edit_mode = [
'paragraphs' => [
'plugin' => 'paragraphs_process_on_value',
'source_value' => 'type',
'expected_value' => 'paragraphs',
'process' => [
'plugin' => 'get',
'source' => 'settings/default_edit_mode',
],
],
];
$add_mode = [
'paragraphs' => [
'plugin' => 'paragraphs_process_on_value',
'source_value' => 'type',
'expected_value' => 'paragraphs',
'process' => [
'plugin' => 'get',
'source' => 'settings/add_mode',
],
],
];
$migration
->mergeProcessOfProperty('options/settings/title', $title);
$migration
->mergeProcessOfProperty('options/settings/title_plural', $title_plural);
$migration
->mergeProcessOfProperty('options/settings/edit_mode', $edit_mode);
$migration
->mergeProcessOfProperty('options/settings/add_mode', $add_mode);
}
}