Last time, I left you the Author CRUD as an exercise. Here’s my version, a quick test, and then the simplest way to translate the whole admin into French.
The Author CRUD
The Author entry is in the menu, and the whole screen is in French: Tous les auteurs, Ajouter un auteur, and every button.
The menu item
public function configureMenuItems(): iterable
{
yield MenuItem::linkToDashboard('Dashboard', 'fa fa-home');
yield MenuItem::linkTo(AuthorCrudController::class, 'Auteur', 'fa fa-user');
yield MenuItem::linkTo(CategoryCrudController::class, 'Catégorie', 'fa fa-tag');
}
The fields
public function configureFields(string $pageName): iterable
{
return [
TextField::new('firstName')->setLabel('Prénom'),
TextField::new('lastName')->setLabel('Nom')->setRequired(true)->setSortable(true),
SlugField::new('authorSlug')->setTargetFieldName(['firstName', 'lastName'])->setLabel('Slug'),
TextEditorField::new('biography')->setLabel('Biographie')
->formatValue(fn (?string $value) => new Markup($value ?? '', 'UTF-8')),
DateField::new('birthday')->setLabel('Date de naissance')->setFormat('dd-MM-yyyy'),
];
}
| Field | Type | Why |
|---|---|---|
| First and last name | TextField | Simple text |
| Slug | SlugField | Built from first and last name, used in URLs |
| Biography | TextEditorField | Rich text: bold, italic, links, lists… |
| Date of birth | DateField | With a French date format |
Wrapping the biography in a Twig Markup object renders the formatting (bold, italic) in the detail view, instead of raw HTML.
The actions
Same principle as the Category CRUD, with more buttons customized: new, edit, delete, view, create… We also add the detail action to the list, since it isn’t enabled by default:
public function configureActions(Actions $actions): Actions
{
return $actions
->add(Crud::PAGE_INDEX, Action::DETAIL)
->update(Crud::PAGE_INDEX, Action::NEW, fn (Action $a) => $a->setLabel('Ajouter un auteur'))
->update(Crud::PAGE_INDEX, Action::EDIT, fn (Action $a) => $a->setLabel('Éditer'))
->update(Crud::PAGE_INDEX, Action::DELETE, fn (Action $a) => $a->setLabel('Retirer'))
->update(Crud::PAGE_INDEX, Action::DETAIL, fn (Action $a) => $a->setLabel('Voir'));
}
I did the same for the Category buttons.
A quick test
Create an author named Test, with a biography in bold and italic, and click Create. It shows up at the end of the list, and the detail view displays the formatting correctly. Then delete it, and it’s gone.
Translating the Rest of EasyAdmin
Some texts are still in English: the delete confirmation pop-up, the search field, “20 results”… You have three options:
- By hand, in each CRUD controller, as we did for the labels and buttons. Precise, but long.
- With Symfony’s translation files, instead of writing every label in the code.
- Change the default locale. EasyAdmin then uses its own built-in French translations everywhere.
Option 3 is the quickest. Open config/packages/translation.yaml and change en to fr:
framework:
default_locale: fr
translator:
default_path: '%kernel.project_dir%/translations'
Refresh: Search becomes Rechercher, the result count is in French, and so is the delete confirmation. This works with any language you need.
Pushing to GitHub
As usual, we save our work:
git status
git add .
git commit -m "author category crud"
git push origin main
On GitHub, the minibib repository now contains the changes.
Exercise · A filter by name
Add a filter on the last name to the Author CRUD, to quickly find an author in a long list.
Show the solution
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
public function configureFilters(Filters $filters): Filters
{
return $filters->add('lastName');
}
A Filters button appears above the list. EasyAdmin picks the right kind of filter based on the field’s type.
What’s Next
Next up is the most important entity of the project: the Book CRUD.
This is Chapter 8 of the Mini Library course. Follow along to build a complete Symfony 8 + EasyAdmin digital library application from scratch.