FilterTestCacheContexts.php

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

Namespace

Drupal\filter_test\Plugin\Filter

File

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

View source
<?php

namespace Drupal\filter_test\Plugin\Filter;

use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\filter\Attribute\Filter;
use Drupal\Core\Language\LanguageInterface;
use Drupal\filter\FilterProcessResult;
use Drupal\filter\Plugin\FilterBase;
use Drupal\filter\Plugin\FilterInterface;

/**
 * Provides a test filter to associate cache contexts.
 */
class FilterTestCacheContexts extends FilterBase {
    
    /**
     * {@inheritdoc}
     */
    public function process($text, $langcode) {
        $result = new FilterProcessResult($text);
        // The changes made by this filter are language-specific.
        $result->addCacheContexts([
            'languages:' . LanguageInterface::TYPE_CONTENT,
        ]);
        return $result;
    }

}

Classes

Title Deprecated Summary
FilterTestCacheContexts Provides a test filter to associate cache contexts.

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