3 namespace Drupal\migrate_external_translated_test\Plugin\migrate\source;
5 use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
8 * A simple migrate source for our tests.
11 * id = "migrate_external_translated_test",
12 * source_module = "migrate_external_translated_test"
15 class MigrateExternalTranslatedTestSource extends SourcePluginBase {
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'],
34 public function fields() {
36 'name' => $this->t('Unique name'),
37 'title' => $this->t('Title'),
38 'lang' => $this->t('Language'),
45 public function __toString() {
52 public function getIds() {
53 $ids['name']['type'] = 'string';
54 if (!$this->configuration['default_lang']) {
55 $ids['lang']['type'] = 'string';
63 protected function initializeIterator() {
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) {
75 return new \ArrayIterator($data);