diff --git a/core/modules/image/image.post_update.php b/core/modules/image/image.post_update.php
index 7684b94daf..7548ec436a 100644
--- a/core/modules/image/image.post_update.php
+++ b/core/modules/image/image.post_update.php
@@ -23,14 +23,15 @@ function image_post_update_image_style_dependencies() {
}
/**
- * Add filter image style to basic_html and full_html filters.
+ * Add filter image style to basic_html and full_html filter formats.
*/
-function image_enable_filter_image_style() {
- $filters = ['basic_html' => 11, 'full_html' => 12];
- foreach ($filters as $filter => $weight) {
- if ($filter = FilterFormat::load($filter)) {
- $filter->setFilterConfig('filter_image_style', ['status' => TRUE, 'weight' => $weight]);
- if (($filter = $filter->filters('filter_html')) && $filter->status) {
+function image_post_update_enable_filter_image_style() {
+ $formats = ['basic_html' => 11, 'full_html' => 12];
+ foreach ($formats as $format => $weight) {
+ if ($format = FilterFormat::load($format)) {
+ $format->setFilterConfig('filter_image_style', ['status' => TRUE, 'weight' => $weight]);
+ // 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 = [];
@@ -38,9 +39,10 @@ function image_enable_filter_image_style() {
$new_attributes = array_filter(explode(' ', $matches[1]));
$new_attributes[] = 'data-image-style';
$config['settings']['allowed_html'] = preg_replace('/
]*)>/', '
', $allowed_html);
- $filter->setFilterConfig('filter_html', $config);
+ $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.');
+
+ }
+
+}