You are here

class MetatagFieldDeriver in Metatag 8

@todo.

Hierarchy

Expanded class hierarchy of MetatagFieldDeriver

1 string reference to 'MetatagFieldDeriver'
d7_metatag_field.yml in migrations/d7_metatag_field.yml
migrations/d7_metatag_field.yml

File

src/Plugin/migrate/source/d7/MetatagFieldDeriver.php, line 20

Namespace

Drupal\metatag\Plugin\migrate\source\d7
View source
class MetatagFieldDeriver extends DeriverBase implements ContainerDeriverInterface {
  use MigrationDeriverTrait;
  use MigrationConfigurationTrait;
  use StringTranslationTrait;

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

  /**
   * Constructs a MetatagFieldDeriver instance.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

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

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $source = $this
      ->getSourcePlugin('d7_metatag_field');
    assert($source instanceof DrupalSqlBase);
    try {
      $source
        ->checkRequirements();
    } catch (RequirementsException $e) {

      // If the source plugin requirements failed, that means we do not have a
      // Drupal source database configured - return nothing.
      return $this->derivatives;
    }
    $entity_type_ids = $source
      ->getDatabase()
      ->select('metatag', 'm')
      ->fields('m', [
      'entity_type',
    ])
      ->distinct()
      ->execute()
      ->fetchAllKeyed(0, 0);
    foreach ($entity_type_ids as $entity_type_id) {

      // Skip if the entity type is missing.
      if (!($entity_type_definition = $this->entityTypeManager
        ->getDefinition($entity_type_id, FALSE))) {
        continue;
      }
      $this->derivatives[$entity_type_id] = $base_plugin_definition;
      $this->derivatives[$entity_type_id]['source']['entity_type'] = $entity_type_id;
      $this->derivatives[$entity_type_id]['source']['entity_type_id'] = $entity_type_id;
      $this->derivatives[$entity_type_id]['label'] = $this
        ->t('@label of @type', [
        '@label' => $base_plugin_definition['label'],
        '@type' => $this->entityTypeManager
          ->getDefinition($entity_type_id)
          ->getPluralLabel(),
      ]);
    }
    return $this->derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
MetatagFieldDeriver::$entityTypeManager protected property The entity type manager.
MetatagFieldDeriver::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
MetatagFieldDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
MetatagFieldDeriver::__construct public function Constructs a MetatagFieldDeriver instance.
MigrationConfigurationTrait::$configFactory protected property The config factory service.
MigrationConfigurationTrait::$followUpMigrationTags protected property The follow-up migration tags.
MigrationConfigurationTrait::$migrationPluginManager protected property The migration plugin manager service.
MigrationConfigurationTrait::$state protected property The state service.
MigrationConfigurationTrait::createDatabaseStateSettings protected function Creates the necessary state entries for SqlBase::getDatabase() to work.
MigrationConfigurationTrait::getConfigFactory protected function Gets the config factory service.
MigrationConfigurationTrait::getConnection protected function Gets the database connection for the source Drupal database.
MigrationConfigurationTrait::getFollowUpMigrationTags protected function Returns the follow-up migration tags.
MigrationConfigurationTrait::getLegacyDrupalVersion public static function Determines what version of Drupal the source database contains.
MigrationConfigurationTrait::getMigrationPluginManager protected function Gets the migration plugin manager service.
MigrationConfigurationTrait::getMigrations protected function Gets the migrations for import.
MigrationConfigurationTrait::getState protected function Gets the state service.
MigrationConfigurationTrait::getSystemData protected function Gets the system data from the system table of the source Drupal database.
MigrationDeriverTrait::getSourcePlugin public static function Returns a fully initialized instance of a source plugin.
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.