diff --git a/core/modules/image/image.post_update.php b/core/modules/image/image.post_update.php index fe41c9f55c..7548ec436a 100644 --- a/core/modules/image/image.post_update.php +++ b/core/modules/image/image.post_update.php @@ -30,8 +30,9 @@ function image_post_update_enable_filter_image_style() { foreach ($formats as $format => $weight) { if ($format = FilterFormat::load($format)) { $format->setFilterConfig('filter_image_style', ['status' => TRUE, 'weight' => $weight]); - if (($format = $format->filters('filter_html')) && $format->status) { - $config = $format->getConfiguration(); + // Update the allowed html tags of filter_html filter if its enabled. + if (($filter = $format->filters('filter_html'))) { + $config = $filter->getConfiguration(); $allowed_html = !empty($config['settings']['allowed_html']) ? $config['settings']['allowed_html'] : NULL; $matches = []; if ($allowed_html && preg_match('/]*)>/', $allowed_html, $matches)) { @@ -41,6 +42,7 @@ function image_post_update_enable_filter_image_style() { $format->setFilterConfig('filter_html', $config); } } + $format->save(); } } } diff --git a/core/modules/image/src/Tests/Update/ImageUpdateTextFormatsTest.php b/core/modules/image/src/Tests/Update/ImageUpdateTextFormatsTest.php new file mode 100644 index 0000000000..7f01c1f568 --- /dev/null +++ b/core/modules/image/src/Tests/Update/ImageUpdateTextFormatsTest.php @@ -0,0 +1,48 @@ +databaseDumpFiles = [ + __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz', + ]; + } + + /** + * Tests image_post_update_enable_filter_image_style(). + * + * @see image_post_update_enable_filter_image_style() + */ + public function testPostUpdateFilterImageStyle() { + // Check that basic_html and full_html format does not have filter_image_style filter applied. + $config_factory = \Drupal::configFactory(); + $basic_html_data = $config_factory->get('filter.format.basic_html')->get(); + $this->assertFalse(isset($basic_html_data['filters']['filter_image_style']), 'Prior to running the update the "filter_image_style" filter does not applied to basic_html format.'); + $full_html_data = $config_factory->get('filter.format.full_html')->get(); + $this->assertFalse(isset($full_html_data['filters']['filter_image_style']), 'Prior to running the update the "filter_image_style" filter does not applied to full_html format.'); + + // Run updates. + $this->runUpdates(); + + // Check that the filter_format entities have been updated. + $config_factory = \Drupal::configFactory(); + $basic_html_data = $config_factory->get('filter.format.basic_html')->get(); + $this->assertTrue(isset($basic_html_data['filters']['filter_image_style']), 'After running the update the "filter_image_style" filter applied to basic_html format.'); + $full_html_data = $config_factory->get('filter.format.full_html')->get(); + $this->assertTrue(isset($full_html_data['filters']['filter_image_style']), 'After running the update the "filter_image_style" filter applied to full_html format.'); + + } + +}