How to combine dom process plugins with media_wysiwyg_filter?

Created on 22 March 2021, over 3 years ago
Updated 18 July 2023, over 1 year ago

I've really struggled with using some of the process filters due to the lack of documentation around them (hence the tags). In particular, I haven't really been able to find any documentation around how to use these plugins in a custom migration - it's as though this is only expected to be used via migrate_upgrade as-is, but I need just parts of it, not a full upgrade setup. Here's what I've got in my node migration currently for just the relevant field:

process:
  body:
    -
      plugin: get
      source: body
    -
      plugin: dom
      method: import
      source: body/value
    -
      plugin: dom_remove
      selector: //span
    -
      plugin: dom
      method: export
    -
      plugin: media_wysiwyg_filter
      media_migrations:
        - yeegoconnect_migrate_d7_file_entity_image_public
      file_migrations:
        - yeegoconnect_migrate_d7_file

I've also attached my entire custom migration module in case that's more helpful.

That throws errors, which aren't particularly helpful, into the messages log:

 -------------- ------------------- ------- -----------------------------------
  Source ID(s)   Destination ID(s)   Level   Message
 -------------- ------------------- ------- -----------------------------------
  3                                  1       Cannot import a non-string value.
  4                                  1       Cannot import a non-string value.
  6                                  1       Cannot import a non-string value.
  7                                  1       Cannot import a non-string value.
  8                                  1       Cannot import a non-string value.
...

All but six of my nodes failed to migrate due to that error.

What I'm trying to do is strip all of the span tags (which contain style crap I don't want) from my source content and convert the Media WYSIWYG embed codes. Additionally, I'd like to do the same thing for the summary field, but the media_wysiwyg_filter plugin seems to be hardcoded to only use the value with no way to process. summary?

TBH, this module could really benefit from some documentation in the handbook (linked in this module list and added in the contributed modules section ). Currently all I've got to go on is the doc blocks in the process plugin files themselves, and those don't account for anything but the most basic use cases.

Feature request
Status

Active

Version

1.0

Component

Documentation

Created by

🇺🇸United States seanr

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇪🇸Spain pcambra Asturies

    Moving my comment from the other issue.

    Thanks for this module, it's saved me a lot of time.
    Just to add to this discussion, I've used the media_wysiwyg_filter standalone in a custom migration and had to alter the plugins to stop depending on d7_file_plain:image:public and d7_file_entity:image:public which I don't use, like so:

    /**
     * Implements hook_migration_plugins_alter().
     */
    function my_module_migration_plugins_alter(array &$migrations) {
      $migration_ids = [
        'upgrade_d7_node_complete_article',
        'upgrade_d7_node_complete_page',
      ];
      $dependencies_to_remove = [
        'd7_file_plain:image:public',
        'd7_file_entity:image:public',
      ];
      foreach ($migration_ids as $migration_id) {
        $dependencies = $migrations[$migration_id]['migration_dependencies'];
        $dependencies['required'] = array_diff($dependencies['required'], $dependencies_to_remove);
        $migrations[$migration_id]['migration_dependencies'] = $dependencies;
      }
    }
    

    Then used the process plugin normally on the migration:

      body/value:
        -
          plugin: get
          source: body/0/value
        -
          plugin: media_wysiwyg_filter
          view_mode_matching:
            default: full
          media_migrations:
            - upgrade_d7_media_images
          file_migrations:
            - upgrade_d7_file
    

    Worth saying that I had much better results in terms of visualization with entity embed than media embed, but the transformation worked very well.

  • 🇪🇸Spain pcambra Asturies

    I've found that using the media_wysiwyg_filter standalone makes all the migrations super super slow due to something that is ran in media_migration_migration_plugins_alter, so I needed to remove the alter hooks:

    /**
     * Implements hook_module_implements_alter().
     */
    function my_module_module_implements_alter(&$implementations, $hook) {
      if ($hook == 'migration_plugins_alter' && isset($implementations['media_migration'])) {
        unset($implementations['media_migration']);
        unset($implementations['media_migration_tools']);
      }
    }
    

    Wondering if it would be worth spinning off the media_wysiwyg_filter as a standalone and composer require it from this one?

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    (I am removing a tag, since tags should not duplicate what already selected for the Component field. I apologize for bumping this issue.)

Production build 0.71.5 2024