diff --git a/core/modules/migrate/src/Plugin/migrate/process/Concat.php b/core/modules/migrate/src/Plugin/migrate/process/Concat.php index 0a03ed5..e394147 100644 --- a/core/modules/migrate/src/Plugin/migrate/process/Concat.php +++ b/core/modules/migrate/src/Plugin/migrate/process/Concat.php @@ -16,7 +16,7 @@ * Available configuration keys: * - delimiter: (optional) A delimiter, or glue string, to insert between the * strings. - * - allow_empty: (optional) If set, empty values will be included in the + * - exclude_empty: (optional) If set, empty values will be excluded from the * output. Defaults to FALSE. * * Examples: @@ -51,7 +51,7 @@ * and "/" as the delimiter, if the 'foo' property is "wambooli" and the 'bar' * property is "pastafazoul", new_text_field will be "wambooli/pastafazoul". * - * You can also choose to allow empty values to be included in the output. + * You can also choose to exclude empty values from the output. * * @code * process: @@ -61,13 +61,27 @@ * - foo * - bar * - oof - * allow_empty: TRUE * delimiter: / * @endcode * - * In the example above, if the 'foo' property is "wambooli" and the 'bar' - * property is NULL and the 'oof' property is "pastafazoul", with a delimiter of - * "/", new_text_field will be "wambooli//pastafazoul". + * For example, if the 'foo' property is "wambooli" and the 'bar' property is + * NULL and the 'oof' property is "pastafazoul", with a delimiter of "/", + * new_text_field will be "wambooli//pastafazoul". + * + * @code + * process: + * new_text_field: + * plugin: concat + * source: + * - foo + * - bar + * - oof + * exclude_empty: TRUE + * delimiter: / + * @endcode + * + * While, in the same case, but with exclude_empty set to TRUE, new_text_field + * will be "wambooli/pastafazoul". * * @see \Drupal\migrate\Plugin\MigrateProcessInterface * @@ -84,7 +98,7 @@ class Concat extends ProcessPluginBase { public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { if (is_array($value)) { $delimiter = isset($this->configuration['delimiter']) ? $this->configuration['delimiter'] : ''; - if (empty($this->configuration['allow_empty'])) { + if (!empty($this->configuration['exclude_empty'])) { $value = array_filter($value); } return implode($delimiter, $value); diff --git a/core/modules/migrate/tests/src/Unit/process/ConcatTest.php b/core/modules/migrate/tests/src/Unit/process/ConcatTest.php index 8d037b0..cce1d71 100644 --- a/core/modules/migrate/tests/src/Unit/process/ConcatTest.php +++ b/core/modules/migrate/tests/src/Unit/process/ConcatTest.php @@ -30,45 +30,55 @@ public function providerConcatWithoutDelimiter() { return [ 'no configuration' => [['foo', 'bar'], 'foobar'], 'with delimiter' => [['foo', 'bar'], 'foo_bar', ['delimiter' => '_']], - 'no delimiter, allow_empty is false' => [ + 'no delimiter, exclude_empty is true' => [ ['foo', NULL, 'bar'], 'foobar', - ['allow_empty' => FALSE] + ['exclude_empty' => TRUE] ], - 'no delimiter, allow_empty is true' => [ + 'no delimiter, exclude_empty is false' => [ ['foo', NULL, 'bar'], 'foobar', - ['allow_empty' => TRUE] + ['exclude_empty' => FALSE] ], - 'with delimiter, allow_empty is false, NULL' => [ + 'with delimiter, exclude_empty is true, NULL' => [ ['foo', NULL, 'bar'], 'foo_bar', - ['delimiter' => '_', 'allow_empty' => FALSE] + ['delimiter' => '_', 'exclude_empty' => TRUE] ], - 'with delimiter, allow_empty is true, NULL' => [ + 'with delimiter, exclude_empty is false, NULL' => [ ['foo', NULL, 'bar'], 'foo__bar', - ['delimiter' => '_', 'allow_empty' => TRUE] + ['delimiter' => '_', 'exclude_empty' => FALSE] ], - 'with delimiter, allow_empty is false, empty string' => [ + 'with delimiter, exclude_empty is not set, NULL' => [ + ['foo', NULL, 'bar'], + 'foo__bar', + ['delimiter' => '_'] + ], + 'with delimiter, exclude_empty is true, empty string' => [ ['foo', '', 'bar'], 'foo_bar', - ['delimiter' => '_', 'allow_empty' => FALSE] + ['delimiter' => '_', 'exclude_empty' => TRUE] + ], + 'with delimiter, exclude_empty is false, empty string' => [ + ['foo', '', 'bar'], + 'foo__bar', + ['delimiter' => '_', 'exclude_empty' => FALSE] ], - 'with delimiter, allow_empty is true, empty string' => [ + 'with delimiter, exclude_empty is not set, empty string' => [ ['foo', '', 'bar'], 'foo__bar', - ['delimiter' => '_', 'allow_empty' => TRUE] + ['delimiter' => '_'] ], - 'with delimiter, allow_empty is true, zero' => [ + 'with delimiter, exclude_empty is true, zero' => [ ['foo', 0, 'bar'], 'foo_0_bar', - ['delimiter' => '_', 'allow_empty' => TRUE] + ['delimiter' => '_', 'exclude_empty' => TRUE] ], - 'with delimiter, allow_empty is true, space' => [ + 'with delimiter, exclude_empty is true, space' => [ ['foo', ' ', 'bar'], 'foo_ _bar', - ['delimiter' => '_', 'allow_empty' => TRUE] + ['delimiter' => '_', 'exclude_empty' => TRUE] ], ]; }