diff --git a/core/modules/editor/editor.post_update.php b/core/modules/editor/editor.post_update.php
new file mode 100644
index 000000000000..3715b6dc575e
--- /dev/null
+++ b/core/modules/editor/editor.post_update.php
@@ -0,0 +1,21 @@
+query('//*[@data-entity-type="file" and @data-entity-uuid]') as $node) {
$uuid = $node->getAttribute('data-entity-uuid');
+
+ // If there is a 'src' attribute, set it to the file entity's current
+ // URL. This ensures the URL works even after the file location changes.
+ if ($node->hasAttribute('src')) {
+ $file = $this->entityManager->loadEntityByUuid('file', $uuid);
+ if ($file) {
+ $node->setAttribute('src', file_url_transform_relative(file_create_url($file->getFileUri())));
+ }
+ }
+
// Only process the first occurrence of each file UUID.
if (!isset($processed_uuids[$uuid])) {
$processed_uuids[$uuid] = TRUE;
@@ -81,6 +91,7 @@ class EditorFileReference extends FilterBase implements ContainerFactoryPluginIn
}
}
}
+ $result->setProcessedText(Html::serialize($dom));
}
return $result;
diff --git a/core/modules/editor/tests/src/Kernel/EditorFileReferenceFilterTest.php b/core/modules/editor/tests/src/Kernel/EditorFileReferenceFilterTest.php
index fb7d3e48919c..51eee9731c6f 100644
--- a/core/modules/editor/tests/src/Kernel/EditorFileReferenceFilterTest.php
+++ b/core/modules/editor/tests/src/Kernel/EditorFileReferenceFilterTest.php
@@ -76,20 +76,23 @@ class EditorFileReferenceFilterTest extends KernelTestBase {
$this->pass('One data-entity-uuid attribute.');
$input = '
';
+ $expected_output = '
';
$output = $test($input);
- $this->assertIdentical($input, $output->getProcessedText());
+ $this->assertIdentical($expected_output, $output->getProcessedText());
$this->assertEqual($cache_tag, $output->getCacheTags());
$this->pass('One data-entity-uuid attribute with odd capitalization.');
$input = '
';
+ $expected_output = '
';
$output = $test($input);
- $this->assertIdentical($input, $output->getProcessedText());
+ $this->assertIdentical($expected_output, $output->getProcessedText());
$this->assertEqual($cache_tag, $output->getCacheTags());
$this->pass('One data-entity-uuid attribute on a non-image tag.');
$input = '';
+ $expected_output = '';
$output = $test($input);
- $this->assertIdentical($input, $output->getProcessedText());
+ $this->assertIdentical($expected_output, $output->getProcessedText());
$this->assertEqual($cache_tag, $output->getCacheTags());
$this->pass('One data-entity-uuid attribute with an invalid value.');
@@ -101,15 +104,19 @@ class EditorFileReferenceFilterTest extends KernelTestBase {
$this->pass('Two different data-entity-uuid attributes.');
$input = '
';
$input .= '
';
+ $expected_output = '
';
+ $expected_output .= '
';
$output = $test($input);
- $this->assertIdentical($input, $output->getProcessedText());
+ $this->assertIdentical($expected_output, $output->getProcessedText());
$this->assertEqual(Cache::mergeTags($cache_tag, $cache_tag_2), $output->getCacheTags());
$this->pass('Two identical data-entity-uuid attributes.');
$input = '
';
$input .= '
';
+ $expected_output = '
';
+ $expected_output .= '
';
$output = $test($input);
- $this->assertIdentical($input, $output->getProcessedText());
+ $this->assertIdentical($expected_output, $output->getProcessedText());
$this->assertEqual($cache_tag, $output->getCacheTags());
}