FilterHtml example

$elements_string = preg_replace_callback('/<(\$[a-z][0-9a-z\-]*|\*)/', function D$matches) use (&$replaced_wildcard_tags) {
      $wildcard_tag_name = $matches[1];
      $replacement = $wildcard_tag_name === '*'
        ? 'preprocessed-global-attribute__'
        : sprintf("preprocessed-wildcard-%s__", substr($wildcard_tag_name, 1));
      $replaced_wildcard_tags[$replacement] = $wildcard_tag_name;
      return "<$replacement";
    }$elements_string);

    // Reuse the parsing logic from FilterHtml::getHTMLRestrictions().     $configuration = ['settings' => ['allowed_html' => $elements_string]];
    $filter = new FilterHtml($configuration, 'filter_html', ['provider' => 'filter']);
    $allowed_elements = $filter->getHTMLRestrictions()['allowed'];
    // Omit the broad wildcard addition that FilterHtml::getHTMLRestrictions()     // always sets; it is specific to how FilterHTML works and irrelevant here.     unset($allowed_elements['*']);
    // @see \Drupal\filter\Plugin\Filter\FilterHtml::getHTMLRestrictions()     // @todo remove this in https://www.drupal.org/project/drupal/issues/3226368     // cSpell:disable-next-line     unset($allowed_elements['__zqh6vxfbk3cg__']);

    // Postprocess tag wildcards: convert     // `<preprocessed-wildcard-text-container__>` to `<$text-container>`.
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $configuration['settings'] = [
      'allowed_html' => '<a href> <p> <em> <strong> <cite> <blockquote> <code class="pretty boring align-*"> <ul alpaca-*="wooly-* strong"> <ol llama-*> <li> <dl> <dt> <dd> <br> <h3 id>',
      'filter_html_help' => 1,
      'filter_html_nofollow' => 0,
    ];
    $this->filter = new FilterHtml($configuration, 'filter_html', ['provider' => 'test']);
    $this->filter->setStringTranslation($this->getStringTranslationStub());
  }

  /** * @covers ::filterAttributes * * @dataProvider providerFilterAttributes * * @param string $html * Input HTML. * @param string $expected * The expected output string. */
Home | Imprint | This part of the site doesn't use cookies.