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