class Paragraphs

Same name in this branch
  1. 8.x-1.x paragraphs/src/Feeds/Target/Paragraphs.php \Drupal\paragraphs\Feeds\Target\Paragraphs
  2. 8.x-1.x paragraphs/src/Plugin/migrate/field/Paragraphs.php \Drupal\paragraphs\Plugin\migrate\field\Paragraphs

Field Plugin for paragraphs migrations.

Plugin annotation


@MigrateField(
  id = "paragraphs",
  core = {7},
  type_map = {
    "paragraphs" = "entity_reference_revisions",
  },
  source_module = "paragraphs",
  destination_module = "paragraphs",
)

Hierarchy

  • class \Drupal\paragraphs\Plugin\migrate\field\Paragraphs extends \Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase

Expanded class hierarchy of Paragraphs

39 string references to 'Paragraphs'
core.entity_form_display.node.paragraphed_content_demo.default.yml in paragraphs_collection/modules/paragraphs_collection_demo/config/install/core.entity_form_display.node.paragraphed_content_demo.default.yml
paragraphs_collection/modules/paragraphs_collection_demo/config/install/core.entity_form_display.node.paragraphed_content_demo.default.yml
core.entity_form_display.node.paragraphed_content_demo.default.yml in paragraphs/modules/paragraphs_demo/config/install/core.entity_form_display.node.paragraphed_content_demo.default.yml
paragraphs/modules/paragraphs_demo/config/install/core.entity_form_display.node.paragraphed_content_demo.default.yml
core.entity_form_display.paragraph.accordion.default.yml in paragraphs_collection/modules/paragraphs_collection_demo/config/install/core.entity_form_display.paragraph.accordion.default.yml
paragraphs_collection/modules/paragraphs_collection_demo/config/install/core.entity_form_display.paragraph.accordion.default.yml
core.entity_form_display.paragraph.container.default.yml in paragraphs_collection/config/install/core.entity_form_display.paragraph.container.default.yml
paragraphs_collection/config/install/core.entity_form_display.paragraph.container.default.yml
core.entity_form_display.paragraph.grid.default.yml in paragraphs_collection/config/install/core.entity_form_display.paragraph.grid.default.yml
paragraphs_collection/config/install/core.entity_form_display.paragraph.grid.default.yml

... See full list

File

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

Namespace

Drupal\paragraphs\Plugin\migrate\field
View source
class Paragraphs extends FieldPluginBase {

  /**
   * {@inheritdoc}
   */
  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);
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public function alterFieldWidgetMigration(MigrationInterface $migration) {
    parent::alterFieldWidgetMigration($migration);
    $this
      ->paragraphAlterFieldWidgetMigration($migration);
  }

  /**
   * {@inheritdoc}
   */
  public function alterFieldFormatterMigration(MigrationInterface $migration) {
    $this
      ->addViewModeProcess($migration);
    parent::alterFieldFormatterMigration($migration);
  }

  /**
   * {@inheritdoc}
   */
  public function getFieldFormatterMap() {
    return [
      'paragraphs_view' => 'entity_reference_revisions_entity_view',
    ] + parent::getFieldFormatterMap();
  }

  /**
   * {@inheritdoc}
   */
  public function getFieldWidgetMap() {
    return [
      'paragraphs_embed' => 'entity_reference_paragraphs',
    ] + parent::getFieldWidgetMap();
  }

  /**
   * {@inheritdoc}
   */
  public function alterFieldMigration(MigrationInterface $migration) {
    $settings = [
      'paragraphs' => [
        'plugin' => 'paragraphs_field_settings',
      ],
    ];
    $migration
      ->mergeProcessOfProperty('settings', $settings);
  }

  /**
   * {@inheritdoc}
   */
  public function alterFieldInstanceMigration(MigrationInterface $migration) {
    $settings = [
      'paragraphs' => [
        'plugin' => 'paragraphs_field_instance_settings',
      ],
    ];
    $migration
      ->mergeProcessOfProperty('settings', $settings);
  }

  /**
   * Adds process for view mode settings.
   *
   * @param \Drupal\migrate\Plugin\MigrationInterface $migration
   *   The migration.
   */
  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);
  }

  /**
   * Adds processes for paragraphs field widgets.
   *
   * @param \Drupal\migrate\Plugin\MigrationInterface $migration
   *   The migration.
   */
  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);
  }

}

Members

Name Modifiers Type Descriptionsort descending Overrides
Paragraphs::getFieldWidgetMap public function
Paragraphs::getFieldFormatterMap public function
Paragraphs::alterFieldWidgetMigration public function
Paragraphs::alterFieldFormatterMigration public function
Paragraphs::alterFieldMigration public function
Paragraphs::alterFieldInstanceMigration public function
Paragraphs::defineValueProcessPipeline public function
Paragraphs::addViewModeProcess protected function Adds process for view mode settings.
Paragraphs::paragraphAlterFieldWidgetMigration protected function Adds processes for paragraphs field widgets.