Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion doc/crud.rst
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ Use the ``unsetAll()`` method to remove all existing query parameters::
$url = $this->adminUrlGenerator
->setController(SomeCrudController::class)
->setAction('theActionName')
->setFragment('tab-main')
->generateUrl();

// ...
Expand Down Expand Up @@ -848,7 +849,8 @@ method (it will be called automatically for you):

{% set url = ea_url()
.setController('App\\Controller\\Admin\\SomeCrudController')
.setAction('theActionName') %}
.setAction('theActionName')
.setFragment('tab-main') %}

Generating CRUD URLs from outside EasyAdmin
...........................................
Expand Down
1 change: 1 addition & 0 deletions src/Config/Option/EA.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ final class EA
public const ROUTE_NAME = 'routeName';
public const ROUTE_PARAMS = 'routeParams';
public const ROUTE_CREATED_BY_EASYADMIN = 'routeCreatedByEasyAdmin';
public const ROUTE_FRAGMENT = '_fragment';
public const SORT = 'sort';
/** @deprecated this parameter is no longer used because menu items are now highlighted automatically */
public const SUBMENU_INDEX = 'submenuIndex';
Expand Down
7 changes: 7 additions & 0 deletions src/Router/AdminUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ public function setEntityId(mixed $entityId): AdminUrlGeneratorInterface
return $this;
}

public function setFragment(string $fragment): AdminUrlGeneratorInterface
{
$this->setRouteParameter(EA::ROUTE_FRAGMENT, $fragment);

return $this;
}

public function get(string $paramName): mixed
{
if (false === $this->isInitialized) {
Expand Down
2 changes: 2 additions & 0 deletions src/Router/AdminUrlGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public function setRoute(

public function setEntityId(mixed $entityId): self;

public function setFragment(string $fragment): self;

public function get(string $paramName): mixed;

public function set(string $paramName, mixed $paramValue): self;
Expand Down
8 changes: 8 additions & 0 deletions tests/Router/AdminUrlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,14 @@ public function testRelativeUrls()
$this->assertSame('http://localhost/admin?crudAction=index&crudControllerFqcn=App%5CController%5CAdmin%5CSomeCrudController&foo=bar&foo1=bar1', $adminUrlGenerator->generateUrl());
}

public function testSetFragment()
{
$adminUrlGenerator = $this->getAdminUrlGenerator();

$adminUrlGenerator->setFragment('tab-1');
$this->assertSame('http://localhost/admin?foo=bar#tab-1', $adminUrlGenerator->generateUrl());
}

private function getAdminUrlGenerator(bool $signedUrls = false, bool $absoluteUrls = true): AdminUrlGeneratorInterface
{
self::bootKernel();
Expand Down