Member-only story

Load Stimulus Controllers in Symfony EasyAdmin

Stefan Pöltl
3 min read3 days ago

--

I had the use case to enable drag and drop sorting in an EasyAdmin user interface. I want to reuse stimulus controllers I already coded on the Crud index page and take advantage of the simplicity of the Asset Mapper component.

Install Symfony and EasyAdmin

composer create-project symfony/skeleton:"7.2.x" my_project_directory
cd my_project_directory
composer require webapp

composer require easycorp/easyadmin-bundle

Boot Stimulus in the Admin

In order to dynamically load the Stimulus controller as you are used to, we must first create an entry point:

Path: assets/admin.js

import './bootstrap.js';

Add admin.js as entrypoint to your importmap.php in the project root

return [
'app' => [
'path' => './assets/app.js',
'entrypoint' => true,
],
'admin' => [
'path' => './assets/admin.js',
'entrypoint' => true,
],

Now we need to load the import map globally in EasyAdmin by overriding the EasyAdmin layout template:

Path: templates/bundles/EasyAdminBundle/layout.html.twig

{% extends '@!EasyAdmin/layout.html.twig' %}
{% block importmap %}
{{ parent() }}
{{ importmap('admin') }}
{% endblock %}

That’s it, now you can use all your Stimulus controllers in EasyAdmin!

--

--

Stefan Pöltl
Stefan Pöltl

No responses yet