diff --git a/migration_templates/d7_paragraph.yml b/migration_templates/d7_paragraph.yml new file mode 100644 index 0000000..a310e88 --- /dev/null +++ b/migration_templates/d7_paragraph.yml @@ -0,0 +1,23 @@ +id: d7_paragraph +label: Paragraphs +migration_tags: + - Drupal 7 +builder: + plugin: d7_paragraph +source: + plugin: d7_paragraph +process: + id: item_id + type: bundle + revision_id: revision_id + langcode: + plugin: default_value + source: language + default_value: "und" +destination: + plugin: entity:paragraph +migration_dependencies: + required: + - d7_user + - d7_paragraph_type + - d7_paragraph_field_instance diff --git a/migration_templates/d7_paragraph_field.yml b/migration_templates/d7_paragraph_field.yml new file mode 100644 index 0000000..9591d47 --- /dev/null +++ b/migration_templates/d7_paragraph_field.yml @@ -0,0 +1,53 @@ +id: d7_paragraph_field +label: Paragraph field configuration +migration_tags: + - Drupal 7 +source: + plugin: d7_paragraph_field + constants: + status: true + langcode: und +process: + entity_type: + plugin: static_map + source: entity_type + bypass: true + map: + paragraphs_item: paragraph + status: 'constants/status' + langcode: 'constants/langcode' + field_name: field_name + type: + plugin: static_map + source: type + map: + date: datetime + datestamp: datetime + datetime: datetime + email: email + file: file + image: image + link_field: link + list_boolean: boolean + list_integer: list_integer + list_text: list_string + number_integer: integer + number_decimal: decimal + number_float: float + paragraphs: entity_reference_revisions + paragraphs_item: paragraph + phone: telephone + taxonomy_term_reference: entity_reference + text: text + text_long: text_long + text_with_summary: text_with_summary + translatable: translatable + cardinality: cardinality + settings: + plugin: d7_paragraph_field_settings +destination: + plugin: entity:field_storage_config +migration_dependencies: + required: + - d7_paragraph_type + - d7_field diff --git a/migration_templates/d7_paragraph_field_instance.yml b/migration_templates/d7_paragraph_field_instance.yml new file mode 100644 index 0000000..958cea8 --- /dev/null +++ b/migration_templates/d7_paragraph_field_instance.yml @@ -0,0 +1,37 @@ +id: d7_paragraph_field_instance +label: Paragraph field instance configuration +migration_tags: + - Drupal 7 +source: + plugin: d7_paragraph_field_instance + constants: + status: true +process: + entity_type: + plugin: static_map + source: entity_type + bypass: true + map: + paragraphs_item: paragraph + field_name: field_name + bundle: bundle + label: label + description: description + required: required + status: 'constants/status' + settings: + plugin: d7_paragraph_field_instance_settings + source: + - instance_settings + - widget_settings + default_value_function: '' + default_value: + plugin: d7_field_instance_defaults + source: + - default_value + - widget_settings +destination: + plugin: entity:field_config +migration_dependencies: + required: + - d7_paragraph_field diff --git a/migration_templates/d7_paragraph_revision.yml b/migration_templates/d7_paragraph_revision.yml new file mode 100644 index 0000000..135de93 --- /dev/null +++ b/migration_templates/d7_paragraph_revision.yml @@ -0,0 +1,21 @@ +id: d7_paragraph_revision +label: Paragraph revisions +migration_tags: + - Drupal 7 +builder: + plugin: d7_paragraph +source: + plugin: d7_paragraph_revision +process: + id: item_id + type: bundle + revision_id: revision_id + langcode: + plugin: default_value + source: language + default_value: "und" +destination: + plugin: entity_revision:paragraph +migration_dependencies: + required: + - d7_paragraph:* diff --git a/migration_templates/d7_paragraph_set.yml b/migration_templates/d7_paragraph_set.yml new file mode 100644 index 0000000..59ad670 --- /dev/null +++ b/migration_templates/d7_paragraph_set.yml @@ -0,0 +1,14 @@ +id: d7_paragraph_set +label: Paragraph sets +migration_tags: + - Drupal 7 +builder: + plugin: d7_paragraph_set +source: + plugin: d7_node +process: + nid: nid + vid: vid + type: type +destination: + plugin: entity:node diff --git a/migration_templates/d7_paragraph_type.yml b/migration_templates/d7_paragraph_type.yml new file mode 100644 index 0000000..8c94520 --- /dev/null +++ b/migration_templates/d7_paragraph_type.yml @@ -0,0 +1,11 @@ +id: d7_paragraph_type +label: Paragraph type configuration +migration_tags: + - Drupal 7 +source: + plugin: d7_paragraph_type +process: + id: bundle + label: name +destination: + plugin: entity:paragraphs_type diff --git a/src/Plugin/migrate/builder/Paragraph.php b/src/Plugin/migrate/builder/Paragraph.php new file mode 100644 index 0000000..60d7e9d --- /dev/null +++ b/src/Plugin/migrate/builder/Paragraph.php @@ -0,0 +1,57 @@ +getSourcePlugin('d7_paragraph_field_instance', $template['source']) as $field) { + $info = $field->getSource(); + $fields[$info['entity_type']][$info['bundle']][$info['field_name']] = $info; + } + + foreach ($this->getSourcePlugin('d7_paragraph_type', $template['source']) as $paragraph_type) { + $bundle = $paragraph_type->getSourceProperty('bundle'); + $values = $template; + $values['id'] .= '__' . $bundle; + $values['label'] = $this->t('@label (@type)', ['@label' => $values['label'], '@type' => $paragraph_type->getSourceProperty('name')]); + $values['source']['paragraph_type'] = $bundle; + $migration = Migration::create($values); + + if (isset($fields['paragraphs_item'][$bundle])) { + foreach ($fields['paragraphs_item'][$bundle] as $field => $data) { + if ($this->cckPluginManager->hasDefinition($data['type'])) { + $this->getCckPlugin($data['type']) + ->processCckFieldValues($migration, $field, $data); + } + else { + $migration->setProcessOfProperty($field, $field); + } + } + } + + $migrations[] = $migration; + } + + return $migrations; + } + +} diff --git a/src/Plugin/migrate/builder/ParagraphSet.php b/src/Plugin/migrate/builder/ParagraphSet.php new file mode 100644 index 0000000..ad6a955 --- /dev/null +++ b/src/Plugin/migrate/builder/ParagraphSet.php @@ -0,0 +1,56 @@ +getSourcePlugin('d7_paragraph_field_instance', $template['source']) as $field) { + $info = $field->getSource(); + $fields[$info['entity_type']][$info['bundle']][$info['field_name']] = $info; + } + + $entity_type_source = 'd7_node_type'; + $entity_type = 'node'; + $entity_name = 'Node'; + foreach ($this->getSourcePlugin($entity_type_source, $template['source']) as $node_type) { + $bundle = $node_type->getSourceProperty('type'); + $values = $template; + $values['id'] .= '__' . $entity_type . '__' . $bundle; + $values['label'] = $this->t('@label (@entity @type)', ['@label' => $values['label'], '@entity' => $entity_name, '@type' => $node_type->getSourceProperty('name')]); + $values['source']['node_type'] = $bundle; + $migration = Migration::create($values); + + if (isset($fields[$entity_type][$bundle])) { + foreach ($fields[$entity_type][$bundle] as $field => $data) { + $migration->setProcessOfProperty($field, array( + 'plugin' => 'paragraph_reference', + 'source' => $field + )); + } + } + + $migrations[] = $migration; + } + + return $migrations; + } + +} diff --git a/src/Plugin/migrate/destination/EntityParagraphType.php b/src/Plugin/migrate/destination/EntityParagraphType.php new file mode 100644 index 0000000..a5c7283 --- /dev/null +++ b/src/Plugin/migrate/destination/EntityParagraphType.php @@ -0,0 +1,20 @@ +getBundleInfo('paragraph')); + $weight = count($paragraph_bundle_ids) + 1; + + if (isset($paragraph_bundle_ids) && count($paragraph_bundle_ids) > 0) { + foreach ($paragraph_bundle_ids as $paragraph_bundle_id) { + $settings['handler_settings']['target_bundles'][$paragraph_bundle_id] = $paragraph_bundle_id; + $enabled = FALSE; + if (isset($settings['allowed_bundles'][$paragraph_bundle_id])) { + $enabled = $settings['allowed_bundles'][$paragraph_bundle_id] === $paragraph_bundle_id; + } + $settings['handler_settings']['target_bundles_drag_drop'][$paragraph_bundle_id] = array( + 'weight' => $weight, + 'enabled' => $enabled + ); + + $weight++; + } + } + } + else { + $settings = parent::transform($value, $migrate_executable, $row, $destination_property); + } + + return $settings; + } + +} diff --git a/src/Plugin/migrate/process/ParagraphFieldSettings.php b/src/Plugin/migrate/process/ParagraphFieldSettings.php new file mode 100644 index 0000000..388c4ff --- /dev/null +++ b/src/Plugin/migrate/process/ParagraphFieldSettings.php @@ -0,0 +1,37 @@ +getSourceProperty('settings'); + + if ('paragraphs' == $row->getSourceProperty('type')) { + $value['target_type'] = 'paragraph'; + } + else { + $value = parent::transform($value, $migrate_executable, $row, $destination_property); + } + + return $value; + } + +} diff --git a/src/Plugin/migrate/process/ParagraphReference.php b/src/Plugin/migrate/process/ParagraphReference.php new file mode 100644 index 0000000..4d98ec6 --- /dev/null +++ b/src/Plugin/migrate/process/ParagraphReference.php @@ -0,0 +1,41 @@ +select('paragraphs_item_revision', 'pr') + ->fields('p', array( + 'item_id', + 'bundle', + )) + ->fields('pr', array( + 'revision_id', + )); + $query->innerJoin('paragraphs_item', 'p', static::JOIN); + + if (isset($this->configuration['paragraph_type'])) { + $query->condition('bundle', $this->configuration['paragraph_type']); + } + + return $query; + } + + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row) { + // Get Field API field values. + foreach (array_keys($this->getFields('paragraphs_item', $row->getSourceProperty('bundle'))) as $field) { + $nid = $row->getSourceProperty('item_id'); + $vid = $row->getSourceProperty('revision_id'); + $row->setSourceProperty($field, $this->getFieldValues('paragraphs_item', $field, $nid, $vid)); + } + return parent::prepareRow($row); + } + + /** + * {@inheritdoc} + */ + public function fields() { + $fields = array( + 'item_id' => $this->t('Paragraph ID'), + 'bundle' => $this->t('Type'), + ); + return $fields; + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['item_id']['type'] = 'integer'; + $ids['item_id']['alias'] = 'p'; + return $ids; + } + +} diff --git a/src/Plugin/migrate/source/ParagraphField.php b/src/Plugin/migrate/source/ParagraphField.php new file mode 100644 index 0000000..4a09a6f --- /dev/null +++ b/src/Plugin/migrate/source/ParagraphField.php @@ -0,0 +1,34 @@ +orConditionGroup() + ->condition('fc.type', 'paragraphs') + ->condition('fci.entity_type', 'paragraphs_item'); + $query->condition($group); + return $query; + } + +} diff --git a/src/Plugin/migrate/source/ParagraphFieldInstance.php b/src/Plugin/migrate/source/ParagraphFieldInstance.php new file mode 100644 index 0000000..989f9ee --- /dev/null +++ b/src/Plugin/migrate/source/ParagraphFieldInstance.php @@ -0,0 +1,34 @@ +orConditionGroup() + ->condition('fc.type', 'paragraphs') + ->condition('fci.entity_type', 'paragraphs_item'); + $query->condition($group); + return $query; + } + +} diff --git a/src/Plugin/migrate/source/ParagraphRevision.php b/src/Plugin/migrate/source/ParagraphRevision.php new file mode 100644 index 0000000..242fc14 --- /dev/null +++ b/src/Plugin/migrate/source/ParagraphRevision.php @@ -0,0 +1,34 @@ + pr.revision_id'; + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['revision_id']['type'] = 'integer'; + $ids['revision_id']['alias'] = 'pr'; + return $ids; + } + +} diff --git a/src/Plugin/migrate/source/ParagraphType.php b/src/Plugin/migrate/source/ParagraphType.php new file mode 100644 index 0000000..66ec24a --- /dev/null +++ b/src/Plugin/migrate/source/ParagraphType.php @@ -0,0 +1,48 @@ +select('paragraphs_bundle', 't')->fields('t'); + } + + /** + * {@inheritdoc} + */ + public function fields() { + return array( + 'bundle' => $this->t('Machine name of the paragraph type.'), + 'name' => $this->t('Human name of the paragraph type.'), + 'locked' => $this->t('Flag.'), + ); + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['bundle']['type'] = 'string'; + return $ids; + } + +}