You are here

protected function HtmlPurifierFilter::applyPurifierConfig in HTML Purifier 8

Applies the configuration to a HTMLPurifier_Config object.

Parameters

string $configuration:

Return value

\HTMLPurifier_Config

2 calls to HtmlPurifierFilter::applyPurifierConfig()
HtmlPurifierFilter::process in src/Plugin/Filter/HtmlPurifierFilter.php
Performs the filter processing.
HtmlPurifierFilter::settingsFormConfigurationValidate in src/Plugin/Filter/HtmlPurifierFilter.php
Settings form validation callback for htmlpurifier_configuration element.

File

src/Plugin/Filter/HtmlPurifierFilter.php, line 49

Class

HtmlPurifierFilter
Plugin annotation @Filter( id = "htmlpurifier", title = @Translation("HTML Purifier"), description = @Translation("Removes malicious HTML code and ensures that the output is standards compliant."), type =…

Namespace

Drupal\htmlpurifier\Plugin\Filter

Code

protected function applyPurifierConfig($configuration) {

  /* @var $purifier_config \HTMLPurifier_Config */
  $purifier_config = \HTMLPurifier_Config::createDefault();
  $settings = Yaml::decode($configuration);
  foreach ($settings as $namespace => $directives) {
    if (is_array($directives)) {
      foreach ($directives as $key => $value) {
        $purifier_config
          ->set("{$namespace}.{$key}", $value);
      }
    }
    else {
      $this->configErrors[] = 'Invalid value for namespace $namespace, must be an array of directives.';
    }
  }
  return $purifier_config;
}