Problem/Motivation

I just found two known content entity migrations which do not have Media WYSIWYG plugins. These are:

  • File entities migrated by Media Migration (yes, this is a very rare case)
  • Drupal 7 Bean entities migrated by Bean Migrate

Proposed resolution

Add WYSIWYG plugins for file entities and bean entities.

Comments

huzooka created an issue. See original summary.

huzooka’s picture

Assigned: huzooka » Unassigned
Status: Active » Needs review
StatusFileSize
new11.39 KB
wim leers’s picture

  1. +++ b/src/MediaWysiwygPluginBase.php
    @@ -14,6 +16,36 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
    +    if (!$source_entity_type_id && count($plugin_definition['entity_type_map']) === 1) {
    +      $source_entity_type_id_keys = array_keys($plugin_definition['entity_type_map']);
    +      $configuration['source_entity_type_id'] = reset($source_entity_type_id_keys);
    +    }
    

    🤔 When can this case occur?

  2. +++ b/src/MediaWysiwygPluginManager.php
    @@ -51,10 +51,10 @@ class MediaWysiwygPluginManager extends DefaultPluginManager {
    -        return $this->createInstance($plugin_id, [
    -          'source_entity_type_id' => $source_entity_type_id,
    -          'destination_entity_type_id' => $plugin_definition['entity_type_map'][$source_entity_type_id],
    -        ]);
    +        return $this->createInstance(
    +          $plugin_id,
    +          ['source_entity_type_id' => $source_entity_type_id]
    +        );
    

    This change shows/proves that the destination entity type ID never needs to be specified in configuration. In fact, it no longer can be.

    It will always be looked up automatically based on the supported source entity type IDs in the plugin's entity_type_map annotation.

    Do I understand that correctly? 😊

huzooka’s picture

Assigned: Unassigned » huzooka
Issue summary: View changes
Status: Needs review » Needs work
StatusFileSize
new86.21 KB

Re #3:

  1. Well, it is definitely possible.
    /**
     * Media WYSIWYG plugin for bean → block_content migrations.
     *
     * @MediaWysiwyg(
     *   id = "dummy",
     *   label = @Translation("dummy")
     * )
     */
    class Dummy extends MediaWysiwygPluginBase {}
      

    This plugin gets discovered.

    A Dummy plugin instance

    Obviously it won't be found with MediaWysiwygPluginManager::createInstanceFromSourceEntityType(), but it will definitely trigger PHP notices.

     

  2. Exactly!

    But to achieve this, I also need this change:

    +++ b/src/MediaWysiwygPluginBase.php
    @@ -14,6 +16,36 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function __construct(array $configuration, $plugin_id, $plugin_definition) {
    +    $source_entity_type_id = $configuration['source_entity_type_id'] ?? NULL;
    +    if (!$source_entity_type_id && count($plugin_definition['entity_type_map']) === 1) {
    +      $source_entity_type_id_keys = array_keys($plugin_definition['entity_type_map']);
    +      $configuration['source_entity_type_id'] = reset($source_entity_type_id_keys);
    +    }
    +
    +    if (
    +      empty($configuration['source_entity_type_id']) ||
    +      empty($plugin_definition['entity_type_map'][$configuration['source_entity_type_id']])
    +    ) {
    +      throw new PluginException(
    +        sprintf(
    +          "The MediaWysiwyg plugin instance of class '%s' cannot be instantiated with the following configuration: %s",
    +          get_class($this),
    +          Variable::export($configuration)
    +        )
    +      );
    +    }
    +
    +    $configuration += [
    +      'destination_entity_type_id' => $plugin_definition['entity_type_map'][$configuration['source_entity_type_id']],
    +    ];
    +
    +    parent::__construct($configuration, $plugin_id, $plugin_definition);
    +  }
    +
    

Back to needs work – I want to address the test failures happening with core 8.9.x.

huzooka’s picture

Assigned: huzooka » Unassigned
Status: Needs work » Needs review
StatusFileSize
new11.92 KB
new1.79 KB
huzooka’s picture

Status: Needs review » Fixed

  • huzooka committed c2b7df8 on 8.x-1.x
    Issue #3211097 by huzooka: Add WYSIWYG plugins for file entities...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.