Installation
composer require partitech/sonata-extra
Save the bundle in bundles.php
Partitech\SonataExtra\PartitechSonataExtraBundle::class => ['all' => true],
Load the resources on the Sonata Front Page
{% block sonata_page_stylesheets %}
<link rel="stylesheet" href="{{ asset('bundles/sonatapage/frontend.css') }}" media="all">
<link rel="stylesheet" href="{{ asset('bundles/partitechsonataextra/assets/styles/admin.css') }}" media="all">
{% endblock %}
{% block sonata_page_javascripts %}
<script src="{{ asset('bundles/partitechsonataextra/assets/admin.js') }}"></script>
{% endblock %}
Declare the administration's resources
sonata_admin:
assets:
extra_javascripts:
- js/runroom_sortable_init.js
- js/jquery-ui.min.js
- js/menu-admin.js
- bundles/fosckeditor/ckeditor.js
- bundles/partitechsonataextra/assets/admin.js
extra_stylesheets:
- bundles/sonatatranslation/css/sonata-translation.css
- bundles/partitechsonataextra/assets/styles/admin.css
- css/admin.css
- build/admin.css
Install public resources
php bin/console sonata:extra:install-gutenberg
php bin/console ckeditor:install --tag=4.19.0
php bin/console assets:install
Initialize Sonata Page and its multilingual routes
php bin/console sonata:page:create-site
php bin/console sonata:page:update-core-routes
php bin/console sonata:extra:page-fix-route
php bin/console sonata:page:create-snapshots
Translations can be overridden in your project using the Symfony translation hierarchy in this way:
mkdir translations
touch translations/SonataExtraBundle.fr.yaml
cat vendor/partitech/sonata-extra/translations/messages.fr.yaml > translations/SonataExtraBundle.fr.yaml
You can redirect the user to the expected site and relative path with AuthenticationSuccessHandler dance security.yaml :
firewalls:
admin:
form_login:
success_handler: Partitech\SonataExtra\Handler\AuthenticationSuccessHandler
Adapt the example to the installed version
The Symfony and Sonata examples remain tied to the versions indicated in the article. Symfony 4.x and Symfony 6.2 are no longer maintained: for a current project, use a maintained branch and the documentation that exactly matches your dependencies.
php bin/console about
composer show symfony/framework-bundle sonata-project/admin-bundle
Before resuming the code, check the signatures, services, routes, and templates concerned. Then add a functional test covering permissions, HTTP code, and the visible result.
Reference: maintained Symfony versions.