Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / taxonomy / src / Plugin / migrate / source / d6 / Vocabulary.php
1 <?php
2
3 namespace Drupal\taxonomy\Plugin\migrate\source\d6;
4
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
7 use Drupal\Core\Field\FieldStorageDefinitionInterface;
8
9 /**
10  * Drupal 6 vocabularies source from database.
11  *
12  * @MigrateSource(
13  *   id = "d6_taxonomy_vocabulary",
14  *   source_provider = "taxonomy"
15  * )
16  */
17 class Vocabulary extends DrupalSqlBase {
18
19   /**
20    * {@inheritdoc}
21    */
22   public function query() {
23     $query = $this->select('vocabulary', 'v')
24       ->fields('v', [
25         'vid',
26         'name',
27         'description',
28         'help',
29         'relations',
30         'hierarchy',
31         'multiple',
32         'required',
33         'tags',
34         'module',
35         'weight',
36       ]);
37     return $query;
38   }
39
40   /**
41    * {@inheritdoc}
42    */
43   public function fields() {
44     return [
45       'vid' => $this->t('The vocabulary ID.'),
46       'name' => $this->t('The name of the vocabulary.'),
47       'description' => $this->t('The description of the vocabulary.'),
48       'help' => $this->t('Help text to display for the vocabulary.'),
49       'relations' => $this->t('Whether or not related terms are enabled within the vocabulary. (0 = disabled, 1 = enabled)'),
50       'hierarchy' => $this->t('The type of hierarchy allowed within the vocabulary. (0 = disabled, 1 = single, 2 = multiple)'),
51       'multiple' => $this->t('Whether or not multiple terms from this vocabulary may be assigned to a node. (0 = disabled, 1 = enabled)'),
52       'required' => $this->t('Whether or not terms are required for nodes using this vocabulary. (0 = disabled, 1 = enabled)'),
53       'tags' => $this->t('Whether or not free tagging is enabled for the vocabulary. (0 = disabled, 1 = enabled)'),
54       'weight' => $this->t('The weight of the vocabulary in relation to other vocabularies.'),
55       'parents' => $this->t("The Drupal term IDs of the term's parents."),
56       'node_types' => $this->t('The names of the node types the vocabulary may be used with.'),
57     ];
58   }
59
60   /**
61    * {@inheritdoc}
62    */
63   public function prepareRow(Row $row) {
64     // Find node types for this row.
65     $node_types = $this->select('vocabulary_node_types', 'nt')
66       ->fields('nt', ['type', 'vid'])
67       ->condition('vid', $row->getSourceProperty('vid'))
68       ->execute()
69       ->fetchCol();
70     $row->setSourceProperty('node_types', $node_types);
71     $row->setSourceProperty('cardinality', ($row->getSourceProperty('tags') == 1 || $row->getSourceProperty('multiple') == 1) ? FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED : 1);
72     return parent::prepareRow($row);
73   }
74
75   /**
76    * {@inheritdoc}
77    */
78   public function getIds() {
79     $ids['vid']['type'] = 'integer';
80     return $ids;
81   }
82
83 }