3 namespace Drupal\taxonomy\Plugin\migrate\source;
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
9 * Taxonomy term source from database.
11 * @todo Support term_relation, term_synonym table if possible.
14 * id = "taxonomy_term",
15 * source_provider = "taxonomy"
18 * @deprecated in Drupal 8.3.0, intended to be removed in Drupal 9.0.0.
19 * Use \Drupal\taxonomy\Plugin\migrate\source\d6\Term or
20 * \Drupal\taxonomy\Plugin\migrate\source\d7\Term.
22 * @see https://www.drupal.org/node/2879193
24 class Term extends DrupalSqlBase {
27 * Name of the term data table.
31 protected $termDataTable;
34 * Name of the term hierarchy table.
38 protected $termHierarchyTable;
43 public function query() {
44 if ($this->getModuleSchemaVersion('taxonomy') >= 7000) {
45 $this->termDataTable = 'taxonomy_term_data';
46 $this->termHierarchyTable = 'taxonomy_term_hierarchy';
49 $this->termDataTable = 'term_data';
50 $this->termHierarchyTable = 'term_hierarchy';
53 $query = $this->select($this->termDataTable, 'td')
58 if (isset($this->configuration['vocabulary'])) {
59 $query->condition('td.vid', (array) $this->configuration['vocabulary'], 'IN');
68 public function fields() {
70 'tid' => $this->t('The term ID.'),
71 'vid' => $this->t('Existing term VID'),
72 'name' => $this->t('The name of the term.'),
73 'description' => $this->t('The term description.'),
74 'weight' => $this->t('Weight'),
75 'parent' => $this->t("The Drupal term IDs of the term's parents."),
77 if ($this->getModuleSchemaVersion('taxonomy') >= 7000) {
78 $fields['format'] = $this->t('Format of the term description.');
86 public function prepareRow(Row $row) {
87 // Find parents for this row.
88 $parents = $this->select($this->termHierarchyTable, 'th')
89 ->fields('th', ['parent', 'tid'])
90 ->condition('tid', $row->getSourceProperty('tid'))
93 $row->setSourceProperty('parent', $parents);
95 return parent::prepareRow($row);
101 public function getIds() {
102 $ids['tid']['type'] = 'integer';