norzechowicz/aceeditor-bundle
Symfony bundle that integrates the Ace code editor into your app, providing form field support for editing code with syntax highlighting, themes, and editor options. Useful for admin panels, CMS editors, and any UI that needs in-browser code editing.
composer require norzechowicz/aceeditor-bundle
config/bundles.php:
Norzechowicz\AceEditorBundle\NorzechowiczAceEditorBundle::class => ['all' => true],
config/packages/ace_editor.yaml
norzechowicz_ace_editor:
theme: 'monokai'
mode: 'php' # or 'javascript', 'html', etc.
use Norzechowicz\AceEditorBundle\Form\Type\AceEditorType;
$builder->add('code', AceEditorType::class, [
'theme' => 'monokai',
'mode' => 'php',
'options' => ['attr' => ['class' => 'my-custom-class']],
]);
textarea with an Ace Editor for syntax-highlighted code input.$builder->add('javascript', AceEditorType::class, [
'theme' => 'github',
'mode' => 'javascript',
'height' => 400,
'width' => 'auto',
]);
options to pass Ace Editor configuration:
'options' => [
'fontSize' => '14px',
'showLineNumbers' => true,
'tabSize' => 4,
]
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$data = $event->getData();
if ($data && !empty($data->getCode())) {
$event->getForm()->add('code', AceEditorType::class, [
'value' => $data->getCode(),
]);
}
});
{{ form_widget(form.code) }}
.ace_editor {
border: 1px solid #ddd;
border-radius: 4px;
}
'read_only' => true,
assets or CDN:
norzechowicz_ace_editor:
assets:
themes: ['github', 'monokai']
modes: ['php', 'javascript']
Asset Loading Issues
ace.js and theme/mode files are accessible.404 errors for missing JS/CSS).assets config in ace_editor.yaml or manually include assets in your base template.Form Theme Conflicts
data-turbo-frame or use {{ form_row(form.code) }} instead of {{ form_widget(form.code) }}.Initial Value Not Persisting
value is set but ignored, check for:
PRE_SET_DATA event handling.dump($form->getData()) in a PRE_SUBMIT event.Check Console for Errors Ace Editor logs errors to the browser console. Look for:
Uncaught TypeError: ace.edit is not a function
→ Likely due to missing ace.js or incorrect initialization order.
Inspect Rendered HTML
Ensure the editor container has the correct data-ace-editor attributes:
<textarea data-ace-editor="true" data-ace-theme="monokai" data-ace-mode="php"></textarea>
Custom Themes/Modes
Add via assets config or manually include in your layout:
<script src="{{ asset('vendor/ace-builds/src-min-noconflict/ext-language_tools.js') }}"></script>
Override JavaScript Initialization Extend the bundle’s JS via a custom asset:
// public/js/ace_editor_extensions.js
document.addEventListener('DOMContentLoaded', function() {
ace.config.set('basePath', '/vendor/ace-builds/src-min-noconflict/');
// Custom logic (e.g., auto-indent on save)
});
Include it after the bundle’s JS in your base template.
Server-Side Validation
Validate code syntax using a library like php-parser:
$builder->add('code', AceEditorType::class)
->addModelTransformer(new CallbackTransformer(
function ($code) { return $code; },
function ($code) {
// Validate here (e.g., check for syntax errors)
return $code;
}
));
How can I help you explore Laravel packages today?