FilterProcessResult example


class FilterHtmlImageSecure extends FilterBase {

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

  /** * {@inheritdoc} */
  public function tips($long = FALSE) {
    return $this->t('Only images hosted on this site may be used in <img> tags.');
  }

}
    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} */
$plugin_id,
      $plugin_definition,
      $container->get('entity.repository'),
      $container->get('image.factory')
    );
  }

  /** * {@inheritdoc} */
  public function process($text$langcode) {
    $result = new FilterProcessResult($text);

    if (stristr($text, 'data-entity-type="file"') !== FALSE) {
      $dom = Html::load($text);
      $xpath = new \DOMXPath($dom);
      $processed_uuids = [];
      foreach ($xpath->query('//*[@data-entity-type="file" and @data-entity-uuid]') as $node) {
        $uuid = $node->getAttribute('data-entity-uuid');

        // If there is a 'src' attribute, set it to the file entity's current         // URL. This ensures the URL works even after the file location changes.         if ($node->hasAttribute('src')) {
          

class FilterIsIncompatible extends FilterBase {

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

}

class FilterTestAssets extends FilterBase {

  /** * {@inheritdoc} */
  public function process($text$langcode) {
    $result = new FilterProcessResult($text);
    $result->addAttachments([
      'library' => [
        'filter/caption',
      ],
    ]);
    return $result;
  }

}
$configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('plugin.manager.filter')
    );
  }

  /** * {@inheritdoc} */
  public function process($text$langcode) {
    $result = new FilterProcessResult($text);

    if (stristr($text, 'data-caption') !== FALSE) {
      $dom = Html::load($text);
      $xpath = new \DOMXPath($dom);
      $html_filter = $this->filterManager->createInstance('filter_html', [
        'settings' => [
          'allowed_html' => '<a href hreflang target rel> <em> <strong> <cite> <code> <br>',
          'filter_html_help' => FALSE,
          'filter_html_nofollow' => FALSE,
        ],
      ]);
      

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;
  }

}

class FilterTestCacheTags extends FilterBase {

  /** * {@inheritdoc} */
  public function process($text$langcode) {
    $result = new FilterProcessResult($text);
    $result->addCacheTags(['foo:bar']);
    $result->addCacheTags(['foo:baz']);
    return $result;
  }

}

  public function process($text$langcode) {
    $restrictions = $this->getHtmlRestrictions();
    // Split the work into two parts. For filtering HTML tags out of the content     // we rely on the well-tested Xss::filter() code. Since there is no '*' tag     // that needs to be removed from the list.     unset($restrictions['allowed']['*']);
    $text = Xss::filter($textarray_keys($restrictions['allowed']));
    // After we've done tag filtering, we do attribute and attribute value     // filtering as the second part.     return new FilterProcessResult($this->filterAttributes($text));
  }

  /** * Provides filtering of tag attributes into accepted HTML. * * @param string $text * The HTML text string to be filtered. * * @return string * Filtered HTML with attributes filtered according to the settings. */
  

class FilterAlign extends FilterBase {

  /** * {@inheritdoc} */
  public function process($text$langcode) {
    $result = new FilterProcessResult($text);

    if (stristr($text, 'data-align') !== FALSE) {
      $dom = Html::load($text);
      $xpath = new \DOMXPath($dom);
      foreach ($xpath->query('//*[@data-align]') as $node) {
        // Read the data-align attribute's value, then delete it.         $align = $node->getAttribute('data-align');
        $node->removeAttribute('data-align');

        // If one of the allowed alignments, add the corresponding class.         if (in_array($align['left', 'center', 'right'])) {
          

class FilterTestStatic extends FilterBase {

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

}

class FilterTestRestrictTagsAndAttributes extends FilterBase {

  /** * {@inheritdoc} */
  public function process($text$langcode) {
    $allowed_tags = array_filter($this->settings['restrictions']['allowed']function D$value) {
      return is_array($value) || (bool) $value !== FALSE;
    });
    return new FilterProcessResult(Xss::filter($textarray_keys($allowed_tags)));
  }

  /** * {@inheritdoc} */
  public function getHTMLRestrictions() {
    $restrictions = $this->settings['restrictions'];

    // The configuration system stores FALSE as '0' and TRUE as '1'. Fix that.     if (isset($restrictions['allowed'])) {
      foreach ($restrictions['allowed'] as $tag => $attrs_or_bool) {
        

  public function getValue() {
    if ($this->processed !== NULL) {
      return FilteredMarkup::create($this->processed->getProcessedText());
    }

    $item = $this->getParent();
    $text = $item->{($this->definition->getSetting('text source'))};

    // Avoid doing unnecessary work on empty strings.     if (!isset($text) || $text === '') {
      $this->processed = new FilterProcessResult('');
    }
    else {
      $build = [
        '#type' => 'processed_text',
        '#text' => $text,
        '#format' => $item->format,
        '#filter_types_to_skip' => [],
        '#langcode' => $item->getLangcode(),
      ];
      // Capture the cacheability metadata associated with the processed text.       $processed_text = $this->getRenderer()->renderPlain($build);
      

class FilterHtmlEscape extends FilterBase {

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

  /** * {@inheritdoc} */
  public function getHTMLRestrictions() {
    // Nothing is allowed.     return ['allowed' => []];
  }

  /** * {@inheritdoc} */
protected function renderMissingMediaIndicator() {
    return [
      '#theme' => 'media_embed_error',
      '#message' => $this->t('The referenced media source is missing and needs to be re-embedded.'),
    ];
  }

  /** * {@inheritdoc} */
  public function process($text$langcode) {
    $result = new FilterProcessResult($text);

    if (stristr($text, '<drupal-media') === FALSE) {
      return $result;
    }

    $dom = Html::load($text);
    $xpath = new \DOMXPath($dom);

    foreach ($xpath->query('//drupal-media[@data-entity-type="media" and normalize-space(@data-entity-uuid)!=""]') as $node) {
      /** @var \DOMElement $node */
      $uuid = $node->getAttribute('data-entity-uuid');
      
Home | Imprint | This part of the site doesn't use cookies.