You are here

function _metatag_is_migration_plugin_supported in Metatag 8

Check if a given migrate plugin should have Metatag's logic added.

Parameters

array $definition: The migration plugin definition to examine.

Return value

bool Indicates whether Metatag's custom migration logic should be added for this migrate plugin definition

See also

metatag_migration_plugins_alter()

1 call to _metatag_is_migration_plugin_supported()
metatag_migration_plugins_alter in ./metatag.module
Implements hook_migration_plugins_alter().

File

./metatag.module, line 927
Contains metatag.module.

Code

function _metatag_is_migration_plugin_supported(array $definition) {

  // Only run add the migration plugins when doing a "Drupal 7" migration. This
  // will catch standard core migrations but allow skipping this log for custom
  // migrations that do not have this tag.
  if (empty($definition['migration_tags'])) {
    return FALSE;
  }
  if (!is_array($definition['migration_tags'])) {
    return FALSE;
  }
  if (!array_intersect([
    'Drupal 6',
    'Drupal 7',
  ], $definition['migration_tags'])) {
    return FALSE;
  }

  // Support for migrate_upgrade module, to avoid adding dependencies on already
  // processed migration procedures.
  if (!empty($definition['migration_group'])) {
    return FALSE;
  }

  // This migration has destination plugins defined.
  if (!empty($definition['destination']['plugin'])) {

    // Follow logic on hook_entity_base_field_info() and exclude the metatag
    // entity itself, plus some others.
    $destinations_to_ignore = [
      'entity:metatag',
      'color',
      'component_entity_display',
      'component_entity_form_display',
      'config',
      'd7_theme_settings',
      'entity:base_field_override',
      'entity:block',
      'entity:block_content',
      'entity:block_content_type',
      'entity:comment',
      'entity:comment_type',
      'entity:contact_form',
      'entity:date_format',
      'entity:entity_view_mode',
      'entity:field_config',
      'entity:field_storage_config',
      'entity:filter_format',
      'entity:image_style',
      'entity:menu',
      'entity:menu_link_content',
      'entity:node_type',
      'entity:rdf_mapping',
      'entity:shortcut',
      'entity:shortcut_set',
      'entity:taxonomy_vocabulary',
      'entity:user_role',
      'shortcut_set_users',
      'url_alias',
      'user_data',
    ];
    if (in_array($definition['destination']['plugin'], $destinations_to_ignore)) {
      return FALSE;
    }
  }

  // Only support content entity destinations. Protect against situations where
  // the plugins haven't loaded yet, e.g. when using Commerce Migrate.
  try {
    $plugin_definition = \Drupal::service('plugin.manager.migrate.destination')
      ->getDefinition($definition['destination']['plugin']);
    $destination_plugin = DefaultFactory::getPluginClass($definition['destination']['plugin'], $plugin_definition);
    if (!is_subclass_of($destination_plugin, EntityContentBase::class) && $destination_plugin !== EntityContentBase::class) {
      return FALSE;
    }
  } catch (\Drupal\Component\Plugin\Exception\PluginNotFoundException $e) {

    // If the entity type doesn't exist, neither with the migration plugin.
    return FALSE;
  }

  // If this stage is reached then this is a supported core migration and the
  // Metatag migration will be automatically handled.
  return TRUE;
}