You are here

abstract class MediaMigrationFieldInstanceSettingsProcessPluginBase in Media Migration 8

Base class for Media Migration's field instance settings plugins.

Hierarchy

Expanded class hierarchy of MediaMigrationFieldInstanceSettingsProcessPluginBase

File

src/Plugin/migrate/process/MediaMigrationFieldInstanceSettingsProcessPluginBase.php, line 18

Namespace

Drupal\media_migration\Plugin\migrate\process
View source
abstract class MediaMigrationFieldInstanceSettingsProcessPluginBase extends ProcessPluginBase implements ContainerFactoryPluginInterface {
  use MigrationDeriverTrait;

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Constructs a new plugin instance.
   *
   * @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\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('entity_type.manager'));
  }

  /**
   * Returns data of media types which will be available after the migration.
   *
   * @return array
   *   Array of the media type's source data, keyed by the media type ID.
   */
  protected function getPredictedMediaTypeData() : array {
    $media_types = [];
    $media_type_file_plain_source = static::getSourcePlugin('d7_file_plain_type');
    foreach ($media_type_file_plain_source as $row) {
      assert($row instanceof Row);
      $media_types[$row
        ->getSourceProperty('bundle')] = $row
        ->getSource();
    }
    $media_type_file_entity_source = static::getSourcePlugin('d7_file_entity_type');
    try {
      foreach ($media_type_file_entity_source as $row) {
        assert($row instanceof Row);
        $media_types[$row
          ->getSourceProperty('bundle')] = $media_types[$row
          ->getSourceProperty('bundle')] ?? $row
          ->getSource();
      }
    } catch (DatabaseExceptionWrapper $e) {

      // File entity source requirements are not always fulfilled.
    }
    return $media_types;
  }

  /**
   * Returns data about the already existing media types.
   *
   * @return array
   *   Array of some media type data, keyed by the media type ID.
   */
  protected function getExistingMediaTypeData() {
    $existing_media_types = $this->entityTypeManager
      ->getStorage('media_type')
      ->loadMultiple();
    return array_reduce($existing_media_types, function (array $carry, MediaTypeInterface $media_type) {
      if (!$media_type
        ->status()) {
        return $carry;
      }
      $media_type_id = $media_type
        ->id();
      $source_plugin = $media_type
        ->getSource();
      $source_field_definition = $source_plugin
        ->getSourceFieldDefinition($media_type);
      if (!$source_field_definition instanceof FieldDefinitionInterface) {
        return $carry;
      }
      $source_field_storage_definition = $source_field_definition
        ->getFieldStorageDefinition();
      $carry[$media_type_id] = [
        'bundle' => $media_type_id,
        'source_plugin_id' => $source_plugin
          ->getPluginId(),
        'scheme' => $source_field_storage_definition
          ->getSettings()['uri_scheme'] ?? NULL,
      ];
      return $carry;
    }, []);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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
MediaMigrationFieldInstanceSettingsProcessPluginBase::$entityTypeManager protected property The entity type manager.
MediaMigrationFieldInstanceSettingsProcessPluginBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
MediaMigrationFieldInstanceSettingsProcessPluginBase::getExistingMediaTypeData protected function Returns data about the already existing media types.
MediaMigrationFieldInstanceSettingsProcessPluginBase::getPredictedMediaTypeData protected function Returns data of media types which will be available after the migration.
MediaMigrationFieldInstanceSettingsProcessPluginBase::__construct public function Constructs a new plugin instance. Overrides PluginBase::__construct
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
MigrationDeriverTrait::getSourcePlugin public static function Returns a fully initialized instance of a source plugin.
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.