class D7TaxonomyTermDeriver

Same name and namespace in other branches
  1. 9 core/modules/taxonomy/src/Plugin/migrate/D7TaxonomyTermDeriver.php \Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver
  2. 8.9.x core/modules/taxonomy/src/Plugin/migrate/D7TaxonomyTermDeriver.php \Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver
  3. 10 core/modules/taxonomy/src/Plugin/migrate/D7TaxonomyTermDeriver.php \Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver

Deriver for Drupal 7 taxonomy term migrations based on vocabularies.

Hierarchy

Expanded class hierarchy of D7TaxonomyTermDeriver

2 string references to 'D7TaxonomyTermDeriver'
d7_taxonomy_term.yml in core/modules/taxonomy/migrations/d7_taxonomy_term.yml
core/modules/taxonomy/migrations/d7_taxonomy_term.yml
d7_taxonomy_term_entity_translation.yml in core/modules/content_translation/migrations/d7_taxonomy_term_entity_translation.yml
core/modules/content_translation/migrations/d7_taxonomy_term_entity_translation.yml

File

core/modules/taxonomy/src/Plugin/migrate/D7TaxonomyTermDeriver.php, line 17

Namespace

Drupal\taxonomy\Plugin\migrate
View source
class D7TaxonomyTermDeriver extends DeriverBase implements ContainerDeriverInterface {
    use MigrationDeriverTrait;
    use StringTranslationTrait;
    
    /**
     * The base plugin ID this derivative is for.
     *
     * @var string
     */
    protected $basePluginId;
    
    /**
     * The migration field discovery service.
     *
     * @var \Drupal\migrate_drupal\FieldDiscoveryInterface
     */
    protected $fieldDiscovery;
    
    /**
     * D7TaxonomyTermDeriver constructor.
     *
     * @param string $base_plugin_id
     *   The base plugin ID for the plugin ID.
     * @param \Drupal\migrate_drupal\FieldDiscoveryInterface $field_discovery
     *   The migration field discovery service.
     */
    public function __construct($base_plugin_id, FieldDiscoveryInterface $field_discovery) {
        $this->basePluginId = $base_plugin_id;
        $this->fieldDiscovery = $field_discovery;
    }
    
    /**
     * {@inheritdoc}
     */
    public static function create(ContainerInterface $container, $base_plugin_id) {
        return new static($base_plugin_id, $container->get('migrate_drupal.field_discovery'));
    }
    
    /**
     * {@inheritdoc}
     */
    public function getDerivativeDefinitions($base_plugin_definition) {
        $vocabulary_source_plugin = static::getSourcePlugin('d7_taxonomy_vocabulary');
        try {
            $vocabulary_source_plugin->checkRequirements();
        } catch (RequirementsException $e) {
            // If the d7_taxonomy_vocabulary requirements failed, that means we do not
            // have a Drupal source database configured - there is nothing to
            // generate.
            return $this->derivatives;
        }
        try {
            foreach ($vocabulary_source_plugin as $row) {
                $bundle = $row->getSourceProperty('machine_name');
                $values = $base_plugin_definition;
                $values['label'] = $this->t('@label (@type)', [
                    '@label' => $values['label'],
                    '@type' => $row->getSourceProperty('name'),
                ]);
                $values['source']['bundle'] = $bundle;
                $values['destination']['default_bundle'] = $bundle;
                
                /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
                $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($values);
                $this->fieldDiscovery
                    ->addBundleFieldProcesses($migration, 'taxonomy_term', $bundle);
                $this->derivatives[$bundle] = $migration->getPluginDefinition();
            }
        } catch (DatabaseExceptionWrapper $e) {
            // Once we begin iterating the source plugin it is possible that the
            // source tables will not exist. This can happen when the
            // MigrationPluginManager gathers up the migration definitions but we do
            // not actually have a Drupal 7 source database.
        }
        return $this->derivatives;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
D7TaxonomyTermDeriver::$basePluginId protected property The base plugin ID this derivative is for.
D7TaxonomyTermDeriver::$fieldDiscovery protected property The migration field discovery service.
D7TaxonomyTermDeriver::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
D7TaxonomyTermDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
D7TaxonomyTermDeriver::__construct public function D7TaxonomyTermDeriver constructor.
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
MigrationDeriverTrait::getSourcePlugin public static function Returns a fully initialized instance of a source plugin.
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
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.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.