You are here

class FilterNull in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/filter/src/Plugin/Filter/FilterNull.php \Drupal\filter\Plugin\Filter\FilterNull
  2. 9 core/modules/filter/src/Plugin/Filter/FilterNull.php \Drupal\filter\Plugin\Filter\FilterNull

Provides a fallback placeholder filter to use for missing filters.

The filter system uses this filter to replace missing filters (for example, if a filter module has been disabled) that are still part of defined text formats. It returns an empty string.

Plugin annotation


@Filter(
  id = "filter_null",
  title = @Translation("Provides a fallback for missing filters. Do not use."),
  type = Drupal\filter\Plugin\FilterInterface::TYPE_HTML_RESTRICTOR,
  weight = -10
)

Hierarchy

Expanded class hierarchy of FilterNull

1 file declares its use of FilterNull
FilterFormatFormBase.php in core/modules/filter/src/FilterFormatFormBase.php

File

core/modules/filter/src/Plugin/Filter/FilterNull.php, line 22

Namespace

Drupal\filter\Plugin\Filter
View source
class FilterNull extends FilterBase {

  /**
   * Tracks if an alert about this filter has been logged.
   *
   * @var bool
   */
  protected $logged = FALSE;

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition) {

    // Once per filter, log that a filter plugin was missing.
    if (!$this->logged) {
      $this->logged = TRUE;
      \Drupal::logger('filter')
        ->alert('Missing filter plugin: %filter.', [
        '%filter' => $plugin_id,
      ]);
    }
    parent::__construct($configuration, $plugin_id, $plugin_definition);
  }

  /**
   * {@inheritdoc}
   */
  public function process($text, $langcode) {
    return new FilterProcessResult('');
  }

  /**
   * {@inheritdoc}
   */
  public function getHTMLRestrictions() {

    // Nothing is allowed.
    return [
      'allowed' => [],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function tips($long = FALSE) {
    return $this
      ->t('Missing filter. All text is removed');
  }

}

Members