diff --git a/core/modules/editor/src/Plugin/Filter/EditorFileReference.php b/core/modules/editor/src/Plugin/Filter/EditorFileReference.php index 5ebb267..96f59c2 100644 --- a/core/modules/editor/src/Plugin/Filter/EditorFileReference.php +++ b/core/modules/editor/src/Plugin/Filter/EditorFileReference.php @@ -8,7 +8,6 @@ namespace Drupal\editor\Plugin\Filter; use Drupal\Component\Utility\Html; -use Drupal\Component\Utility\NestedArray; use Drupal\filter\FilterProcessResult; use Drupal\filter\Plugin\FilterBase; @@ -49,7 +48,7 @@ public function process($text, $langcode) { } } } - $result->setCacheTags(NestedArray::mergeDeepArray($all_file_cache_tags)); + $result->addCacheTags($all_file_cache_tags); } return $result; diff --git a/core/modules/filter/src/FilterProcessResult.php b/core/modules/filter/src/FilterProcessResult.php index de40f07..c07b9a3 100644 --- a/core/modules/filter/src/FilterProcessResult.php +++ b/core/modules/filter/src/FilterProcessResult.php @@ -145,6 +145,19 @@ public function getCacheTags() { } /** + * Adds cache tags associated with the processed text. + * + * @param array $cache_tags + * The cache tags to be added. + * + * @return $this + */ + public function addCacheTags(array $cache_tags) { + $this->cacheTags = NestedArray::mergeDeepArray($this->cacheTags, $cache_tags); + return $this; + } + + /** * Sets cache tags associated with the processed text. * * @param array $cache_tags @@ -167,6 +180,19 @@ public function getAssets() { } /** + * Adds assets associated with the processed text. + * + * @param array $assets + * The associated assets to be attached. + * + * @return $this + */ + public function addAssets(array $assets) { + $this->assets = NestedArray::mergeDeepArray($this->assets, $assets); + return $this; + } + + /** * Sets assets associated with the processed text. * * @param array $assets @@ -189,6 +215,24 @@ public function getPostRenderCacheCallbacks() { } /** + * Adds #post_render_cache callbacks associated with the processed text. + * + * @param callable $callback + * The #post_render_cache callback that will replace the placeholder with + * its eventual markup. + * @param array $context + * An array providing context for the #post_render_cache callback. + * + * @see drupal_render_cache_generate_placeholder() + * + * @return $this + */ + public function addPostRenderCacheCallback($callback, array $context) { + $this->postRenderCacheCallbacks[$callback][] = $context; + return $this; + } + + /** * Sets #post_render_cache callbacks associated with the processed text. * * @param array $post_render_cache_callbacks diff --git a/core/modules/filter/src/Plugin/Filter/FilterCaption.php b/core/modules/filter/src/Plugin/Filter/FilterCaption.php index 1b7c7e1..bccaf02 100644 --- a/core/modules/filter/src/Plugin/Filter/FilterCaption.php +++ b/core/modules/filter/src/Plugin/Filter/FilterCaption.php @@ -105,7 +105,7 @@ public function process($text, $langcode) { $result->setProcessedText(Html::serialize($dom)); if ($caption_found) { - $result->setAssets(array( + $result->addAssets(array( 'library' => array( 'filter/caption', ), diff --git a/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestAssets.php b/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestAssets.php index 4bd93af..a7de6d9 100644 --- a/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestAssets.php +++ b/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestAssets.php @@ -27,7 +27,7 @@ class FilterTestAssets extends FilterBase { */ public function process($text, $langcode) { $result = new FilterProcessResult($text); - $result->setAssets(array( + $result->addAssets(array( 'library' => array( 'filter/caption', ), diff --git a/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestCacheTags.php b/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestCacheTags.php index d970b83..3c03c3f 100644 --- a/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestCacheTags.php +++ b/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestCacheTags.php @@ -27,7 +27,8 @@ class FilterTestCacheTags extends FilterBase { */ public function process($text, $langcode) { $result = new FilterProcessResult($text); - $result->setCacheTags(array('foo' => array('bar', 'baz'))); + $result->addCacheTags(array('foo' => array('bar'))); + $result->addCacheTags(array('foo' => array('baz'))); return $result; } diff --git a/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestPostRenderCache.php b/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestPostRenderCache.php index cee058a..c8beaef 100644 --- a/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestPostRenderCache.php +++ b/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestPostRenderCache.php @@ -32,11 +32,7 @@ public function process($text, $langcode) { 'token' => drupal_render_cache_generate_token(), ); $result = new FilterProcessResult($text . '

' . drupal_render_cache_generate_placeholder($callback, $context, $context['token']) . '

'); - $result->setPostRenderCacheCallbacks(array( - $callback => array( - $context, - ), - )); + $result->addPostRenderCacheCallback($callback, $context); return $result; } diff --git a/core/modules/system/src/Tests/Common/RenderTest.php b/core/modules/system/src/Tests/Common/RenderTest.php index 0d23de1..8eccba9 100644 --- a/core/modules/system/src/Tests/Common/RenderTest.php +++ b/core/modules/system/src/Tests/Common/RenderTest.php @@ -774,13 +774,16 @@ function testDrupalRenderRenderCachePlaceholder() { 'token' => drupal_render_cache_generate_token(), ); $callback = 'common_test_post_render_cache_placeholder'; + $placeholder = drupal_render_cache_generate_placeholder($callback, $context, $context['token']); + $this->assertIdentical($placeholder, Html::normalize($placeholder), 'Placeholder unaltered by Html::normalize() which is used by FilterHtmlCorrector.'); + $test_element = array( '#post_render_cache' => array( $callback => array( $context ), ), - '#markup' => drupal_render_cache_generate_placeholder($callback, $context, $context['token']), + '#markup' => $placeholder, '#prefix' => '', '#suffix' => '' );