You are here

abstract class EmbedFilterBase in Media Migration 8

Base class for media embed code filter text process plugins.

Hierarchy

Expanded class hierarchy of EmbedFilterBase

File

src/Plugin/migrate/process/EmbedFilterBase.php, line 14

Namespace

Drupal\media_migration\Plugin\migrate\process
View source
abstract class EmbedFilterBase extends ProcessPluginBase implements ContainerFactoryPluginInterface {

  /**
   * The actual migration plugin instance.
   *
   * @var \Drupal\migrate\Plugin\MigrationInterface
   */
  protected $migration;

  /**
   * The media UUID oracle.
   *
   * @var \Drupal\media_migration\MediaMigrationUuidOracleInterface
   */
  protected $mediaUuidOracle;

  /**
   * The entity embed display plugin manager service, if available.
   *
   * @var \Drupal\entity_embed\EntityEmbedDisplay\EntityEmbedDisplayManager|null
   */
  protected $entityEmbedDisplayPluginManager;

  /**
   * Constructs a new EmbedFilterBase object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\migrate\Plugin\MigrationInterface $migration
   *   The migration entity.
   * @param \Drupal\media_migration\MediaMigrationUuidOracleInterface $media_uuid_oracle
   *   The media UUID oracle.
   * @param \Drupal\entity_embed\EntityEmbedDisplay\EntityEmbedDisplayManager|null $entity_embed_display_manager
   *   The entity embed display plugin manager service, if available.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, MediaMigrationUuidOracleInterface $media_uuid_oracle, $entity_embed_display_manager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->migration = $migration;
    $this->mediaUuidOracle = $media_uuid_oracle;
    $this->entityEmbedDisplayPluginManager = $entity_embed_display_manager;
  }

  /**
   * Returns the destination display plugin ID.
   *
   * @param string $view_mode
   *   The view_mode from the source.
   * @param string $destination_filter_plugin_id
   *   The transform destination filter plugin ID.
   *
   * @return string
   *   The embed media's display plugin ID or view_mode.
   */
  protected function getDisplayPluginId(string $view_mode, string $destination_filter_plugin_id) {
    switch ($destination_filter_plugin_id) {
      case 'entity_embed':
        $display_plugin_id = "view_mode:media.{$view_mode}";
        break;
      case 'media_embed':
        return $view_mode;
      default:
        throw new \LogicException();
    }

    // Ensure that the display plugin exists.
    if ($this->entityEmbedDisplayPluginManager instanceof EntityEmbedDisplayManager) {
      $available_plugins = $this->entityEmbedDisplayPluginManager
        ->getDefinitionOptionsForEntityType('media');
      if (empty($available_plugins)) {
        throw new \LogicException("Media Migration cannot replace a media_filter token in a content entity, since there aren't any available entity_embed display plugins.");
      }
      if (!isset($available_plugins[$display_plugin_id])) {

        // If the preselected display plugin does not exist, then we will
        // try to map it to 'view_mode:media.full'.
        if (isset($available_plugins['view_mode:media.full'])) {
          $display_plugin_id = 'view_mode:media.full';
        }
        else {
          $view_mode_plugins = array_reduce(array_keys($available_plugins), function ($carry, $plugin_id) {
            if (strpos($plugin_id, 'view_mode:media.') === 0) {
              $carry[$plugin_id] = $plugin_id;
            }
            return $carry;
          });

          // If we have 'view_mode:media.[any]', we use the first one; if
          // not, then use the first display plugin.
          $display_plugin_id = !empty($view_mode_plugins) ? reset($view_mode_plugins) : array_keys($available_plugins)[0];
        }
      }
    }
    return $display_plugin_id;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContainerFactoryPluginInterface::create public static function Creates an instance of the plugin. 112
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
EmbedFilterBase::$entityEmbedDisplayPluginManager protected property The entity embed display plugin manager service, if available.
EmbedFilterBase::$mediaUuidOracle protected property The media UUID oracle.
EmbedFilterBase::$migration protected property The actual migration plugin instance.
EmbedFilterBase::getDisplayPluginId protected function Returns the destination display plugin ID.
EmbedFilterBase::__construct public function Constructs a new EmbedFilterBase object. Overrides PluginBase::__construct 2
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
ProcessPluginBase::multiple public function Indicates whether the returned value requires multiple handling. Overrides MigrateProcessInterface::multiple 3
ProcessPluginBase::transform public function Performs the associated process. Overrides MigrateProcessInterface::transform 70
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.