Skip to content

Feature Request: Native Support for Embedded Entity Detail View in AssociationField #7389

@BriceFab

Description

@BriceFab

Use Case

When displaying an associated entity in a detail page, we often want to show all its fields directly in the detail view, not just a link. This is similar to renderAsEmbeddedForm() for forms, but for detail pages.

Current Workaround

To achieve this, we need to:

  1. Create a custom Twig component/service that:
    • Retrieves the field configuration from the associated entity's CRUD controller
    • Uses EntityFactory::createForEntityInstance() and FieldFactory::processFields() to generate FieldDto objects
    • Filters out layout fields and fields hidden on detail pages
    • Renders fields using EasyAdmin's render_field_contents macro
  2. Create a custom template that calls this component
  3. Configure the AssociationField to use this custom template via setTemplatePath()

This works but requires significant boilerplate and deep knowledge of EasyAdmin internals.

Proposed Solution

Add a method similar to renderAsEmbeddedForm() but for detail pages:

yield AssociationField::new('fitnessProfile')
    ->renderAsEmbeddedDetail(FitnessProfileCrudController::class)
    ->onlyOnDetail();

This would:

  • Automatically fetch and render all fields configured for the detail page of the associated entity
  • Use the same field configuration, formatting, and rendering logic as the main detail page
  • Maintain consistency with EasyAdmin's UI and behavior
  • Handle edge cases (null associations, hidden fields, layout fields, etc.)

Benefits

  1. Consistency: Uses the same field configuration and rendering as the main detail page
  2. Maintainability: Changes to the associated entity's field configuration are automatically reflected
  3. Simplicity: No custom code needed for a common use case
  4. Type safety: Leverages existing EasyAdmin infrastructure

Implementation Notes

  • Should reuse existing EntityFactory and FieldFactory logic
  • Should respect field visibility settings (onlyOnDetail(), hideOnDetail(), etc.)
  • Should filter out layout fields (tabs, panels, etc.)
  • Could optionally support a subset of fields via a parameter

This would complement renderAsEmbeddedForm() and provide a native way to display embedded entity details without custom workarounds.

Thank you in advance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions