Installation
composer require trsteel/ckeditor-bundle
Add to bundles.php (Symfony 5+):
return [
Trsteel\CkeditorBundle\TrsteelCkeditorBundle::class => ['all' => true],
];
Install Assets
php bin/console assets:install public
First Use Case Add to a form type:
use Trsteel\CkeditorBundle\Form\Type\CkeditorType;
$builder->add('content', CkeditorType::class);
Render in a template:
{{ form_row(form.content) }}
config/packages/trsteel_ckeditor.yaml (auto-generated after installation)templates/trsteel_ckeditor/editor.html.twig (customization entry point)assets/ckeditor/ (asset directory for JS/CSS overrides)Basic Integration
// src/Form/ArticleType.php
$builder->add('body', CkeditorType::class, [
'config' => [
'toolbar' => ['bold', 'italic', 'numberedList'],
],
]);
Dynamic Configuration Use dependency injection to pass runtime config:
$builder->add('description', CkeditorType::class, [
'config' => $this->getCkeditorConfig($userRole),
]);
Asset Overrides
Extend default assets via assets.json:
{
"ckeditor": {
"js": ["path/to/custom-plugin.js"],
"css": ["path/to/custom-styles.css"]
}
}
Data Transformers
Enable HTML sanitization in config/packages/trsteel_ckeditor.yaml:
trsteel_ckeditor:
transformers: ['html_purifier']
{{ form_row(form.content, {'attr': {'data-turbo-frame': '_self'}}) }}
data_class with ApiPlatform entities:
$builder->add('markdown', CkeditorType::class, [
'mapped' => false,
'attr' => ['class' => 'markdown-input'],
]);
trsteel_ckeditor:
toolbars:
basic: ['bold', 'italic', 'link']
advanced: ['*', 'numberedList', 'blockQuote']
Then reference:
'config' => ['toolbar' => 'advanced']
Asset Pipeline Issues
assets:install is run and symlinks are correct.
php bin/console assets:install public --symlink
/build/ckeditor.js.Configuration Overrides
config:dump-reference to verify precedence:
php bin/console config:dump-reference TrsteelCkeditorBundle
Data Transformer Conflicts
$builder->add('content', CkeditorType::class, [
'transformers' => ['html_purifier', 'html_entity_decode'],
]);
Twig Template Overrides
{# templates/trsteel_ckeditor/editor.html.twig #}
{{ dump(app.request.uri) }} to verify template resolution.Enable CKEditor Debug Mode:
trsteel_ckeditor:
debug: true
Logs config and asset paths to Symfony profiler.
Check for JavaScript Errors:
php bin/console debug:assets
Verify ckeditor entry exists and is built.
Custom Plugins
Add plugins via assets.json:
{
"ckeditor": {
"plugins": ["your_plugin"]
}
}
Then include in toolbar:
'config' => ['toolbar' => ['your_plugin']]
Event Listeners
Subscribe to ckeditor.init event for runtime modifications:
// src/EventListener/CkeditorListener.php
public function onCkeditorInit(CkeditorEvent $event) {
$event->getConfig()->extraPlugins = 'your_plugin';
}
Register in services.yaml:
services:
App\EventListener\CkeditorListener:
tags:
- { name: 'kernel.event_listener', event: 'ckeditor.init' }
Database Storage
For large content, use DoctrineExtensions with Sluggable:
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @Gedmo\Slug(fields={"title"})
*/
private $slug;
How can I help you explore Laravel packages today?