Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / migrate / src / Plugin / migrate / process / Callback.php
1 <?php
2
3 namespace Drupal\migrate\Plugin\migrate\process;
4
5 use Drupal\migrate\MigrateExecutableInterface;
6 use Drupal\migrate\ProcessPluginBase;
7 use Drupal\migrate\Row;
8
9 /**
10  * Passes the source value to a callback.
11  *
12  * The callback process plugin allows simple processing of the value, such as
13  * strtolower(). The callable takes the source value as the single mandatory
14  * argument. No additional arguments can be passed to the callback.
15  *
16  * Available configuration keys:
17  * - callable: The name of the callable method.
18  *
19  * Examples:
20  *
21  * @code
22  * process:
23  *   destination_field:
24  *     plugin: callback
25  *     callable: strtolower
26  *     source: source_field
27  * @endcode
28  *
29  * An example where the callable is a static method in a class:
30  *
31  * @code
32  * process:
33  *   destination_field:
34  *     plugin: callback
35  *     callable:
36  *       - '\Drupal\Component\Utility\Unicode'
37  *       - strtolower
38  *     source: source_field
39  * @endcode
40  *
41  * @see \Drupal\migrate\Plugin\MigrateProcessInterface
42  *
43  * @MigrateProcessPlugin(
44  *   id = "callback"
45  * )
46  */
47 class Callback extends ProcessPluginBase {
48
49   /**
50    * {@inheritdoc}
51    */
52   public function __construct(array $configuration, $plugin_id, $plugin_definition) {
53     if (!isset($configuration['callable'])) {
54       throw new \InvalidArgumentException('The "callable" must be set.');
55     }
56     elseif (!is_callable($configuration['callable'])) {
57       throw new \InvalidArgumentException('The "callable" must be a valid function or method.');
58     }
59     parent::__construct($configuration, $plugin_id, $plugin_definition);
60   }
61
62   /**
63    * {@inheritdoc}
64    */
65   public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
66     return call_user_func($this->configuration['callable'], $value);
67   }
68
69 }