Skip to content

Commit

Permalink
add html purifier config
Browse files Browse the repository at this point in the history
  • Loading branch information
trsteel88 committed Mar 12, 2014
1 parent ffd8770 commit a4519cd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
11 changes: 9 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ public function getConfigTreeBuilder()

$rootNode
->children()
->scalarNode('class')
->defaultValue('Trsteel\CkeditorBundle\Form\Type\CkeditorType')
->scalarNode('class')->defaultValue('Trsteel\CkeditorBundle\Form\Type\CkeditorType')->end()
->arrayNode('html_purifier')
->addDefaultsIfNotSet()
->children()
->variableNode('config')
->defaultValue(array())
->info("The default html purifer config. See http://htmlpurifier.org/live/configdoc/plain.html for more information.")
->end()
->end()
->end()
->variableNode('transformers')
->defaultValue(array('html_purifier'))
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/TrsteelCkeditorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function load(array $configs, ContainerBuilder $container)
$config['base_path'] = ltrim($config['base_path'], '/');

$container->setParameter('trsteel_ckeditor.form.type.class', $config['class']);
$container->setParameter('trsteel_ckeditor.html_purifier.config', $config['html_purifier']['config']);
$container->setParameter('trsteel_ckeditor.ckeditor.transformers', $config['transformers']);
$container->setParameter('trsteel_ckeditor.ckeditor.toolbar', $config['toolbar']);
$container->setParameter('trsteel_ckeditor.ckeditor.toolbar_groups', $config['toolbar_groups']);
Expand Down
15 changes: 14 additions & 1 deletion Form/DataTransformer/HTMLPurifierTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ class HTMLPurifierTransformer implements DataTransformerInterface
*/
private $purifier;

/**
* @var array
*/
private $config;

/**
* @param array $config
*/
public function __construct(array $config)
{
$this->config = $config;
}

/**
* {@inheritdoc}
*/
Expand All @@ -33,7 +46,7 @@ public function reverseTransform($value)
protected function getPurifier()
{
if (null === $this->purifier) {
$this->purifier = new \HTMLPurifier();
$this->purifier = new \HTMLPurifier($this->config);
}

return $this->purifier;
Expand Down
1 change: 1 addition & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ services:
trsteel_ckeditor.transformer.html_purifier:
class: Trsteel\CkeditorBundle\Form\DataTransformer\HTMLPurifierTransformer
public: false
arguments: [%trsteel_ckeditor.html_purifier.config%]
tags:
- { name: trsteel_ckeditor.transformer, alias: html_purifier }

0 comments on commit a4519cd

Please sign in to comment.