You are here

final class MediaMigration in Media Migration 8

Media Migration configuration and helpers.

Hierarchy

Expanded class hierarchy of MediaMigration

24 files declare their use of MediaMigration
CKEditorLinkFileToLinkitFilter.php in src/Plugin/migrate/process/CKEditorLinkFileToLinkitFilter.php
D7FileConfigDeriver.php in src/Plugin/migrate/D7FileConfigDeriver.php
D7FileDeriver.php in src/Plugin/migrate/D7FileDeriver.php
D7FileEntityConfigDeriver.php in src/Plugin/migrate/D7FileEntityConfigDeriver.php
D7FileEntityDeriver.php in src/Plugin/migrate/D7FileEntityDeriver.php

... See full list

File

src/MediaMigration.php, line 10

Namespace

Drupal\media_migration
View source
final class MediaMigration {

  /**
   * Migration tag for every media related migrations.
   *
   * @const string
   */
  const MIGRATION_TAG_MAIN = 'Media Migration';

  /**
   * Migration tag for media configuration migrations.
   *
   * @const string
   */
  const MIGRATION_TAG_CONFIG = 'Media Configuration';

  /**
   * Migration tag for media entity migrations.
   *
   * @const string
   */
  const MIGRATION_TAG_CONTENT = 'Media Entity';

  /**
   * The name of the media UUID prophecy table.
   *
   * @const string
   */
  const MEDIA_UUID_PROPHECY_TABLE = 'media_migration_media_entity_uuid_prophecy';

  /**
   * The name of the media source ID column.
   *
   * @const string
   */
  const MEDIA_UUID_PROPHECY_SOURCEID_COL = 'source_id';

  /**
   * The name of the column that contains the destination UUID.
   *
   * @const string
   */
  const MEDIA_UUID_PROPHECY_UUID_COL = 'destination_uuid';

  /**
   * The name of the setting of how embedded media should be referred.
   *
   * @const string
   */
  const MEDIA_REFERENCE_METHOD_SETTINGS = 'media_migration_embed_media_reference_method';

  /**
   * The ID embedded media reference method.
   *
   * @const string
   */
  const EMBED_MEDIA_REFERENCE_METHOD_ID = 'id';

  /**
   * The UUID embedded media reference method.
   *
   * @const string
   */
  const EMBED_MEDIA_REFERENCE_METHOD_UUID = 'uuid';

  /**
   * Default embedded media reference method.
   *
   * @const string
   */
  const EMBED_MEDIA_REFERENCE_METHOD_DEFAULT = self::EMBED_MEDIA_REFERENCE_METHOD_ID;

  /**
   * Valid embedded media reference methods.
   *
   * @const string[]
   */
  const VALID_EMBED_MEDIA_REFERENCE_METHODS = [
    self::EMBED_MEDIA_REFERENCE_METHOD_ID,
    self::EMBED_MEDIA_REFERENCE_METHOD_UUID,
  ];

  /**
   * The name of embed code transformation destination filter plugin setting.
   *
   * @const string
   */
  const MEDIA_TOKEN_DESTINATION_FILTER_SETTINGS = 'media_migration_embed_token_transform_destination_filter_plugin';

  /**
   * Entity embed destination filter.
   *
   * @const string
   */
  const MEDIA_TOKEN_DESTINATION_FILTER_ENTITY_EMBED = 'entity_embed';

  /**
   * Media embed destination filter.
   *
   * @const string
   */
  const MEDIA_TOKEN_DESTINATION_FILTER_MEDIA_EMBED = 'media_embed';

  /**
   * Default embed token destination filter plugin ID.
   *
   * Actually, MEDIA_TOKEN_DESTINATION_FILTER_MEDIA_EMBED would be the correct
   * default, but doing that would cause a BC break in this module.
   *
   * @const string
   */
  const MEDIA_TOKEN_DESTINATION_FILTER_DEFAULT = self::MEDIA_TOKEN_DESTINATION_FILTER_ENTITY_EMBED;

  /**
   * The required modules of the valid destination filter plugins.
   *
   * @const array[]
   */
  const MEDIA_TOKEN_DESTINATION_FILTER_REQUIREMENTS = [
    self::MEDIA_TOKEN_DESTINATION_FILTER_ENTITY_EMBED => [
      'entity_embed',
    ],
    self::MEDIA_TOKEN_DESTINATION_FILTER_MEDIA_EMBED => [
      'media',
    ],
  ];

  /**
   * SQL pattern of Linkit file links in (formatted) text fields.
   *
   * @const string
   */
  const SQL_PATTERN_LINKIT_FILE_LINK = '%<a %href=_/file/%';

  /**
   * PCRE pattern of Linkit file links in (formatted) text fields.
   *
   * @const string
   */
  const PCRE_PATTERN_LINKIT_FILE_LINK = '/.*<a(?=\\s).*(?<=\\s)href=(?<quote>[\'|"])\\/file\\/\\d+(?P=quote)/';

  /**
   * Sets the method of the embedded media reference.
   *
   * @return string
   *   The reference method. This might be 'id', or 'uuid'.
   */
  public static function getEmbedMediaReferenceMethod() {
    $value_from_settings = Settings::get(self::MEDIA_REFERENCE_METHOD_SETTINGS, self::EMBED_MEDIA_REFERENCE_METHOD_DEFAULT);
    if (self::getEmbedTokenDestinationFilterPlugin() === self::MEDIA_TOKEN_DESTINATION_FILTER_MEDIA_EMBED) {
      return self::EMBED_MEDIA_REFERENCE_METHOD_UUID;
    }
    return in_array($value_from_settings, self::VALID_EMBED_MEDIA_REFERENCE_METHODS, TRUE) ? $value_from_settings : self::EMBED_MEDIA_REFERENCE_METHOD_DEFAULT;
  }

  /**
   * Returns the embed media token transform's destination filter plugin.
   *
   * @return string
   *   The embed media token transform's destination filter_plugin from
   *   settings.php.
   */
  public static function getEmbedTokenDestinationFilterPlugin() {
    return Settings::get(self::MEDIA_TOKEN_DESTINATION_FILTER_SETTINGS, self::MEDIA_TOKEN_DESTINATION_FILTER_DEFAULT);
  }

  /**
   * Whether the transform's destination filter_plugin is valid or not.
   *
   * @param string|null $filter_plugin_id
   *   The filter plugin ID to check.
   *
   * @return bool
   *   TRUE if the plugin is valid, FALSE if not.
   */
  public static function embedTokenDestinationFilterPluginIsValid($filter_plugin_id = NULL) {
    $valid_filter_plugin_ids = array_keys(self::MEDIA_TOKEN_DESTINATION_FILTER_REQUIREMENTS);
    $filter_plugin_id = $filter_plugin_id ?? self::getEmbedTokenDestinationFilterPlugin();
    return in_array($filter_plugin_id, $valid_filter_plugin_ids, TRUE);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MediaMigration::embedTokenDestinationFilterPluginIsValid public static function Whether the transform's destination filter_plugin is valid or not.
MediaMigration::EMBED_MEDIA_REFERENCE_METHOD_DEFAULT constant Default embedded media reference method.
MediaMigration::EMBED_MEDIA_REFERENCE_METHOD_ID constant The ID embedded media reference method.
MediaMigration::EMBED_MEDIA_REFERENCE_METHOD_UUID constant The UUID embedded media reference method.
MediaMigration::getEmbedMediaReferenceMethod public static function Sets the method of the embedded media reference.
MediaMigration::getEmbedTokenDestinationFilterPlugin public static function Returns the embed media token transform's destination filter plugin.
MediaMigration::MEDIA_REFERENCE_METHOD_SETTINGS constant The name of the setting of how embedded media should be referred.
MediaMigration::MEDIA_TOKEN_DESTINATION_FILTER_DEFAULT constant Default embed token destination filter plugin ID.
MediaMigration::MEDIA_TOKEN_DESTINATION_FILTER_ENTITY_EMBED constant Entity embed destination filter.
MediaMigration::MEDIA_TOKEN_DESTINATION_FILTER_MEDIA_EMBED constant Media embed destination filter.
MediaMigration::MEDIA_TOKEN_DESTINATION_FILTER_REQUIREMENTS constant The required modules of the valid destination filter plugins.
MediaMigration::MEDIA_TOKEN_DESTINATION_FILTER_SETTINGS constant The name of embed code transformation destination filter plugin setting.
MediaMigration::MEDIA_UUID_PROPHECY_SOURCEID_COL constant The name of the media source ID column.
MediaMigration::MEDIA_UUID_PROPHECY_TABLE constant The name of the media UUID prophecy table.
MediaMigration::MEDIA_UUID_PROPHECY_UUID_COL constant The name of the column that contains the destination UUID.
MediaMigration::MIGRATION_TAG_CONFIG constant Migration tag for media configuration migrations.
MediaMigration::MIGRATION_TAG_CONTENT constant Migration tag for media entity migrations.
MediaMigration::MIGRATION_TAG_MAIN constant Migration tag for every media related migrations.
MediaMigration::PCRE_PATTERN_LINKIT_FILE_LINK constant PCRE pattern of Linkit file links in (formatted) text fields.
MediaMigration::SQL_PATTERN_LINKIT_FILE_LINK constant SQL pattern of Linkit file links in (formatted) text fields.
MediaMigration::VALID_EMBED_MEDIA_REFERENCE_METHODS constant Valid embedded media reference methods.