Version 1
[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 transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
53     if (is_callable($this->configuration['callable'])) {
54       $value = call_user_func($this->configuration['callable'], $value);
55     }
56     return $value;
57   }
58
59 }