Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / migrate / src / Plugin / migrate / process / DefaultValue.php
1 <?php
2
3 namespace Drupal\migrate\Plugin\migrate\process;
4
5 use Drupal\migrate\ProcessPluginBase;
6 use Drupal\migrate\MigrateExecutableInterface;
7 use Drupal\migrate\Row;
8
9 /**
10  * Returns a given default value if the input is empty.
11  *
12  * The default_value process plugin provides the ability to set a fixed default
13  * value. The plugin returns a default value if the input value is considered
14  * empty (NULL, FALSE, 0, '0', an empty string, or an empty array). The strict
15  * configuration key can be used to set the default only when the incoming
16  * value is NULL.
17  *
18  * Available configuration keys:
19  * - default_value: The fixed default value to apply.
20  * - strict: (optional) Use strict value checking. Defaults to false.
21  *   - FALSE: Apply default when input value is empty().
22  *   - TRUE: Apply default when input value is NULL.
23  *
24  * Example:
25  *
26  * @code
27  * process:
28  *   uid:
29  *     -
30  *       plugin: migration_lookup
31  *       migration: users
32  *       source: author
33  *     -
34  *       plugin: default_value
35  *       default_value: 44
36  * @endcode
37  *
38  * This will look up the source value of author in the users migration and if
39  * not found, set the destination property uid to 44.
40  *
41  * @see \Drupal\migrate\Plugin\MigrateProcessInterface
42  *
43  * @MigrateProcessPlugin(
44  *   id = "default_value"
45  * )
46  */
47 class DefaultValue extends ProcessPluginBase {
48
49   /**
50    * {@inheritdoc}
51    */
52   public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
53     if (!empty($this->configuration['strict'])) {
54       return isset($value) ? $value : $this->configuration['default_value'];
55     }
56     return $value ?: $this->configuration['default_value'];
57   }
58
59 }