Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b05a224

Browse files
committed
Merge branch '4.x' into 5.x
* 4.x: Added a note in the UPGRADE file Introduce a new type of menu item to link to any controller Minor tweak fix: Modified CrudAutocompleteSubscriber to use non doctrine-native ULID Fix another occurrence in autocomplete() method Update action confirmation modal title in Polish Refactor/dto collections Renamed the class Fix inconsistent label generation for AssociationField and EntityFilter Fix some deprecations Add tests for the nested embedded properties search fix Fix search on nested embedded properties Add a test for the previous merge Minor fixes related to previous merge Allow setQueryBuilder() callable to return a custom QueryBuilder Minor tweak Refactor close field creation to use a common method Fix filter on embedded properties Bump webpack from 5.96.1 to 5.104.1 Fallback to entity FQCN short name if entity translation feature is not used
2 parents 1e0c1e5 + edca188 commit b05a224

87 files changed

Lines changed: 2116 additions & 1149 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

UPGRADE.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
Upgrade between EasyAdmin 4.x versions
22
======================================
33

4+
EasyAdmin 4.29.0
5+
----------------
6+
7+
The `linkToCrud()` method used to link to CRUD controllers from the main menu of the
8+
dashboard is deprecated in favor of the new `linkTo()` method:
9+
10+
// Before
11+
yield MenuItem::linkToCrud('Categories', 'fa fa-tags', Category::class);
12+
yield MenuItem::linkToCrud('Blog Posts', 'fa fa-file-text', BlogPost::class);
13+
yield MenuItem::linkToCrud(null, null, Comment::class);
14+
15+
// After
16+
yield MenuItem::linkTo(CategoryCrudController::class, 'Categories', 'fa fa-tags');
17+
yield MenuItem::linkTo(BlogPostCrudController::class, 'Blog Posts', 'fa fa-file-text');
18+
yield MenuItem::linkTo(CommentCrudController::class);
19+
420
EasyAdmin 4.26.0
521
----------------
622

doc/dashboards.rst

Lines changed: 90 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,10 @@ The main menu is a collection of objects implementing
319319
``EasyCorp\Bundle\EasyAdminBundle\Contracts\Menu\MenuItemInterface`` that configure
320320
the look and behavior of each menu item::
321321

322-
use App\Entity\BlogPost;
323-
use App\Entity\Category;
324-
use App\Entity\Comment;
325-
use App\Entity\User;
322+
use App\Controller\Admin\BlogPostCrudController;
323+
use App\Controller\Admin\CategoryCrudController;
324+
use App\Controller\Admin\CommentCrudController;
325+
use App\Controller\Admin\UserCrudController;
326326
use EasyCorp\Bundle\EasyAdminBundle\Attribute\AdminDashboard;
327327
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
328328
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
@@ -338,12 +338,12 @@ the look and behavior of each menu item::
338338
MenuItem::linkToDashboard('Dashboard', 'fa fa-home'),
339339

340340
MenuItem::section('Blog'),
341-
MenuItem::linkToCrud('Categories', 'fa fa-tags', Category::class),
342-
MenuItem::linkToCrud('Blog Posts', 'fa fa-file-text', BlogPost::class),
341+
MenuItem::linkTo(CategoryCrudController::class, 'Categories', 'fa fa-tags'),
342+
MenuItem::linkTo(BlogPostCrudController::class, 'Blog Posts', 'fa fa-file-text'),
343343

344344
MenuItem::section('Users'),
345-
MenuItem::linkToCrud('Comments', 'fa fa-comment', Comment::class),
346-
MenuItem::linkToCrud('Users', 'fa fa-user', User::class),
345+
MenuItem::linkTo(CommentCrudController::class, 'Comments', 'fa fa-comment'),
346+
MenuItem::linkTo(UserCrudController::class, 'Users', 'fa fa-user'),
347347
];
348348
}
349349
}
@@ -390,13 +390,73 @@ The rest of options depend on each menu item type, as explained in the next sect
390390
Menu Item Types
391391
~~~~~~~~~~~~~~~
392392

393+
Controller Menu Item
394+
....................
395+
396+
This is the most common menu item type. Use ``MenuItem::linkTo()`` to link to
397+
any admin controller: CRUD controllers, Dashboard controllers, or custom
398+
controllers with the ``#[AdminRoute]`` attribute.
399+
400+
The first argument is the FQCN *(fully-qualified class name)* of the controller.
401+
The label and icon are optional (when linking to a CRUD controller without a
402+
label, EasyAdmin derives it automatically from the entity name)::
403+
404+
use App\Controller\Admin\CategoryCrudController;
405+
use App\Controller\Admin\LegacyCategoryCrudController;
406+
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
407+
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
408+
409+
public function configureMenuItems(): iterable
410+
{
411+
return [
412+
// ...
413+
414+
// links to the 'index' action of the Category CRUD controller
415+
// the label is auto-derived from the entity name (e.g. "Categories")
416+
MenuItem::linkTo(CategoryCrudController::class),
417+
418+
// you can pass an explicit label and icon
419+
MenuItem::linkTo(CategoryCrudController::class, 'Categories', 'fa fa-tags'),
420+
421+
// links to a different CRUD action
422+
MenuItem::linkTo(CategoryCrudController::class, 'Add Category', 'fa fa-tags')
423+
->setAction(Action::NEW),
424+
425+
MenuItem::linkTo(CategoryCrudController::class, 'Show Main Category', 'fa fa-tags')
426+
->setAction(Action::DETAIL)
427+
->setEntityId(40585),
428+
429+
// uses custom sorting options for the listing
430+
MenuItem::linkTo(CategoryCrudController::class, 'Categories', 'fa fa-tags')
431+
->setDefaultSort(['createdAt' => 'DESC']),
432+
];
433+
}
434+
435+
You can also link to your own Symfony controllers if they use the
436+
``#[AdminRoute]`` attribute to integrate them in EasyAdmin::
437+
438+
use App\Controller\Admin\AnalyticsDashboardController;
439+
440+
MenuItem::linkTo(AnalyticsDashboardController::class, 'Analytics', 'fa fa-chart-line');
441+
442+
If the controller is invokable (has a ``__invoke()`` method), the action is
443+
detected automatically. Otherwise, call ``->setAction('theActionName')`` to
444+
specify which action to link to.
445+
393446
CRUD Menu Item
394447
..............
395448

396-
This is the most common menu item type and it links to some action of some
397-
:doc:`CRUD controller </crud>`. Instead of passing the FQCN *(fully-qualified
398-
class name)* of the CRUD controller, you must pass the FQCN of the Doctrine
399-
entity associated to the CRUD controller::
449+
.. note::
450+
451+
``MenuItem::linkToCrud()`` is still fully supported, but ``MenuItem::linkTo()``
452+
(explained above) is now the recommended way to create menu items that link to
453+
CRUD controllers. ``linkTo()`` provides a unified API that works with any type
454+
of admin controller and puts the controller class first, making the code
455+
easier to navigate and refactor.
456+
457+
``MenuItem::linkToCrud()`` links to some action of some :doc:`CRUD controller </crud>`.
458+
Instead of passing the FQCN of the CRUD controller, you pass the FQCN of the
459+
Doctrine entity associated to the CRUD controller::
400460

401461
use App\Entity\Category;
402462
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
@@ -446,6 +506,16 @@ have to specify the route name (it's found automatically)::
446506
];
447507
}
448508

509+
.. tip::
510+
511+
You can also use ``MenuItem::linkTo()`` to link to a dashboard. This is
512+
especially useful when you have multiple dashboards and want to link to a
513+
*different* one::
514+
515+
use App\Controller\Admin\AnalyticsDashboardController;
516+
517+
MenuItem::linkTo(AnalyticsDashboardController::class, 'Analytics', 'fa fa-chart-line');
518+
449519
Route Menu Item
450520
...............
451521

@@ -558,15 +628,18 @@ Submenus
558628
The main menu can display up to two level nested menus. Submenus are defined
559629
using the ``subMenu()`` item type::
560630

631+
use App\Controller\Admin\BlogPostCrudController;
632+
use App\Controller\Admin\CategoryCrudController;
633+
use App\Controller\Admin\CommentCrudController;
561634
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
562635

563636
public function configureMenuItems(): iterable
564637
{
565638
return [
566639
MenuItem::subMenu('Blog', 'fa fa-article')->setSubItems([
567-
MenuItem::linkToCrud('Categories', 'fa fa-tags', Category::class),
568-
MenuItem::linkToCrud('Posts', 'fa fa-file-text', BlogPost::class),
569-
MenuItem::linkToCrud('Comments', 'fa fa-comment', Comment::class),
640+
MenuItem::linkTo(CategoryCrudController::class, 'Categories', 'fa fa-tags'),
641+
MenuItem::linkTo(BlogPostCrudController::class, 'Posts', 'fa fa-file-text'),
642+
MenuItem::linkTo(CommentCrudController::class, 'Comments', 'fa fa-comment'),
570643
]),
571644
// ...
572645
];
@@ -591,8 +664,8 @@ generator to return the menu items::
591664

592665
if ('... some complex expression ...') {
593666
yield MenuItem::section('Blog');
594-
yield MenuItem::linkToCrud('Categories', 'fa fa-tags', Category::class);
595-
yield MenuItem::linkToCrud('Blog Posts', 'fa fa-file-text', BlogPost::class);
667+
yield MenuItem::linkTo(CategoryCrudController::class, 'Categories', 'fa fa-tags');
668+
yield MenuItem::linkTo(BlogPostCrudController::class, 'Blog Posts', 'fa fa-file-text');
596669
}
597670

598671
// ...

doc/security.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ user must have to see the menu item::
110110
return [
111111
// ...
112112

113-
MenuItem::linkToCrud('Blog Posts', null, BlogPost::class)
113+
MenuItem::linkTo(BlogPostCrudController::class, 'Blog Posts')
114114
->setPermission('ROLE_EDITOR'),
115115
];
116116
}
@@ -132,7 +132,7 @@ menu item definition to not have to deal with array merges::
132132
yield MenuItem::linkToDashboard('Dashboard', 'fa fa-home');
133133

134134
if ($this->isGranted('ROLE_EDITOR') && '...') {
135-
yield MenuItem::linkToCrud('Blog Posts', null, BlogPost::class);
135+
yield MenuItem::linkTo(BlogPostCrudController::class, 'Blog Posts');
136136
}
137137

138138
// ...

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"slugify": "^1.4.0",
1919
"tom-select": "^2.0.1",
2020
"trix": "^2.1.16",
21-
"webpack": "^5.0.0",
21+
"webpack": "^5.104.1",
2222
"webpack-cli": "^5.1.4"
2323
},
2424
"license": "UNLICENSED",

src/Collection/ActionCollection.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@
22

33
namespace EasyCorp\Bundle\EasyAdminBundle\Collection;
44

5-
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Collection\CollectionInterface;
65
use EasyCorp\Bundle\EasyAdminBundle\Dto\ActionDto;
76
use EasyCorp\Bundle\EasyAdminBundle\Dto\ActionGroupDto;
87

98
/**
109
* @author Javier Eguiluz <[email protected]>
11-
*
12-
* @implements CollectionInterface<string, ActionDto|ActionGroupDto>
1310
*/
14-
final class ActionCollection implements CollectionInterface
11+
final class ActionCollection implements \ArrayAccess, \Countable, \IteratorAggregate
1512
{
1613
/**
1714
* @param array<string, ActionDto|ActionGroupDto> $actions
1815
*/
19-
private function __construct(private array $actions)
16+
public function __construct(private array $actions = [])
2017
{
2118
}
2219

@@ -28,6 +25,8 @@ public function __clone()
2825
}
2926

3027
/**
28+
* @deprecated since 4.28.2 and removed in 5.0.0, use FilterCollection::__construct() instead.
29+
*
3130
* @param array<string, ActionDto|ActionGroupDto> $actions
3231
*/
3332
public static function new(array $actions): self
@@ -83,15 +82,15 @@ public function getIterator(): \ArrayIterator
8382

8483
public function getGlobalActions(): self
8584
{
86-
return self::new(array_filter(
85+
return new self(array_filter(
8786
$this->actions,
8887
static fn (ActionDto|ActionGroupDto $action): bool => $action->isGlobalAction()
8988
));
9089
}
9190

9291
public function getBatchActions(): self
9392
{
94-
return self::new(array_filter(
93+
return new self(array_filter(
9594
$this->actions,
9695
static fn (ActionDto|ActionGroupDto $action): bool => $action instanceof ActionDto && $action->isBatchAction()
9796
));

src/Collection/EntityCollection.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,23 @@
22

33
namespace EasyCorp\Bundle\EasyAdminBundle\Collection;
44

5-
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Collection\CollectionInterface;
65
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
76

87
/**
98
* @author Javier Eguiluz <[email protected]>
10-
*
11-
* @implements CollectionInterface<string, EntityDto>
129
*/
13-
final class EntityCollection implements CollectionInterface
10+
final class EntityCollection implements \ArrayAccess, \Countable, \IteratorAggregate
1411
{
1512
/**
1613
* @param array<string, EntityDto> $entities
1714
*/
18-
private function __construct(private array $entities)
15+
public function __construct(private array $entities = [])
1916
{
2017
}
2118

2219
/**
20+
* @deprecated since 4.28.2 and removed in 5.0.0, use FilterCollection::__construct() instead.
21+
*
2322
* @param array<string, EntityDto> $entities
2423
*/
2524
public static function new(array $entities): self

src/Collection/FieldCollection.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,22 @@
22

33
namespace EasyCorp\Bundle\EasyAdminBundle\Collection;
44

5-
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Collection\CollectionInterface;
65
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface;
76
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
87
use EasyCorp\Bundle\EasyAdminBundle\Field\Field;
98

109
/**
1110
* @author Javier Eguiluz <[email protected]>
12-
*
13-
* @implements CollectionInterface<string, FieldDto>
1411
*/
15-
final class FieldCollection implements CollectionInterface
12+
final class FieldCollection implements \ArrayAccess, \Countable, \IteratorAggregate
1613
{
1714
/** @var array<string, FieldDto> */
1815
private array $fields;
1916

2017
/**
2118
* @param array<FieldInterface|string> $fields
2219
*/
23-
private function __construct(iterable $fields)
20+
public function __construct(iterable $fields)
2421
{
2522
$this->fields = $this->processFields($fields);
2623
}
@@ -37,6 +34,8 @@ public function __clone()
3734
}
3835

3936
/**
37+
* @deprecated since 4.28.2 and removed in 5.0.0, use FilterCollection::__construct() instead.
38+
*
4039
* @param array<FieldInterface|string> $fields
4140
*/
4241
public static function new(iterable $fields): self

src/Collection/FilterCollection.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,23 @@
22

33
namespace EasyCorp\Bundle\EasyAdminBundle\Collection;
44

5-
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Collection\CollectionInterface;
65
use EasyCorp\Bundle\EasyAdminBundle\Dto\FilterDto;
76

87
/**
98
* @author Javier Eguiluz <[email protected]>
10-
*
11-
* @implements CollectionInterface<string, FilterDto>
129
*/
13-
final class FilterCollection implements CollectionInterface
10+
final class FilterCollection implements \ArrayAccess, \Countable, \IteratorAggregate
1411
{
1512
/**
1613
* @param array<string, FilterDto> $filters
1714
*/
18-
private function __construct(private array $filters)
15+
public function __construct(private array $filters = [])
1916
{
2017
}
2118

2219
/**
20+
* @deprecated since 4.28.2 and removed in 5.0.0, use FilterCollection::__construct() instead.
21+
*
2322
* @param array<string, FilterDto> $filters
2423
*/
2524
public static function new(array $filters = []): self

0 commit comments

Comments
 (0)