Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / taxonomy / src / Plugin / migrate / source / d6 / VocabularyPerType.php
1 <?php
2
3 namespace Drupal\taxonomy\Plugin\migrate\source\d6;
4
5 use Drupal\migrate\Row;
6
7 /**
8  * Gets all the vocabularies based on the node types that have Taxonomy enabled.
9  *
10  * @MigrateSource(
11  *   id = "d6_taxonomy_vocabulary_per_type",
12  *   source_module = "taxonomy"
13  * )
14  */
15 class VocabularyPerType extends Vocabulary {
16
17   /**
18    * {@inheritdoc}
19    */
20   public function query() {
21     $query = parent::query();
22     $query->join('vocabulary_node_types', 'nt', 'v.vid = nt.vid');
23     $query->fields('nt', ['type']);
24     return $query;
25   }
26
27   /**
28    * {@inheritdoc}
29    */
30   public function prepareRow(Row $row) {
31     // Get the i18n taxonomy translation setting for this vocabulary.
32     // 0 - No multilingual options
33     // 1 - Localizable terms. Run through the localization system.
34     // 2 - Predefined language for a vocabulary and its terms.
35     // 3 - Per-language terms, translatable (referencing terms with different
36     // languages) but not localizable.
37     $i18ntaxonomy_vocab = $this->variableGet('i18ntaxonomy_vocabulary', NULL);
38     $vid = $row->getSourceProperty('vid');
39     $i18ntaxonomy_vocabulary = FALSE;
40     if (array_key_exists($vid, $i18ntaxonomy_vocab)) {
41       $i18ntaxonomy_vocabulary = $i18ntaxonomy_vocab[$vid];
42     }
43     $row->setSourceProperty('i18ntaxonomy_vocabulary', $i18ntaxonomy_vocabulary);
44     return parent::prepareRow($row);
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   public function getIds() {
51     $ids['vid']['type'] = 'integer';
52     $ids['vid']['alias'] = 'nt';
53     $ids['type']['type'] = 'string';
54     return $ids;
55   }
56
57 }