19ca6a9a2a7b2d70b12db4510ce7813fdc8d944a
[yaffs-website] / web / modules / contrib / migrate_plus / src / Plugin / migrate / source / SourcePluginExtension.php
1 <?php
2
3 namespace Drupal\migrate_plus\Plugin\migrate\source;
4
5 use Drupal\migrate\Plugin\MigrationInterface;
6 use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
7
8 /**
9  * Generally-useful extensions to the core SourcePluginBase.
10  */
11 abstract class SourcePluginExtension extends SourcePluginBase {
12
13   /**
14    * Information on the source fields to be extracted from the data.
15    *
16    * @var array[]
17    *   Array of field information keyed by field names. A 'label' subkey
18    *   describes the field for migration tools; a 'path' subkey provides the
19    *   source-specific path for obtaining the value.
20    */
21   protected $fields = [];
22
23   /**
24    * Description of the unique ID fields for this source.
25    *
26    * @var array[]
27    *   Each array member is keyed by a field name, with a value that is an
28    *   array with a single member with key 'type' and value a column type such
29    *   as 'integer'.
30    */
31   protected $ids = [];
32
33   /**
34    * {@inheritdoc}
35    */
36   public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration) {
37     parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
38     $this->fields = $configuration['fields'];
39     $this->ids = $configuration['ids'];
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public function fields() {
46     $fields = [];
47     foreach ($this->fields as $field_info) {
48       $fields[$field_info['name']] = isset($field_info['label']) ? $field_info['label'] : $field_info['name'];
49     }
50     return $fields;
51   }
52
53   /**
54    * {@inheritdoc}
55    */
56   public function getIds() {
57     return $this->ids;
58   }
59
60 }