1. 8.5.x core/modules/taxonomy/src/Plugin/migrate/source/Term.php
  2. 8.5.x core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php
  3. 8.5.x core/modules/taxonomy/src/Plugin/migrate/source/d6/Term.php
  4. 8.5.x core/modules/taxonomy/src/Entity/Term.php
  5. 8.5.x core/modules/taxonomy/src/Plugin/views/argument_validator/Term.php
  6. 8.0.x core/modules/taxonomy/src/Entity/Term.php
  7. 8.0.x core/modules/taxonomy/src/Plugin/views/argument_validator/Term.php
  8. 8.0.x core/modules/taxonomy/src/Plugin/migrate/source/Term.php
  9. 8.1.x core/modules/taxonomy/src/Plugin/migrate/source/Term.php
  10. 8.1.x core/modules/taxonomy/src/Plugin/views/argument_validator/Term.php
  11. 8.1.x core/modules/taxonomy/src/Entity/Term.php
  12. 8.2.x core/modules/taxonomy/src/Plugin/migrate/source/Term.php
  13. 8.2.x core/modules/taxonomy/src/Entity/Term.php
  14. 8.2.x core/modules/taxonomy/src/Plugin/migrate/source/d6/Term.php
  15. 8.2.x core/modules/taxonomy/src/Plugin/views/argument_validator/Term.php
  16. 8.2.x core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php
  17. 8.3.x core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php
  18. 8.3.x core/modules/taxonomy/src/Plugin/migrate/source/Term.php
  19. 8.3.x core/modules/taxonomy/src/Entity/Term.php
  20. 8.3.x core/modules/taxonomy/src/Plugin/migrate/source/d6/Term.php
  21. 8.3.x core/modules/taxonomy/src/Plugin/views/argument_validator/Term.php
  22. 8.4.x core/modules/taxonomy/src/Entity/Term.php
  23. 8.4.x core/modules/taxonomy/src/Plugin/migrate/source/d6/Term.php
  24. 8.4.x core/modules/taxonomy/src/Plugin/views/argument_validator/Term.php
  25. 8.4.x core/modules/taxonomy/src/Plugin/migrate/source/Term.php
  26. 8.4.x core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php
  27. 8.6.x core/modules/taxonomy/src/Plugin/migrate/source/d6/Term.php
  28. 8.6.x core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php
  29. 8.6.x core/modules/taxonomy/src/Plugin/migrate/source/Term.php
  30. 8.6.x core/modules/taxonomy/src/Entity/Term.php
  31. 8.6.x core/modules/taxonomy/src/Plugin/views/argument_validator/Term.php

Namespace

Drupal\taxonomy\Plugin\migrate\source\d7

File

core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php
View source
<?php

namespace Drupal\taxonomy\Plugin\migrate\source\d7;

use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;

/**
 * Taxonomy term source from database.
 *
 * @todo Support term_relation, term_synonym table if possible.
 *
 * @MigrateSource(
 *   id = "d7_taxonomy_term",
 *   source_provider = "taxonomy"
 * )
 */
class Term extends FieldableEntity {

  /**
   * {@inheritdoc}
   */
  public function query() {
    $query = $this
      ->select('taxonomy_term_data', 'td')
      ->fields('td')
      ->distinct()
      ->orderBy('tid');
    $query
      ->leftJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid');
    $query
      ->addField('tv', 'machine_name');
    if (isset($this->configuration['bundle'])) {
      $query
        ->condition('tv.machine_name', (array) $this->configuration['bundle'], 'IN');
    }
    return $query;
  }

  /**
   * {@inheritdoc}
   */
  public function fields() {
    $fields = [
      'tid' => $this
        ->t('The term ID.'),
      'vid' => $this
        ->t('Existing term VID'),
      'machine_name' => $this
        ->t('Vocabulary machine name'),
      'name' => $this
        ->t('The name of the term.'),
      'description' => $this
        ->t('The term description.'),
      'weight' => $this
        ->t('Weight'),
      'parent' => $this
        ->t("The Drupal term IDs of the term's parents."),
      'format' => $this
        ->t("Format of the term description."),
    ];
    return $fields;
  }

  /**
   * {@inheritdoc}
   */
  public function prepareRow(Row $row) {

    // Get Field API field values.
    foreach (array_keys($this
      ->getFields('taxonomy_term', $row
      ->getSourceProperty('machine_name'))) as $field) {
      $tid = $row
        ->getSourceProperty('tid');
      $row
        ->setSourceProperty($field, $this
        ->getFieldValues('taxonomy_term', $field, $tid));
    }

    // Find parents for this row.
    $parents = $this
      ->select('taxonomy_term_hierarchy', 'th')
      ->fields('th', [
      'parent',
      'tid',
    ])
      ->condition('tid', $row
      ->getSourceProperty('tid'))
      ->execute()
      ->fetchCol();
    $row
      ->setSourceProperty('parent', $parents);
    return parent::prepareRow($row);
  }

  /**
   * {@inheritdoc}
   */
  public function getIds() {
    $ids['tid']['type'] = 'integer';
    return $ids;
  }

}

Classes

Namesort descending Description
Term Taxonomy term source from database.