FilterTestCacheMerge.php

Same filename and directory in other branches
  1. 9 core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestCacheMerge.php
  2. 8.9.x core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestCacheMerge.php
  3. 11.x core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestCacheMerge.php

Namespace

Drupal\filter_test\Plugin\Filter

File

core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestCacheMerge.php

View source
<?php

namespace Drupal\filter_test\Plugin\Filter;

use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\filter\Attribute\Filter;
use Drupal\filter\FilterProcessResult;
use Drupal\filter\Plugin\FilterBase;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\filter\Plugin\FilterInterface;

/**
 * Provides a test filter to merge with CacheableMetadata.
 */
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;
  }

}

Classes

Title Deprecated Summary
FilterTestCacheMerge Provides a test filter to merge with CacheableMetadata.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.