Skip to content
Advertisement

How to display associated objects with links to their details page in Symfony 5 EasyAdmin 3?

I have two entities, Offer and Candidate, with a OneToMany relationship between them. The relevant code parts are the followings:

In Offer.php:

JavaScript

In Candidate.php:

JavaScript

In OfferCrudController.php:

JavaScript

In CandidateCrudController.php:

JavaScript

My problem is that while in the case of Candidates EasyAdmin displays the Offer linked to its details page for each Candidate, for the Offers it displays only the non-clickable string representations of the Candidates, as the images show it:

clickable Offers

non-clickable Candidates

Is it possible to display the Candidates too with their appropriate links to their details page?

Advertisement

Answer

Yes, it’s possible, but you should create a custom template for this. Let’s say, you’ve created /templates/admin/field/offer/detail/candidates.html.twig. Then in OfferCrudController need to set created template for candidates field*:

JavaScript
  • example with generator, but it can be easily written as array item, like in your example (instead ArrayField). I just prefer to use generator in that case, because that’s more convenient to configure.

And in template just generate URL for each entity:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement