creative-web-solution/cws-quilljs-bundle
Symfony bundle that integrates the QuillJS rich text editor. Install via Composer, register the bundle, then configure cws_quill_js in config/packages to enable it and define toolbar buttons (bold/italic, lists, links, clean, etc.).
composer require creative-web-solution/cws-quilljs-bundle
config/bundles.php:
Cws\Bundle\QuillJsBundle\CwsQuillJsBundle::class => ['all' => true],
config/packages/cws_quill_js.yaml:
cws_quill_js:
enabled: true
toolbar:
- ['bold', 'italic']
QuillJsType:
use Cws\Bundle\QuillJsBundle\Form\Type\QuillJsType;
$builder->add('content', QuillJsType::class);
Render the form in a Twig template. The bundle auto-loads QuillJS assets.QuillJsType for any textarea field requiring rich text:
$builder->add('description', QuillJsType::class, [
'toolbar_config' => [
['bold', 'italic', 'underline'],
['link', 'image']
]
]);
# config/packages/cws_quill_js.yaml
cws_quill_js:
default_toolbar: ['bold', 'italic']
field_specific:
article_content: [['bold', 'italic', 'link'], ['clean']]
Then reference in form:
$builder->add('article_content', QuillJsType::class, ['field_name' => 'article_content']);
quill, quill.snow) via Symfony’s asset mapper. No manual <script> tags needed.templates/bundles/cwsquilljs/).use Symfony\Component\DomCrawler\Crawler;
$html = $form->get('content')->getData();
$crawler = new Crawler($html);
$sanitized = $crawler->html(); // Basic sanitization
const quill = document.querySelector('.ql-editor').closest('.quill').quill;
const delta = quill.getContents(); // Raw delta format
quill_js_editor Twig function to render standalone editors:
{{ quill_js_editor({
'id': 'custom-editor',
'toolbar': [['bold'], ['italic']],
'value': old_content
}) }}
// webpack.config.js
Encore.enableSingleRuntimeChunk()
.disableSingleRuntimeChunk()
.configureBabel(() => { /* ... */ })
.copyFiles({
from: './vendor/creative-web-solution/cws-quilljs-bundle/public',
to: 'bundles/cwsquilljs/[path][name].[ext]',
pattern: /\.(js|css)$/
});
csrf_token helper in JavaScript:
const token = document.querySelector('meta[name="csrf-token"]').content;
fetch('/save', {
method: 'POST',
headers: { 'X-CSRF-Token': token },
body: JSON.stringify({ content: quill.getContents() })
});
field_specific must match the form field name exactly (case-sensitive).quill is not defined if assets fail to load. Verify:
app/design/config/bundles.php includes the bundle.cws_quill_js.yaml.php bin/console cache:clear.[['bold'], ['italic']]), not a flat array.cws_quill_js:
modules:
syntax: true
mentions:
endpoint: '/api/mentions'
Then use in Twig:
{{ quill_js_editor({
'modules': ['syntax', 'mentions']
}) }}
document.querySelector('.ql-editor').addEventListener('blur', (e) => {
const content = e.target.closest('.ql-container').querySelector('.ql-editor').innerHTML;
// Trigger Symfony event or AJAX save
});
vendor/creative-web-solution/cws-quilljs-bundle/templates/ to templates/bundles/cwsquilljs/ to customize editor behavior.cws_quill_js:
enabled: false # Disable globally
Then enable per field:
$builder->add('content', QuillJsType::class, ['enabled' => true]);
# config/packages/asset_mapper.yaml
framework:
assets:
version_strategy: hash
How can I help you explore Laravel packages today?