Commit ade0716a authored by alexpott's avatar alexpott

Issue #2516802 by Dave Reid: FilterProcessResult->merge() results in PHP...

Issue #2516802 by Dave Reid: FilterProcessResult->merge() results in PHP warning: Missing argument 1 for FilterProcessResult::__construct()
parent 90b4ae4c
......@@ -139,7 +139,7 @@ public function setCacheMaxAge($max_age) {
* A new CacheableMetadata object, with the merged data.
*/
public function merge(CacheableMetadata $other) {
$result = new static();
$result = clone $this;
// This is called many times per request, so avoid merging unless absolutely
// necessary.
......
......@@ -221,6 +221,10 @@ function testProcessedTextElement() {
'weight' => 0,
'status' => TRUE,
),
'filter_test_cache_merge' => array(
'weight' => 0,
'status' => TRUE,
),
'filter_test_placeholders' => array(
'weight' => 1,
'status' => TRUE,
......@@ -257,6 +261,8 @@ function testProcessedTextElement() {
// The cache tags set by the filter_test_cache_tags filter.
'foo:bar',
'foo:baz',
// The cache tags set by the filter_test_cache_merge filter.
'merge:tag',
);
$this->assertEqual($expected_cache_tags, $build['#cache']['tags'], 'Expected cache tags present.');
$expected_cache_contexts = [
......@@ -265,6 +271,8 @@ function testProcessedTextElement() {
// The default cache contexts for Renderer.
'languages:' . LanguageInterface::TYPE_INTERFACE,
'theme',
// The cache tags set by the filter_test_cache_merge filter.
'user.permissions',
];
$this->assertEqual($expected_cache_contexts, $build['#cache']['contexts'], 'Expected cache contexts present.');
$expected_markup = '<p>Hello, world!</p><p>This is a dynamic llama.</p>';
......
<?php
/**
* @file
* Contains \Drupal\filter_test\Plugin\Filter\FilterTestCacheMerge.
*/
namespace Drupal\filter_test\Plugin\Filter;
use Drupal\filter\FilterProcessResult;
use Drupal\filter\Plugin\FilterBase;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Language\LanguageInterface;
/**
* Provides a test filter to merge with CacheableMetadata.
*
* @Filter(
* id = "filter_test_cache_merge",
* title = @Translation("Testing filter"),
* description = @Translation("Does not change content; merges cacheable metadata."),
* type = Drupal\filter\Plugin\FilterInterface::TYPE_TRANSFORM_REVERSIBLE
* )
*/
class FilterTestCacheMerge extends FilterBase {
/**
* {@inheritdoc}
*/
public function process($text, $langcode) {
$result = new FilterProcessResult($text);
$metadata = new CacheableMetadata();
$metadata->addCacheTags(['merge:tag']);
$metadata->addCacheContexts(['user.permissions']);
$result = $result->merge($metadata);
return $result;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment