Skip to content

Commit

Permalink
add transformer documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
trsteel88 committed May 4, 2012
1 parent 46a13cf commit d0f068c
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions Resources/doc/transformers.md
@@ -0,0 +1,74 @@
## Creating your own transformers

Transformers are used to change the html data before it is saved.

For an example transformer see [Transformer/StripJS.php](Transformer/StripJS.php)

### Step 1: Create your transformer

src/AcmeDemoBundle/Transformer/RemoveImages.php

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

### Step 2: Tag your transformer so it can be detected.

src/AcmeDemoBundle/config/services.yml

```yaml
acme_demo_ckeditor.transformer.strip_comments:
class: Acme\DemoBundle\Transformer\RemoveImages
tags:
- { name: trsteel_ckeditor.transformer, alias: remove_images }
```

Note: The alias must be unique.

### Step 3: Enable your custom transformer

Enable the transformer globally in config.yml

```yaml
trsteel_ckeditor:
transformers: ['remove_images']
```

Or enable it on a specific form

```php
<?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 strip_js, strip_css etc)

0 comments on commit d0f068c

Please sign in to comment.