From 9268dcc4ece17d71ed12499fe840a199e9f05db2 Mon Sep 17 00:00:00 2001 From: effulgentsia Date: Tue, 19 Jul 2016 11:21:29 -0700 Subject: [PATCH] Issue #2666382 by Wim Leers, alexpott, TwoD, timmillwood, catch: EditorFileReference filter: generate URLs for inline images --- core/modules/editor/editor.post_update.php | 21 +++++++++++++++++++ .../src/Plugin/Filter/EditorFileReference.php | 11 ++++++++++ .../Kernel/EditorFileReferenceFilterTest.php | 17 ++++++++++----- 3 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 core/modules/editor/editor.post_update.php 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 = '