c3add91a6b791b59572ef9ce44820794278213c4
[yaffs-website] / web / core / modules / migrate / src / Plugin / migrate / source / EmptySource.php
1 <?php
2
3 namespace Drupal\migrate\Plugin\migrate\source;
4
5 /**
6  * Source returning a row based on the constants provided.
7  *
8  * Example:
9  *
10  * @code
11  * source:
12  *   plugin: empty
13  *   constants:
14  *     entity_type: user
15  *     field_name: image
16  * @endcode
17  *
18  * This will return a single row containing 'entity_type' and 'field_name'
19  * elements, with values of 'user' and 'image', respectively.
20  *
21  * @MigrateSource(
22  *   id = "empty",
23  *   source_module = "migrate"
24  * )
25  */
26 class EmptySource extends SourcePluginBase {
27
28   /**
29    * {@inheritdoc}
30    */
31   public function fields() {
32     return [
33       'id' => t('ID'),
34     ];
35   }
36
37   /**
38    * {@inheritdoc}
39    */
40   public function initializeIterator() {
41     return new \ArrayIterator([['id' => '']]);
42   }
43
44   /**
45    * Allows class to decide how it will react when it is treated like a string.
46    */
47   public function __toString() {
48     return '';
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   public function getIds() {
55     $ids['id']['type'] = 'string';
56     return $ids;
57   }
58
59   /**
60    * {@inheritdoc}
61    */
62   public function count($refresh = FALSE) {
63     return 1;
64   }
65
66 }