3 namespace Drupal\taxonomy\Plugin\migrate\source\d7;
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
9 * Taxonomy term source from database.
11 * @todo Support term_relation, term_synonym table if possible.
14 * id = "d7_taxonomy_term",
15 * source_module = "taxonomy"
18 class Term extends FieldableEntity {
23 public function query() {
24 $query = $this->select('taxonomy_term_data', 'td')
28 $query->leftJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid');
29 $query->addField('tv', 'machine_name');
31 if (isset($this->configuration['bundle'])) {
32 $query->condition('tv.machine_name', (array) $this->configuration['bundle'], 'IN');
41 public function fields() {
43 'tid' => $this->t('The term ID.'),
44 'vid' => $this->t('Existing term VID'),
45 'machine_name' => $this->t('Vocabulary machine name'),
46 'name' => $this->t('The name of the term.'),
47 'description' => $this->t('The term description.'),
48 'weight' => $this->t('Weight'),
49 'parent' => $this->t("The Drupal term IDs of the term's parents."),
50 'format' => $this->t("Format of the term description."),
58 public function prepareRow(Row $row) {
59 // Get Field API field values.
60 foreach (array_keys($this->getFields('taxonomy_term', $row->getSourceProperty('machine_name'))) as $field) {
61 $tid = $row->getSourceProperty('tid');
62 $row->setSourceProperty($field, $this->getFieldValues('taxonomy_term', $field, $tid));
65 // Find parents for this row.
66 $parents = $this->select('taxonomy_term_hierarchy', 'th')
67 ->fields('th', ['parent', 'tid'])
68 ->condition('tid', $row->getSourceProperty('tid'))
71 $row->setSourceProperty('parent', $parents);
73 // Determine if this is a forum container.
74 $forum_container_tids = $this->variableGet('forum_containers', []);
75 $current_tid = $row->getSourceProperty('tid');
76 $row->setSourceProperty('is_container', in_array($current_tid, $forum_container_tids));
78 return parent::prepareRow($row);
84 public function getIds() {
85 $ids['tid']['type'] = 'integer';