Installation
composer require ailove-dev/ckeditor-bundle
Ensure Trsteel\CkeditorBundle is installed (handled automatically via composer.json dependency).
Enable the Bundle
Add to config/bundles.php:
return [
// ...
Trsteel\CkeditorBundle\TrsteelCkeditorBundle::class => ['all' => true],
AiloveDev\CKEditorBundle\CKEditorBundle::class => ['all' => true],
];
Basic Configuration
Override default settings in config/packages/ckeditor.yaml:
trsteel_ckeditor:
base_path: '%kernel.project_dir%/public/ckeditor'
config_path: '%kernel.project_dir%/public/ckeditor/config'
upload_path: '%kernel.project_dir%/public/uploads/ckeditor'
upload_url: '/uploads/ckeditor'
assets_path: '%kernel.project_dir%/vendor/ckeditor/ckeditor4'
First Use Case: Form Integration
Use the CKEditorType in a Symfony form:
use AiloveDev\CKEditorBundle\Form\Type\CKEditorType;
$builder->add('content', CKEditorType::class, [
'config' => ['toolbar' => 'Full'],
'media_library' => true, // Enable SonataMediaBundle integration
]);
CKEditorType as a drop-in replacement for TextareaType in forms.config/packages/ckeditor.yaml:
trsteel_ckeditor:
configs:
custom:
toolbar: [['Bold', 'Italic'], ['NumberedList', 'BulletedList']]
Reference in form:
$builder->add('content', CKEditorType::class, ['config' => 'custom']);
$builder->add('content', CKEditorType::class, [
'media_library' => true,
'media_provider' => 'sonata.media.provider.file', // Adjust as needed
]);
file, image).trsteel_ckeditor:
upload_path: '%kernel.project_dir%/public/custom_uploads'
upload_url: '/custom_uploads'
assets_path to point to a custom CKEditor version (e.g., for CDN-hosted builds).{{ form_widget(form.content, {'attr': {'class': 'ckeditor'}}) }}
{{ encore_entry_link_tags('app') }} {# Ensure CKEditor assets are enqueued #}
Missing Assets:
assets_path points to the correct CKEditor installation (default: vendor/ckeditor/ckeditor4). Run composer install if assets are missing.SonataMediaBundle Mismatch:
media_provider matches a configured Sonata provider (e.g., sonata.media.provider.file). Check SonataMediaBundle’s providers config.Permission Issues:
upload_path is writable by the web server:
chmod -R 775 %kernel.project_dir%/public/uploads/ckeditor
Config Overrides:
ckeditor.yaml:
php bin/console cache:clear
use Symfony\Component\DependencyInjection\ContainerInterface;
public function debugConfig(ContainerInterface $container) {
dump($container->getParameter('trsteel_ckeditor.configs'));
}
Custom Upload Handlers:
Extend Trsteel\CkeditorBundle\EventListener\UploadListener to handle non-file uploads (e.g., database storage).
Dynamic Toolbars: Use Twig to pass dynamic configs:
{{ form_widget(form.content, {
'config': {
'toolbar': ['Bold', 'Italic', app.request.query.get('extra_toolbar', [])]
}
}) }}
Plugin Integration:
Add custom CKEditor plugins by extending the assets_path to include plugin folders and updating the config:
trsteel_ckeditor:
configs:
custom:
extraPlugins: 'myplugin'
Form Events:
Listen to ckeditor.form.event to modify field options dynamically:
$eventDispatcher->addListener('ckeditor.form.event', function (FormEvent $event) {
$event->setData(['toolbar' => 'Custom']);
});
How can I help you explore Laravel packages today?