summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2015-07-06 14:02:19 (GMT)
committerAlex Pott2015-07-06 14:03:31 (GMT)
commitade0716a659dcf10962ac5b8cdf3dfdfb3aa4017 (patch)
treea5f9556b04be91c1a9871fb8dc7f1248ee8575d0
parent90b4ae4c4ae5baa4170e3de56b81f3baa6f8f053 (diff)
Issue #2516802 by Dave Reid: FilterProcessResult->merge() results in PHP warning: Missing argument 1 for FilterProcessResult::__construct()
-rw-r--r--core/lib/Drupal/Core/Cache/CacheableMetadata.php2
-rw-r--r--core/modules/filter/src/Tests/FilterAPITest.php8
-rw-r--r--core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestCacheMerge.php41
3 files changed, 50 insertions, 1 deletions
diff --git a/core/lib/Drupal/Core/Cache/CacheableMetadata.php b/core/lib/Drupal/Core/Cache/CacheableMetadata.php
index a0c1ba8..acb005c 100644
--- a/core/lib/Drupal/Core/Cache/CacheableMetadata.php
+++ b/core/lib/Drupal/Core/Cache/CacheableMetadata.php
@@ -139,7 +139,7 @@ class CacheableMetadata implements CacheableDependencyInterface {
* 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.
diff --git a/core/modules/filter/src/Tests/FilterAPITest.php b/core/modules/filter/src/Tests/FilterAPITest.php
index ff23d39..4ad909b 100644
--- a/core/modules/filter/src/Tests/FilterAPITest.php
+++ b/core/modules/filter/src/Tests/FilterAPITest.php
@@ -221,6 +221,10 @@ class FilterAPITest extends EntityUnitTestBase {
'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 @@ class FilterAPITest extends EntityUnitTestBase {
// 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 @@ class FilterAPITest extends EntityUnitTestBase {
// 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>';
diff --git a/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestCacheMerge.php b/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestCacheMerge.php
new file mode 100644
index 0000000..9e56c9b
--- /dev/null
+++ b/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestCacheMerge.php
@@ -0,0 +1,41 @@
+<?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;
+ }
+
+}