You are here

class TermNode in Zircon Profile 8

Same name in this branch
  1. 8 core/modules/taxonomy/src/Plugin/migrate/source/d6/TermNode.php \Drupal\taxonomy\Plugin\migrate\source\d6\TermNode
  2. 8 core/modules/taxonomy/src/Plugin/migrate/builder/d6/TermNode.php \Drupal\taxonomy\Plugin\migrate\builder\d6\TermNode
Same name and namespace in other branches
  1. 8.0 core/modules/taxonomy/src/Plugin/migrate/builder/d6/TermNode.php \Drupal\taxonomy\Plugin\migrate\builder\d6\TermNode

Plugin annotation

@PluginID("d6_term_node");

Hierarchy

Expanded class hierarchy of TermNode

File

core/modules/taxonomy/src/Plugin/migrate/builder/d6/TermNode.php, line 21
Contains \Drupal\taxonomy\Plugin\migrate\builder\d6\TermNode.

Namespace

Drupal\taxonomy\Plugin\migrate\builder\d6
View source
class TermNode extends BuilderBase implements ContainerFactoryPluginInterface {

  /**
   * The migration template storage service.
   *
   * @var \Drupal\migrate\MigrateTemplateStorage
   */
  protected $templateStorage;

  /**
   * Constructs a TermNode builder.
   *
   * @param array $configuration
   *   Plugin configuration.
   * @param string $plugin_id
   *   The plugin ID.
   * @param mixed $plugin_definition
   *   The plugin definition.
   * @param \Drupal\migrate\MigrateTemplateStorage $template_storage
   *   The migration template storage handler.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateTemplateStorage $template_storage) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->templateStorage = $template_storage;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('migrate.template_storage'));
  }

  /**
   * Builds a map of source vocabulary IDs to expected destination IDs.
   *
   * @param array $source
   *   Additional configuration for the d6_taxonomy_vocabulary source.
   *
   * @return array
   *   The vid map. The keys are the source IDs and the values are the
   *   (expected) destination IDs.
   */
  protected function getVocabularyIdMap(array $source) {
    $map = [];
    $template = $this->templateStorage
      ->getTemplateByName('d6_taxonomy_vocabulary');
    $template['source'] += $source;
    $migration = Migration::create($template);
    $executable = new MigrateExecutable($migration, new MigrateMessage());

    // Only process the destination ID properties.
    $process = array_intersect_key($template['process'], $migration
      ->getDestinationPlugin()
      ->getIds());
    foreach ($migration
      ->getSourcePlugin() as $source_row) {

      // Process the row to generate the expected destination ID.
      $executable
        ->processRow($source_row, $process);
      $map[$source_row
        ->getSourceProperty('vid')] = $source_row
        ->getDestinationProperty('vid');
    }
    return $map;
  }

  /**
   * {@inheritdoc}
   */
  public function buildMigrations(array $template) {
    $migrations = [];
    foreach ($this
      ->getVocabularyIdMap($template['source']) as $source_vid => $destination_vid) {
      $values = $template;
      $values['id'] .= '__' . $source_vid;
      $values['source']['vid'] = $source_vid;
      $migration = Migration::create($values);
      $migration
        ->setProcessOfProperty($destination_vid, 'tid');
      $migrations[] = $migration;
    }
    return $migrations;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BuilderBase::getSourcePlugin protected function Returns a fully initialized instance of a source plugin.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
PluginBase::$configuration protected property Configuration information passed into the plugin. 2
PluginBase::$pluginDefinition protected property The plugin implementation definition.
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
StringTranslationTrait::$stringTranslation protected property The string translation service.
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.
TermNode::$templateStorage protected property The migration template storage service.
TermNode::buildMigrations public function Builds migration entities based on a template. Overrides MigrateBuilderInterface::buildMigrations
TermNode::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
TermNode::getVocabularyIdMap protected function Builds a map of source vocabulary IDs to expected destination IDs.
TermNode::__construct public function Constructs a TermNode builder. Overrides PluginBase::__construct