Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / language / src / Plugin / migrate / source / Language.php
1 <?php
2
3 namespace Drupal\language\Plugin\migrate\source;
4
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
7
8 /**
9  * @MigrateSource(
10  *   id = "language",
11  *   source_module = "locale"
12  * )
13  */
14 class Language extends DrupalSqlBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   public function fields() {
20     return [
21       'language' => $this->t('The language code.'),
22       'name' => $this->t('The English name of the language.'),
23       'native' => $this->t('The native name of the language.'),
24       'direction' => $this->t('The language direction. (0 = LTR, 1 = RTL)'),
25       'enabled' => $this->t('Whether the language is enabled.'),
26       'plurals' => $this->t('Number of plural indexes in this language.'),
27       'formula' => $this->t('PHP formula to get plural indexes.'),
28       'domain' => $this->t('Domain to use for this language.'),
29       'prefix' => $this->t('Path prefix used for this language.'),
30       'weight' => $this->t('The language weight when listed.'),
31       'javascript' => $this->t('Location of the JavaScript translation file.'),
32     ];
33   }
34
35   /**
36    * {@inheritdoc}
37    */
38   public function getIds() {
39     return [
40       'language' => [
41         'type' => 'string',
42       ],
43     ];
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function query() {
50     return $this->select('languages')->fields('languages');
51   }
52
53   /**
54    * {@inheritdoc}
55    */
56   public function prepareRow(Row $row) {
57     if (!empty($this->configuration['fetch_all'])) {
58       // Get an array of all languages.
59       $languages = $this->query()->execute()->fetchAll();
60       $row->setSourceProperty('languages', $languages);
61     }
62
63     if (!empty($this->configuration['domain_negotiation'])) {
64       // Check if domain negotiation is used to be able to fill in the default
65       // language domain, which may be empty. In D6, domain negotiation is used
66       // when the 'language_negotiation' variable is set to '3', and in D7, when
67       // the 'locale_language_negotiation_url_part' variable is set to '1'.
68       if ($this->variableGet('language_negotiation', 0) == 3 || $this->variableGet('locale_language_negotiation_url_part', 0) == 1) {
69         $row->setSourceProperty('domain_negotiation_used', TRUE);
70       }
71     }
72
73     return parent::prepareRow($row);
74   }
75
76 }