Version 1
[yaffs-website] / web / modules / contrib / migrate_plus / src / Plugin / migrate / source / SourcePluginExtension.php
diff --git a/web/modules/contrib/migrate_plus/src/Plugin/migrate/source/SourcePluginExtension.php b/web/modules/contrib/migrate_plus/src/Plugin/migrate/source/SourcePluginExtension.php
new file mode 100644 (file)
index 0000000..19ca6a9
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+
+namespace Drupal\migrate_plus\Plugin\migrate\source;
+
+use Drupal\migrate\Plugin\MigrationInterface;
+use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
+
+/**
+ * Generally-useful extensions to the core SourcePluginBase.
+ */
+abstract class SourcePluginExtension extends SourcePluginBase {
+
+  /**
+   * Information on the source fields to be extracted from the data.
+   *
+   * @var array[]
+   *   Array of field information keyed by field names. A 'label' subkey
+   *   describes the field for migration tools; a 'path' subkey provides the
+   *   source-specific path for obtaining the value.
+   */
+  protected $fields = [];
+
+  /**
+   * Description of the unique ID fields for this source.
+   *
+   * @var array[]
+   *   Each array member is keyed by a field name, with a value that is an
+   *   array with a single member with key 'type' and value a column type such
+   *   as 'integer'.
+   */
+  protected $ids = [];
+
+  /**
+   * {@inheritdoc}
+   */
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration) {
+    parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
+    $this->fields = $configuration['fields'];
+    $this->ids = $configuration['ids'];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function fields() {
+    $fields = [];
+    foreach ($this->fields as $field_info) {
+      $fields[$field_info['name']] = isset($field_info['label']) ? $field_info['label'] : $field_info['name'];
+    }
+    return $fields;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getIds() {
+    return $this->ids;
+  }
+
+}