Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / migrate_plus / src / Plugin / migrate / process / ArrayShift.php
1 <?php
2
3 namespace Drupal\migrate_plus\Plugin\migrate\process;
4
5 use Drupal\migrate\MigrateException;
6 use Drupal\migrate\MigrateExecutableInterface;
7 use Drupal\migrate\ProcessPluginBase;
8 use Drupal\migrate\Row;
9
10 /**
11  * Performs an array_shift() on a source array.
12  *
13  * @MigrateProcessPlugin(
14  *   id = "array_shift",
15  *   handle_multiples = TRUE
16  * )
17  *
18  * The "extract" plugin in core can extract array values when indexes are
19  * already known. This plugin helps extract the first value in an array by
20  * performing a "shift" operation.
21  *
22  * Example: Say, the migration source has an associative array of names in
23  * a property called "authors" and the keys in the array can vary, you
24  * can extract the first value like this:
25  *
26  * @code
27  *   first_author:
28  *     plugin: array_shift
29  *     source: authors
30  * @endcode
31  */
32 class ArrayShift extends ProcessPluginBase {
33
34   /**
35    * {@inheritdoc}
36    */
37   public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
38     if (!is_array($value)) {
39       throw new MigrateException('Input should be an array.');
40     }
41     return array_shift($value);
42   }
43
44 }