adnedelcu/summernote-bundle
Symfony bundle that integrates the Summernote WYSIWYG editor. Install via Composer, enable in AppKernel, and configure selector, toolbar, size, and asset includes (jQuery/Bootstrap/FontAwesome). Optional plugins and pasted image upload via custom route.
Installation:
composer require adnedelcu/summernote-bundle
Enable the bundle in config/bundles.php (Symfony 4+) or AppKernel.php (Symfony 2/3):
ADN\SummernoteBundle\ADNSummernoteBundle::class => ['all' => true],
Basic Usage: Add the Twig extension to your template:
{{ adn_summernote({
id: 'my-editor',
content: 'Initial content here'
}) }}
Include the required JS/CSS in your base template:
{{ adn_summernote_stylesheets() }}
{{ adn_summernote_javascripts() }}
First Use Case: Create a form field for rich text editing:
{{ form_row(form.description, {
'attr': {
'class': 'summernote',
'data-summernote': json_encode({
height: 300,
toolbar: [
['style', ['style']],
['font', ['bold', 'italic', 'underline']],
['insert', ['link']]
]
})
}
}) }}
Dynamic Configuration: Pass options dynamically via Twig:
{% set options = {
height: 400,
callbacks: {
onInit: 'function() { console.log("Editor initialized"); }'
}
} %}
{{ adn_summernote({ id: 'dynamic-editor', options: options }) }}
Form Integration: Bind to Symfony forms:
// Controller
$form = $this->createFormBuilder($entity)
->add('content', TextType::class, [
'attr' => ['class' => 'summernote']
])
->getForm();
{{ form_widget(form.content) }}
Asset Management:
Override default assets by configuring paths in config/packages/adn_summernote.yaml:
adn_summernote:
assets:
css: '/custom/path/summernote.css'
js: '/custom/path/summernote.min.js'
Plugin Management: Enable/disable plugins globally:
adn_summernote:
plugins:
- 'codeview'
- 'table'
disabled_plugins:
- 'insertvideo'
Event Handling: Listen for editor events via JavaScript:
{{ adn_summernote_javascripts() }}
<script>
$('#my-editor').on('summernote.change', function(we, contents) {
console.log('Content changed:', contents);
});
</script>
Asset Loading Order:
adn_summernote_stylesheets() and adn_summernote_javascripts() are loaded before the editor initialization.Plugin Conflicts:
insertvideo) may require additional dependencies (e.g., YouTube API).Symfony 4+ Configuration:
config/packages/adn_summernote.yaml (Symfony 4+) or app/config/config.yml (Symfony 2/3).bundles.php for Symfony 4.Form Data Binding:
htmlspecialchars_decode() when retrieving data:
$cleanContent = htmlspecialchars_decode($entity->getContent());
Caching Issues:
{{ adn_summernote_stylesheets({ version: '1.0.0' }) }}
Check Console for Errors:
404 errors on asset paths or JavaScript errors in the browser console.Verify Bundle Activation:
debug:container:
php bin/console debug:container adn_summernote
Inspect Generated HTML:
Custom Templates:
Override Twig templates by copying them from:
vendor/adnedelcu/summernote-bundle/Resources/views/ to templates/bundles/adnsummernote/.
Event Subscribers:
Extend functionality via Symfony events (e.g., kernel.request to dynamically modify editor options).
Webpack Encore Integration: For Symfony Flex projects, manually include Summernote via:
// webpack.config.js
Encore
.addEntry('summernote', './node_modules/summernote/dist/summernote.min.js')
.enableReactPreset()
.copyFiles({
from: './node_modules/summernote/dist/',
to: 'build/[name].[ext]',
pattern: /\.(css|js)$/
});
Advanced Configuration: Use PHP services to dynamically generate options:
# config/services.yaml
services:
App\Service\SummernoteConfigurator:
arguments:
$plugins: '%kernel.debug% ? ["codeview"] : []'
{{ adn_summernote(app.summernote_configurator.getOptions()) }}
How can I help you explore Laravel packages today?