Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / migrate / tests / modules / migrate_external_translated_test / src / Plugin / migrate / source / MigrateExternalTranslatedTestSource.php
1 <?php
2
3 namespace Drupal\migrate_external_translated_test\Plugin\migrate\source;
4
5 use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
6
7 /**
8  * A simple migrate source for our tests.
9  *
10  * @MigrateSource(
11  *   id = "migrate_external_translated_test",
12  *   source_module = "migrate_external_translated_test"
13  * )
14  */
15 class MigrateExternalTranslatedTestSource extends SourcePluginBase {
16
17   /**
18    * The data to import.
19    *
20    * @var array
21    */
22   protected $import = [
23     ['name' => 'cat', 'title' => 'Cat', 'lang' => 'English'],
24     ['name' => 'cat', 'title' => 'Chat', 'lang' => 'French'],
25     ['name' => 'cat', 'title' => 'Gato', 'lang' => 'Spanish'],
26     ['name' => 'dog', 'title' => 'Dog', 'lang' => 'English'],
27     ['name' => 'dog', 'title' => 'Chien', 'lang' => 'French'],
28     ['name' => 'monkey', 'title' => 'Monkey', 'lang' => 'English'],
29   ];
30
31   /**
32    * {@inheritdoc}
33    */
34   public function fields() {
35     return [
36       'name' => $this->t('Unique name'),
37       'title' => $this->t('Title'),
38       'lang' => $this->t('Language'),
39     ];
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public function __toString() {
46     return '';
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function getIds() {
53     $ids['name']['type'] = 'string';
54     if (!$this->configuration['default_lang']) {
55       $ids['lang']['type'] = 'string';
56     }
57     return $ids;
58   }
59
60   /**
61    * {@inheritdoc}
62    */
63   protected function initializeIterator() {
64     $data = [];
65
66     // Keep the rows with the right languages.
67     $want_default = $this->configuration['default_lang'];
68     foreach ($this->import as $row) {
69       $is_english = $row['lang'] == 'English';
70       if ($want_default == $is_english) {
71         $data[] = $row;
72       }
73     }
74
75     return new \ArrayIterator($data);
76   }
77
78 }