Note: This first needs #2262975: Non-Multiple field types with per-field storage are not supported in CckFieldValues.

Problem/Motivation

image and file fields in D6 and D7 use fid for the file ID, term fields use tid in 7.x. Node reference fields use nid, and so on...

Everything uses target_id in D8.

This kind of works right now but only because FieldCckValues doesn't support non-multiple/multi-property fields, which will be fixed by the issue above, but that will result in having fid/nid and so on in the source values, that will then be ignored by the target field.

So we need a way to convert/rename them.

Proposed resolution

The attached patch adds a transformer plugin, which can be configured like this:

  target_field:
    plugin: transformer
    source: source_field
    map:
      nid: target_id
      other_field.value: description

I also added support for bringing in other field values because we need this for a custom migration.

Remaining tasks

- Write tests.
- Automatically configure image/file/... reference fields to use that plugin? How will other reference fields from contrib (like node, user, role, whatever-reference field) be supported?

User interface changes

API changes

CommentFileSizeAuthor
#1 transformer-2272353-1.patch2.09 KBberdir

Comments

berdir’s picture

Status: Active » Needs review
StatusFileSize
new2.09 KB

Here's the patch.

Berdir queued 1: transformer-2272353-1.patch for re-testing.

benjy’s picture

  1. +++ b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/process/Transformer.php
    @@ -0,0 +1,71 @@
    + * Migrate filter format serial to string id in permission name.
    

    Left over comment.

  2. +++ b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/process/Transformer.php
    @@ -0,0 +1,71 @@
    +    // Standardize non-multiple values.
    +    if (!is_numeric(current(array_keys($value)))) {
    +      $value = array(0 => $value);
    +    }
    

    Why do we need to do this? Can you give an example?

Otherwise the plugin looks good. Can we make use of it and add a test?

ultimike’s picture

Status: Needs review » Needs work
drclaw’s picture

Would this not be achieved now using the iterator processor? The following works for image fields, for example:

  field_image:
    plugin: iterator
    source: field_image
    process:
      target_id: fid
      alt: alt
      title: title
      width: width
      height: height

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mikeryan’s picture

Status: Needs work » Postponed (maintainer needs more info)

Per drclaw - is there still a need for this?

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mikeryan’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)