480e5ed4938f573d899df855dc246a0797fb44e4
[yaffs-website] / web / core / modules / migrate / src / Plugin / MigrateSourceInterface.php
1 <?php
2
3 namespace Drupal\migrate\Plugin;
4
5 use Drupal\Component\Plugin\PluginInspectionInterface;
6 use Drupal\migrate\Row;
7
8 /**
9  * Defines an interface for migrate sources.
10  *
11  * @see \Drupal\migrate\Plugin\MigratePluginManager
12  * @see \Drupal\migrate\Annotation\MigrateSource
13  * @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
14  * @see plugin_api
15  *
16  * @ingroup migration
17  */
18 interface MigrateSourceInterface extends \Countable, \Iterator, PluginInspectionInterface {
19
20   /**
21    * Returns available fields on the source.
22    *
23    * @return array
24    *   Available fields in the source, keys are the field machine names as used
25    *   in field mappings, values are descriptions.
26    */
27   public function fields();
28
29   /**
30    * Adds additional data to the row.
31    *
32    * @param \Drupal\Migrate\Row $row
33    *   The row object.
34    *
35    * @return bool
36    *   FALSE if this row needs to be skipped.
37    */
38   public function prepareRow(Row $row);
39
40   /**
41    * Allows class to decide how it will react when it is treated like a string.
42    */
43   public function __toString();
44
45   /**
46    * Defines the source fields uniquely identifying a source row.
47    *
48    * None of these fields should contain a NULL value. If necessary, use
49    * prepareRow() or hook_migrate_prepare_row() to rewrite NULL values to
50    * appropriate empty values (such as '' or 0).
51    *
52    * @return array[]
53    *   An associative array of field definitions keyed by field ID. Values are
54    *   associative arrays with a structure that contains the field type ('type'
55    *   key). The other keys are the field storage settings as they are returned
56    *   by FieldStorageDefinitionInterface::getSettings().
57    *
58    *   Examples:
59    *
60    *   A composite source primary key that is defined by an integer and a string
61    *   might look like this:
62    *   @code
63    *     return [
64    *       'id' => [
65    *         'type' => 'integer',
66    *         'unsigned' => FALSE,
67    *         'size' => 'big',
68    *       ],
69    *       'version' => [
70    *         'type' => 'string',
71    *         'max_length' => 64,
72    *         'is_ascii' => TRUE,
73    *       ],
74    *     ];
75    *   @endcode
76    *
77    *   If 'type' points to a field plugin with multiple columns and needs to
78    *   refer to a column different than 'value', the key of that column will be
79    *   appended as a suffix to the plugin name, separated by dot ('.'). Example:
80    *   @code
81    *     return [
82    *       'format' => [
83    *         'type' => 'text.format',
84    *       ],
85    *     ];
86    *   @endcode
87    *
88    *   Additional custom keys/values that are not part of field storage
89    *   definition can be added as shown below. The most common setting
90    *   passed along to the ID definition is 'alias', used by the SqlBase source
91    *   plugin in order to distinguish between ambiguous column names - for
92    *   example, when a SQL source query joins two tables with the same column
93    *   names.
94    *   @code
95    *     return [
96    *       'nid' => [
97    *         'type' => 'integer',
98    *         'alias' => 'n',
99    *       ],
100    *     ];
101    *   @endcode
102    *
103    * @see \Drupal\Core\Field\FieldStorageDefinitionInterface::getSettings()
104    * @see \Drupal\Core\Field\Plugin\Field\FieldType\IntegerItem
105    * @see \Drupal\Core\Field\Plugin\Field\FieldType\StringItem
106    * @see \Drupal\text\Plugin\Field\FieldType\TextItem
107    * @see \Drupal\migrate\Plugin\migrate\source\SqlBase
108    */
109   public function getIds();
110
111   /**
112    * Gets the source module providing the source data.
113    *
114    * @return string|null
115    *   The source module or NULL if not found.
116    */
117   public function getSourceModule();
118
119 }