ns/ace-sonata-bundle
A Sonata bundle that integrates the Ace code editor into Symfony admin panels, adding syntax-highlighted, in-browser code editing fields for backend forms and content management. Lightweight integration for teams already using Sonata Admin.
This is a Symfony bundle (not Laravel) that wires the Ace editor into Sonata Admin so you can render a real code editor inside admin forms instead of a plain textarea. Given the score (0.005) and 1 dependent, treat it as a reference implementation you'll likely need to fork or vendor rather than a drop-in dependency.
Minimal steps:
composer require ns/ace-sonata-bundle
config/bundles.php (Symfony Flex) or AppKernel.php:
return [
// ...
Ns\AceSonataBundle\NsAceSonataBundle::class => ['all' => true],
];
sonata:admin:setup, assets:install --symlink).Resources/views directory — that's where the Sonata template overrides live, and it tells you exactly which field type is being decorated.Admin class:
protected function configureFormFields(FormMapper $form): void
{
$form
->add('body', null, ['label' => 'Template Body'])
->add('css', null, ['label' => 'CSS']);
}
If the bundle ships a custom form type (check Form/Type), swap null for that type and pass Ace options (mode, theme, height) via the attr array.block_name / attr rather than overriding templates. Template overrides are brittle across Sonata versions.->add('html', null, [
'attr' => ['data-ace-mode' => 'html', 'data-ace-theme' => 'monokai', 'rows' => 20],
])
Then initialize Ace in a small JS file that reads those data attributes.CodeEditorAdmin base class that applies the Ace field type to a configurable list of properties, then extend it for each entity — avoids copy-pasting FormMapper boilerplate.SonataAdminBundle:Form:form_admin_fields.html.twig and conditionally render a <div id="ace-..."> when a data-ace attribute is present. This is where you attach ace.edit(...) and sync the editor value back to the hidden textarea on submit.form.addEventListener('submit', () => textarea.value = editor.getValue()); otherwise the value silently reverts.sonata_admin assets config or a Twig block javascripts override to pull ace.js plus the required mode-*.js / theme-*.js files. Prefer loading from a CDN or a locally installed ace-builds package over the bundle's bundled copy (which will be stale).show action, giving editors a consistent look between edit and view.src/ or use repositories + vcs to pin a patched fork.composer require in a Laravel app — the service provider does not exist. Use laravel-ace-style packages or a plain <script> include instead.mode-* and theme-* into separate files; forgetting to load the mode results in a plain-text editor with no highlighting and no error message. Load ace.js, mode-html.js, theme-monokai.js, ext-language_tools.js explicitly.<textarea> and edits a sibling <div>. If you only initialize on DOMContentLoaded, dynamically added Sonata collection rows (sonata_collection) won't get editors — hook into sonata.admin.event / collection.add callbacks or use MutationObserver.ace.edit() calls. Move initialization to an external JS file or add a nonce; otherwise the editor silently fails to render.console.log(typeof ace) — if undefined, the asset didn't load; if defined but no editor appears, the container ID selector is wrong (Sonata prefixes field IDs, e.g. sonata_my_entity_body).ns_ace_sonata: config keys for default mode/theme; check DependencyInjection/Configuration.php to know the exact keys before guessing.templates/bundles/NsAceSonataBundle/ (Symfony's bundle override path) rather than editing vendor/; this survives composer update — assuming the package is even maintained enough to be updated.ace.edit(). Budget for inlining it rather than fighting upstream.How can I help you explore Laravel packages today?