3 namespace Drupal\migrate\Plugin\migrate\source;
5 use Drupal\migrate\Plugin\MigrationInterface;
8 * Allows source data to be defined in the configuration of the source plugin.
10 * The embedded_data source plugin is used to inject source data from the plugin
11 * configuration. One use case is when some small amount of fixed data is
12 * imported, so that it can be referenced by other migrations. Another use case
15 * Available configuration keys
16 * - data_rows: The source data array.
17 * - ids: The unique ID field of the data.
23 * plugin: embedded_data
26 * channel_machine_name: music
27 * channel_description: Music
29 * channel_machine_name: movies
30 * channel_description: Movies
32 * channel_machine_name:
36 * This example migrates a channel vocabulary.
38 * @see \Drupal\migrate\Plugin\MigrateSourceInterface
41 * id = "embedded_data",
42 * source_module = "migrate"
45 class EmbeddedDataSource extends SourcePluginBase {
48 * Data obtained from the source plugin configuration.
51 * Array of data rows, each one an array of values keyed by field names.
53 protected $dataRows = [];
56 * Description of the unique ID fields for this source.
59 * Each array member is keyed by a field name, with a value that is an
60 * array with a single member with key 'type' and value a column type such
68 public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration) {
69 parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
70 $this->dataRows = $configuration['data_rows'];
71 $this->ids = $configuration['ids'];
77 public function fields() {
78 if ($this->count() > 0) {
79 $first_row = reset($this->dataRows);
80 $field_names = array_keys($first_row);
81 return array_combine($field_names, $field_names);
91 public function initializeIterator() {
92 return new \ArrayIterator($this->dataRows);
98 public function __toString() {
99 return 'Embedded data';
105 public function getIds() {
112 public function count($refresh = FALSE) {
113 return count($this->dataRows);