diff --git a/core/modules/filter/src/Plugin/migrate/process/FilterSettings.php b/core/modules/filter/src/Plugin/migrate/process/FilterSettings.php index 235042609c3b6db5397a1d3780b62ef6696cfb1c..eb0da328d0675bde4c0f3a1df0f9f8237216d77d 100644 --- a/core/modules/filter/src/Plugin/migrate/process/FilterSettings.php +++ b/core/modules/filter/src/Plugin/migrate/process/FilterSettings.php @@ -42,7 +42,9 @@ class FilterSettings extends ProcessPluginBase { public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { // Only the filter_html filter's settings have a changed format. if ($row->getDestinationProperty('id') === 'filter_html') { - $value['allowed_html'] = str_replace(array_keys($this->allowedHtmlDefaultAttributes), array_values($this->allowedHtmlDefaultAttributes), $value['allowed_html']); + if (!empty($value['allowed_html'])) { + $value['allowed_html'] = str_replace(array_keys($this->allowedHtmlDefaultAttributes), array_values($this->allowedHtmlDefaultAttributes), $value['allowed_html']); + } } return $value; } diff --git a/core/modules/filter/tests/src/Kernel/Plugin/migrate/process/FilterSettingsTest.php b/core/modules/filter/tests/src/Kernel/Plugin/migrate/process/FilterSettingsTest.php new file mode 100644 index 0000000000000000000000000000000000000000..42502110775c5e2abbf9446e59a93e1f47059d29 --- /dev/null +++ b/core/modules/filter/tests/src/Kernel/Plugin/migrate/process/FilterSettingsTest.php @@ -0,0 +1,102 @@ +getMock(MigrationInterface::class); + $plugin = new FilterSettings([], 'filter_settings', [], $migration); + + $executable = $this->getMock(MigrateExecutableInterface::class); + $row = $this->getMockBuilder(Row::class) + ->disableOriginalConstructor() + ->getMock(); + + $row->expects($this->atLeastOnce()) + ->method('getDestinationProperty') + ->willReturn($destination_id); + + $output_value = $plugin->transform($value, $executable, $row, 'foo'); + $this->assertSame($expected_value, $output_value); + } + + /** + * The test data provider. + * + * @return array + */ + public function dataProvider() { + return [ + // Tests that the transformed value is identical to the input value when + // destination is not the filter_html. + + // Test with an empty source array. + [ + [], + 'any_filter', + [], + ], + // Test with a source string. + [ + 'a string', + 'any_filter', + 'a string', + ], + // Test with a source filter array. + [ + [ + 'allowed_html' => '