You are here

class FilterExtension in Thunder 8.5

Same name and namespace in other branches
  1. 8.2 modules/thunder_article/src/Twig/FilterExtension.php \Drupal\thunder_article\Twig\FilterExtension
  2. 8.3 modules/thunder_article/src/Twig/FilterExtension.php \Drupal\thunder_article\Twig\FilterExtension
  3. 8.4 modules/thunder_article/src/Twig/FilterExtension.php \Drupal\thunder_article\Twig\FilterExtension
  4. 6.2.x modules/thunder_article/src/Twig/FilterExtension.php \Drupal\thunder_article\Twig\FilterExtension
  5. 6.0.x modules/thunder_article/src/Twig/FilterExtension.php \Drupal\thunder_article\Twig\FilterExtension
  6. 6.1.x modules/thunder_article/src/Twig/FilterExtension.php \Drupal\thunder_article\Twig\FilterExtension

Introduce some twig filters.

Hierarchy

  • class \Drupal\thunder_article\Twig\FilterExtension extends \Drupal\thunder_article\Twig\Twig_Extension

Expanded class hierarchy of FilterExtension

1 string reference to 'FilterExtension'
thunder_article.services.yml in modules/thunder_article/thunder_article.services.yml
modules/thunder_article/thunder_article.services.yml
1 service uses FilterExtension
thunder_article.twig.filter_extension in modules/thunder_article/thunder_article.services.yml
Drupal\thunder_article\Twig\FilterExtension

File

modules/thunder_article/src/Twig/FilterExtension.php, line 8

Namespace

Drupal\thunder_article\Twig
View source
class FilterExtension extends \Twig_Extension {

  /**
   * Returns introduced filters.
   *
   * @return array
   *   Declared Twig filters
   */
  public function getFilters() {
    return [
      new \Twig_SimpleFilter('plain_text', [
        $this,
        'plainText',
      ]),
      new \Twig_SimpleFilter('basic_format', [
        $this,
        'basicFormat',
      ], [
        'is_safe' => [
          'html',
        ],
      ]),
    ];
  }

  /**
   * Returns the name of the extension.
   *
   * @return string
   *   The extension name
   */
  public function getName() {
    return 'thunder_article_filter_extension';
  }

  /**
   * Plains a text. Strips everything evil out.
   *
   * @param string $value
   *   The content to be processed.
   *
   * @return string
   *   The processed content.
   */
  public static function plainText($value) {
    $element = render($value);
    $element = strip_tags($element);
    $element = html_entity_decode($element, ENT_QUOTES);
    return $element;
  }

  /**
   * Cleans a text and just allow a few tags.
   *
   * @param string $value
   *   The content to be processed.
   *
   * @return string
   *   The processed content.
   */
  public static function basicFormat($value) {
    $element = render($value);
    $element = strip_tags($element, '<a><em><strong><b><i>');
    return $element;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FilterExtension::basicFormat public static function Cleans a text and just allow a few tags.
FilterExtension::getFilters public function Returns introduced filters.
FilterExtension::getName public function Returns the name of the extension.
FilterExtension::plainText public static function Plains a text. Strips everything evil out.