Skip to content

[Feature] Support setting URL fragment with AdminUrlGenerator #7218

@beknownst

Description

@beknownst

Short description of what this feature will allow to do:
Add support for URL fragments (hash anchors) to the AdminUrlGenerator class, enabling developers to generate admin URLs that scroll to specific sections of a page or reference/activate a specific tab (e.g. #tab-main). This could be realised by using Symfony's native router support for URL fragments via the _fragment parameter.

I am aware that it currently is possible to use $this->adminUrlGenerator->set('_fragment', 'tab-main') in order to achieve the requested behaviour, but I find it not very clean and consistent with the other dedicated functions EasyAdmin has (e.g., setEntityId() instead of set('entityId', ...) and setController() instead of set('crudControllerFqcn', ...)).

This enhancement makes it easier for developers to link directly to specific page sections (tabs, accordions, anchors) in their admin interfaces and to reference the fragment functionality in documentation.
_

Example of how to use this feature

$url = $this->adminUrlGenerator
    ->setController(SomeCrudController::class)
    ->setAction(Action::EDIT)
    ->setEntityId(123)
    ->setFragment('tab-inventory')
    ->generateUrl();

// Result: /admin/some/edit/123#tab-inventory

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions