Transformers are used to change the html data before it is saved.
For an example transformer see /trsteel88/TrsteelCkeditorBundle/blob/master/Form/Transformer/StripJS.php
src/AcmeDemoBundle/Transformer/RemoveImages.php
<?php
namespace Acme\DemoBundle\Transformer;
use Symfony\Component\Form\DataTransformerInterface;
class RemoveImages implements DataTransformerInterface
{
/**
* {@inheritDoc}
*/
public function transform($data)
{
return $data;
}
/**
* {@inheritDoc}
*/
public function reverseTransform($data)
{
return preg_replace('/<img[^>]+\>/is', '', $data);
}
}
src/AcmeDemoBundle/config/services.yml
acme_demo_ckeditor.transformer.remove_images:
class: Acme\DemoBundle\Transformer\RemoveImages
tags:
- { name: trsteel_ckeditor.transformer, alias: remove_images }
Note: The alias must be unique.
Enable the transformer globally in config.yml
trsteel_ckeditor:
transformers: ['remove_images']
Or enable it on a specific form
<?php
$form = $this->createFormBuilder($post)
->add('title', 'text')
->add('content', 'ckeditor', array(
'transformers' => array('remove_images'),
))
->getForm()
;
Note: If you override the transformers value none of the default transformers will be including (eg html_purifier)