Follow-up to #2630578-32: Formats duplicated in D6 upgrade

Should we do any mapping of old formats to somewhat equivalent formats in D8?

'filtered_html' (d6/d7) => 'basic_html' (d8)

Comments

heddn created an issue. See original summary.

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

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now 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.

heddn’s picture

Status: Active » Closed (works as designed)

Migrations are intended to migrate into an empty system. If a site in installed with minimal profile, the basic would never exist.

drzraf’s picture

If the "standard" profile is used, assuming that

  • "standard" profile installs a role, some format filters and theme/blocks
  • all the migrations will be played

... the migration process will certainly duplicate these components (in most use-cases)

Does it mean that the minimal profile is the first choice for people intending to migrate?

heddn’s picture

What I meant to say, is that the default mapping in the template from d6 and d7 to d8 won't be changed. If, however, someone wants to deviate from the default, they can use the static map process plugin. I am marked as won't fix for changing the default mapping. But feel free to change it in your specific situation.

My example of minimal shows that filter names are differently named in different profiles. So to assume anything about their naming assumes to much. Filters are named in d6, d7 and d8 depending on the install profile and later edits from site admins. Making assumptions in that space is going to lead not being correct in several cases. For someone who has done the manual mapping, I've had to weigh all these things. And it isn't simple. So falling back on the default of we do not assume anything seems sane and in line with migrate's normal stance.

drzraf’s picture

Thank you for the clarification.
The approach seems sane to me, as long as writing custom mappings is simple enough and well documented.
Could the 'filtered_html' (d6/d7) => 'basic_html' (d8) mapping appear somewhere as an "example"?

heddn’s picture

AdamPS’s picture

Link in #7 is broken if anyone knows a working one please post it

AdamPS’s picture

Title: Format mappings in D6/D7 upgrade » Document how to perform format mappings in D6/D7 upgrade
Version: 8.3.x-dev » 8.9.x-dev
Category: Feature request » Task
Status: Closed (works as designed) » Active

Altered the title to match the request from #6 which is to explain how someone can manually create a format mapping if they want to. This seems like something that people will want to do and could even be an example for the documentation of StaticMap. See also #3061681: Provide the ability to map text formats between source and destination which is more ambitious, and tries to automatically perform this mapping.

I guess that the link in #7 was just a link to the StaticMap class. I am aware that the class exists, but I can't see how/where to use it. There are references to the text format in very many places: many fields on many entity types. Please could we have an explanation of what file to edit at least?

AdamPS’s picture

OK I have it working. Is there someone we can put this for others who are interested?

A hook to substitute the class

/**
 * Implements hook_migrate_field_info_alter().
 */
function XXX_migrate_field_info_alter(array &$definitions) {
  $definitions['d7_text']['class'] = 'Drupal\XXX\Plugin\migrate\TextFieldOverride';
}

The class itself

namespace Drupal\XXX\Plugin\migrate;

use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\text\Plugin\migrate\field\d7\TextField;

/**
 * Replacement class for "d7_text" field migration.
 */
class TextFieldOverride extends TextField {

  /**
   * {@inheritdoc}
   */
  public function defineValueProcessPipeline(MigrationInterface $migration, $field_name, $data) {
    $process = [
      'plugin' => 'sub_process',
      'source' => $field_name,
      'process' => [
        'value' => 'value',
        'format' =>
        [
          'plugin' => 'static_map',
          'source' => 'format',
          'map' => [
            'filtered_html' => 'basic_html',
          ],
        ],
      ],
    ];

    $migration->mergeProcessOfProperty($field_name, $process);
  }

}

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Anybody’s picture

Hi @AdamPS,

we just ran into the same situation and I guess one clarification here could help others who run into the same issue:

What is "d7_text" in

/**
 * Implements hook_migrate_field_info_alter().
 */
function XXX_migrate_field_info_alter(array &$definitions) {
  $definitions['d7_text']['class'] = 'Drupal\XXX\Plugin\migrate\TextFieldOverride';
}

Is it the name of the field or or the migration id or the text format?

Like in #3061681: Provide the ability to map text formats between source and destination I guess it would make a lot of sense to document these kind of static mapping migrations somewhere for such typical cases. I'm aware of HOOK_migration_plugins_alter() and HOOK_migrate_prepare_row() which are very helpful for other cases, but in this case they don't help I guess?

So what we'd like to do is use existing Drupal 8 / 9 formats by map instead of migrating (some of / all) the old ones.

I'm curious if there is a better way to switch out upgrade_dX_filter_format and use the map instead of

  body/format:
    -
      plugin: migration_lookup
      migration: upgrade_d6_filter_format
      source: format

in node_complete_XXX migrations, but it doesn't seem to be well abstracted to do that for every field.

If anyone has a good snippet or idea, you're very welcome. I have to think about this.
Perhaps it's even easier to switch the formats after migration with a post-migrate script...

Edit:
Perhaps the strategy might be to replace "upgrade_d6_filter_format" to not import any formats but instead just return the mapping?

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

jmee’s picture

Here are some examples where the migration definition file has been edited, but I think it would be better to use hook_migration_plugins_alter if you need to apply this change everywhere

In my example, the D7 source site's text formats weren't migrated properly when the site was upgrade to d7, so machine names are in the d6 format.

Node body field:

process:
  body:
    -   
      plugin: sub_process
      source: body
      process:
        value: value
        format:
          -   
            plugin: static_map
            bypass: true
            source: format
            map:
              '1': 'basic_html'
              '2': 'full_html'
              '3': 'plain_text'
              '4': 'plain_text'
            default_value: 'basic_html'

Term description field:

process:
  description/value:
    -       
      plugin: get 
      source: description
  description/format:
    -       
      plugin: static_map
      source: format
      map:
        '1': 'basic_html'
        '2': 'full_html'
      default_value: 'basic_html'

Or a simple default value also works:

process:
  description/format:
    -   
      plugin: default_value
      default_value: 'basic_html'  

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.