-1

I'm looking to migrate two fields on D7 (one a link field, the other a text field) into a single link field on D10.

The meat of the migration is here:

source:
  plugin: d7_paragraphs_item
  bundle: BUNDLE
process:
  d10_link_field:
    plugin: field_link
    source: d7_link_field
  d10_link_field/title: d7_title_field/value

This is resulting in a title of NULL in the d10_link_field.

Any pointers would be greatly appreciated.

2

2 Answers 2

0

Custom process is the answer (as it usually is):

Migration:

source:
  plugin: d7_paragraphs_item
  bundle: BUNDLE
process:
  d10_link_field:
    plugin: field_link_custom
    source: d7_link_field
    title_source: d7_title_field

And the plugin:

<?php

namespace Drupal\MODULE_migrate\Plugin\migrate\process;

use Drupal\link\Plugin\migrate\process\FieldLink;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;

/**
 * Extension of the field_link plugin to handle multiple source fields.
 *
 * Add to the process section of the migration YML:
 *
 * @code
 * field_destination:
 *   plugin: field_link_custom
 *   source: field_source
 *   title_source: field_title_source
 * @endcode
 *
 * @MigrateProcessPlugin(
 *   id = "field_link_custom",
 *   handle_multiples = TRUE
 * )
 */
class FieldLinkCustom extends FieldLink {

  /**
   * {@inheritdoc}
   */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    $route = parent::transform($value[0], $migrate_executable, $row, $destination_property);
    $route['title'] = $row->getSourceProperty($this->configuration['title_source'])[0]['value'];
    return $route;
  }

}
0

You should be able to do something like this, without any custom process plugin:

process:
  'd10_link_field/uri': d7_link_field/0/url
  'd10_link_field/title': d7_title_field/0/value

Most custom D7 fields are multivalue by default, so you need the /0/ to access its first value. D7 Link and Text fields have a different structure so you need to check whether the value is in a value or url subfield.

You can use the Migrate Devel module to inspect the migrations while working on them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.