You are here

public function D7TaxonomyTermDeriver::getDerivativeDefinitions in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/taxonomy/src/Plugin/migrate/D7TaxonomyTermDeriver.php \Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver::getDerivativeDefinitions()
  2. 10 core/modules/taxonomy/src/Plugin/migrate/D7TaxonomyTermDeriver.php \Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver::getDerivativeDefinitions()

Gets the definition of all derivatives of a base plugin.

Parameters

array $base_plugin_definition: The definition array of the base plugin.

Return value

array An array of full derivative definitions keyed on derivative id.

Overrides DeriverBase::getDerivativeDefinitions

See also

getDerivativeDefinition()

File

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

Class

D7TaxonomyTermDeriver
Deriver for Drupal 7 taxonomy term migrations based on vocabularies.

Namespace

Drupal\taxonomy\Plugin\migrate

Code

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'] = 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;
}