3 namespace Drupal\migrate\Plugin\migrate\process;
5 use Drupal\migrate\ProcessPluginBase;
6 use Drupal\migrate\MigrateExecutableInterface;
7 use Drupal\migrate\Row;
10 * Returns a given default value if the input is empty.
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
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.
30 * plugin: migration_lookup
34 * plugin: default_value
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.
41 * @see \Drupal\migrate\Plugin\MigrateProcessInterface
43 * @MigrateProcessPlugin(
44 * id = "default_value"
47 class DefaultValue extends ProcessPluginBase {
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'];
56 return $value ?: $this->configuration['default_value'];