Installation:
composer require egeloen/ckeditor-bundle
Add the bundle to config/bundles.php:
return [
// ...
Ivory\CKEditorBundle\IvoryCKEditorBundle::class => ['all' => true],
];
Configuration:
Enable the bundle in config/packages/ivory_ck_editor.yaml:
ivory_ck_editor:
default_config: my_default_config
configs:
my_default_config:
toolbar: [ 'bold', 'italic', 'numberedList', 'bulletedList' ]
filebrowserUploadUrl: /upload
filebrowserUploadHandler: IvoryCKEditorBundle:Upload:upload
First Use Case: Add the CKEditor field to a Symfony form:
use Ivory\CKEditorBundle\Form\Type\CKEditorType;
$builder->add('content', CKEditorType::class, [
'config' => 'my_default_config',
]);
Upload Handler (if needed):
Ensure your upload directory is writable and configure the upload controller (provided by the bundle) to handle file uploads.
CKEditorType in Symfony forms for rich-text fields.$builder->add('description', CKEditorType::class, [
'config' => 'rich_text_config',
'attr' => ['class' => 'ckeditor-full'],
]);
ivory_ck_editor.yaml:
configs:
basic_config:
toolbar: ['bold', 'italic']
height: 200
advanced_config:
toolbar: ['bold', 'italic', 'image', 'codeSnippet']
extraPlugins: 'codesnippet'
$builder->add('content', CKEditorType::class, ['config' => 'advanced_config']);
$builder->add('content', CKEditorType::class, [
'config' => function (FormInterface $form, array $options) {
return [
'toolbar' => ['bold', 'italic', 'link'],
'filebrowserImageUploadUrl' => $this->generateUrl('app_upload_image'),
];
},
]);
{# templates/IvoryCKEditor/ckeditor.html.twig #}
{{ parent() }}
{{ ckeditor_extra_js('custom_plugin.js') }}
// src/Controller/UploadController.php
use Ivory\CKEditorBundle\Controller\UploadController as BaseUploadController;
class UploadController extends BaseUploadController
{
public function uploadAction(Request $request)
{
$response = parent::uploadAction($request);
// Add custom logic (e.g., resize images)
return $response;
}
}
filebrowserUploadHandler: App\Controller\UploadController::uploadAction
ckeditor Twig function to render editors directly in templates:
{{ ckeditor(form.content, {
'config': 'basic_config',
'attr': {'class': 'compact-editor'}
}) }}
config/bundles.php step.# config/packages/twig.yaml
twig:
paths: ['%kernel.project_dir%/templates']
globals:
ckeditor_version: '%kernel.cache_dir%/ckeditor_version.txt'
php bin/console cache:clear
laravel/symfony-bridge), ensure:
config/app.php under extra.bundles.ivory_ck_editor.yaml config is merged into Laravel’s configuration system.%kernel.project_dir%/web/uploads/ckeditor) is writable:
mkdir -p web/uploads/ckeditor
chmod -R 775 web/uploads/ckeditor
routing.yaml:
app_upload:
path: /upload
methods: POST
defaults: { _controller: 'App\Controller\UploadController::uploadAction' }
assets key in config/packages/ivory_ck_editor.yaml points to the correct path:
assets:
base_url: /bundles/ivoryckeditor
config or config_name to reference existing configs:
// ❌ Avoid (overwrites everything)
$builder->add('content', CKEditorType::class, [
'config' => ['toolbar' => ['bold']] // Loses other settings
]);
// ✅ Prefer
$builder->add('content', CKEditorType::class, ['config' => 'my_config']);
codesnippet) must be installed via npm or included manually in the assets directory.extraPlugins and their JS/CSS are loaded.debug: true in config/packages/ivory_ck_editor.yaml to log configuration issues:
debug: true
F12) to inspect:
CKEDITOR is not defined).ivory_ck_editor:validate command to check configs:
php bin/console ivory:ckeditor:validate
php bin/console cache:clear
rm -rf var/cache/*
Ivory\CKEditorBundle\Controller\UploadController to add validation or processing:
use Ivory\CKEditorBundle\Controller\UploadController as BaseUploadController;
class CustomUploadController extends BaseUploadController
{
public function uploadAction(Request $request)
{
$response = parent::uploadAction($request);
$file = $response->getFile();
// Add custom logic (e.g., resize images)
return $response;
}
}
# config/services.yaml
services:
App\Service\CKEditorConfigBuilder:
arguments:
$defaultConfig: '%ivory_ck_editor.configs.default%'
// src/Service/CKEditorConfigBuilder.php
class CKEditorConfigBuilder
{
public function build(array $options): array
{
return array_merge($this->defaultConfig, $options);
}
}
Use it in forms:
$builder->add('content', CKEditorType::class, [
'config' => $this->container->get(CKEditorConfigBuilder::class)->build(['height' => 300]),
]);
How can I help you explore Laravel packages today?