Install the Bundle
composer require atheon/ckeditor-bundle
Add to config/bundles.php (Symfony 4+):
return [
// ...
Atheon\CKEditorBundle\AtheonCKEditorBundle::class => ['all' => true],
];
Enable the Form Type
Register the ckeditor form type in your config/packages/atheon_ckeditor.yaml:
atheon_ckeditor:
editor_file: 'ckeditor/ckeditor.js' # Path to CKEditor JS file
editor_basepath: '/bundles/atheonckeditor/' # Base URL for CKEditor assets
First Usage in a Form
use Atheon\CKEditorBundle\Form\Type\CKEditorType;
$builder->add('content', CKEditorType::class, [
'config' => [
'toolbar' => 'Basic', // Predefined toolbar or custom config
],
]);
Verify Assets
Ensure CKEditor assets (ckeditor.js, plugins, skins) are published:
php bin/console atheon:ckeditor:install
{{ form_start(form) }}
{{ form_row(form.content) }} <!-- Renders CKEditor -->
<button type="submit">Save</button>
{{ form_end(form) }}
Override default settings via YAML or PHP:
# config/packages/atheon_ckeditor.yaml
atheon_ckeditor:
editor_config:
toolbar:
- ['Bold', 'Italic']
- ['NumberedList', 'BulletedList']
removePlugins: 'elementspath'
Pass inline config to the form type:
$builder->add('bio', CKEditorType::class, [
'config' => [
'height' => 300,
'extraPlugins' => 'codesnippet',
],
]);
php bin/console atheon:ckeditor:install to copy CKEditor files to public/bundles/atheonckeditor/.editor_basepath in config to point to a CDN or local directory.// src/Entity/Article.php
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
class Article {
/**
* @ORM\Column(type="text")
* @Assert\NotBlank
*/
private $content;
}
Access CKEditor assets in Twig:
{{ atheon_ckeditor_assets() }} <!-- Renders JS/CSS links -->
Assert\Length or custom constraints on the text field.DataTransformerInterface.Symfony\Component\DomCrawler\Crawler or HTMLPurifier to clean HTML before storage.Symfony\Panther to test CKEditor UI interactions.Asset Paths
composer install.php bin/console atheon:ckeditor:install or manually copy files to public/bundles/atheonckeditor/.ln -s vendor/egeloen/ckeditor-bundle/Resources/public/ckeditor public/bundles/atheonckeditor/
CKEditor Version Mismatch
editor_file in config.XSS Vulnerabilities
Symfony\Component\Security\Csrf\TokenManager or libraries like HTMLPurifier:
$purifier = new \HTMLPurifier();
$cleanHtml = $purifier->purify($rawHtml);
Configuration Overrides
config_name in form options to merge configs:
$builder->add('content', CKEditorType::class, [
'config_name' => 'custom_config', // References a named config in YAML
]);
Debugging
# config/packages/dev/atheon_ckeditor.yaml
atheon_ckeditor:
debug: true
Performance
{% block javascripts %}.Localization
config:
atheon_ckeditor:
editor_config:
language: 'fr'
Advanced Features
VichUploaderBundle for image uploads:
'config' => [
'filebrowserImageUploadUrl' => '/upload/image',
'filebrowserBrowseUrl' => '/browser',
],
ckfinder, mathjax) by including them in extraPlugins.Upgrade Path
symfony/dependency-injection constraints in composer.json.Extension Points
CKEditorType for reusable configurations:
class CustomCKEditorType extends CKEditorType {
public function configureOptions(OptionsResolver $resolver) {
$resolver->setDefaults([
'config' => [
'toolbar' => ['CustomToolbar'],
],
]);
}
}
CI/CD
- run: php bin/console atheon:ckeditor:install --no-debug
How can I help you explore Laravel packages today?