Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / field / src / Plugin / migrate / source / d6 / FieldOptionTranslation.php
diff --git a/web/core/modules/field/src/Plugin/migrate/source/d6/FieldOptionTranslation.php b/web/core/modules/field/src/Plugin/migrate/source/d6/FieldOptionTranslation.php
new file mode 100644 (file)
index 0000000..bc2671a
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+
+namespace Drupal\field\Plugin\migrate\source\d6;
+
+/**
+ * Gets field option label translations.
+ *
+ * @MigrateSource(
+ *   id = "d6_field_option_translation",
+ *   source_module = "i18ncck"
+ * )
+ */
+class FieldOptionTranslation extends Field {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function query() {
+    // Get the fields that have field options translations.
+    $query = $this->select('i18n_strings', 'i18n')
+      ->fields('i18n')
+      ->fields('lt', [
+        'translation',
+        'language',
+        'plid',
+        'plural',
+        'i18n_status',
+      ])
+      ->condition('i18n.type', 'field')
+      ->condition('property', 'option\_%', 'LIKE')
+      ->isNotNull('translation');
+    $query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
+    $query->leftjoin('content_node_field', 'cnf', 'cnf.field_name = i18n.objectid');
+    $query->addField('cnf', 'field_name');
+    $query->addField('cnf', 'global_settings');
+    // Minimise changes to the d6_field_option_translation.yml, which is copied
+    // from d6_field.yml, by ensuring the 'type' property is from
+    // content_node_field table.
+    $query->addField('cnf', 'type');
+    $query->addField('i18n', 'type', 'i18n_type');
+
+    return $query;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function fields() {
+    $fields = [
+      'property' => $this->t('Option ID.'),
+      'objectid' => $this->t('Object ID'),
+      'objectindex' => $this->t('Integer value of Object ID'),
+      'format' => $this->t('The input format used by this string'),
+      'lid' => $this->t('Source string ID'),
+      'language' => $this->t('Language code'),
+      'translation' => $this->t('Translation of the option'),
+      'plid' => $this->t('Parent lid'),
+      'plural' => $this->t('Plural index number in case of plural strings'),
+    ];
+    return parent::fields() + $fields;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getIds() {
+    return parent::getIds() +
+      [
+        'language' => ['type' => 'string'],
+        'property' => ['type' => 'string'],
+      ];
+  }
+
+}