From 21858fd80932296adc4445e6a77f5bfa07518b1f Mon Sep 17 00:00:00 2001 From: Yannick Date: Fri, 4 Apr 2025 10:01:16 +0200 Subject: [PATCH 1/4] feat : add form view of action in Dropdown (Twig component) --- assets/css/easyadmin-theme/actions.css | 10 ++++ assets/css/easyadmin-theme/theme.css | 1 + .../ActionMenu/ActionList/Item.html.twig | 14 +++++ templates/crud/index.html.twig | 4 +- .../Controller/ActionsCrudControllerTest.php | 5 ++ .../InlineActionsCrudControllerTest.php | 51 +++++++++++++++++++ .../src/Controller/ActionsCrudController.php | 4 ++ .../InlineActionsCrudController.php | 45 ++++++++++++++++ 8 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 assets/css/easyadmin-theme/actions.css create mode 100644 tests/Controller/InlineActionsCrudControllerTest.php create mode 100644 tests/TestApplication/src/Controller/InlineActionsCrudController.php diff --git a/assets/css/easyadmin-theme/actions.css b/assets/css/easyadmin-theme/actions.css new file mode 100644 index 0000000000..6f31108518 --- /dev/null +++ b/assets/css/easyadmin-theme/actions.css @@ -0,0 +1,10 @@ +.dropdown-actions { + .dropdown-menu { + + li > form > button.action-button { + all: unset; + cursor: pointer; + width: 100%; + } + } +} diff --git a/assets/css/easyadmin-theme/theme.css b/assets/css/easyadmin-theme/theme.css index 54aa9d70af..a72a1f80dc 100644 --- a/assets/css/easyadmin-theme/theme.css +++ b/assets/css/easyadmin-theme/theme.css @@ -14,3 +14,4 @@ @import "./autocomplete.css"; @import "./errors.css"; @import "./pages.css"; +@import "./actions.css"; diff --git a/templates/components/ActionMenu/ActionList/Item.html.twig b/templates/components/ActionMenu/ActionList/Item.html.twig index 8b7372e3a9..8464a0cbe8 100644 --- a/templates/components/ActionMenu/ActionList/Item.html.twig +++ b/templates/components/ActionMenu/ActionList/Item.html.twig @@ -4,11 +4,25 @@ icon = null, url = null, htmlAttributes = {}, + htmlElement = "a", + name = "" %}
  • + {% if htmlElement == "form" %} + {%- set form_id = 'form-' ~ name ~ '-' ~ random() -%} + + {% else %} {%- if icon %} {% endif -%} {%- if label is not empty -%}{{ renderLabelRaw ? label|raw : label }}{%- endif -%} + {% endif %}
  • diff --git a/templates/crud/index.html.twig b/templates/crud/index.html.twig index 1145367579..6c845eec31 100644 --- a/templates/crud/index.html.twig +++ b/templates/crud/index.html.twig @@ -172,7 +172,9 @@ class="{{ action.cssClass }}" url="{{ action.linkUrl }}" icon="{{ action.icon }}" icon:class="action-icon" htmlAttributes="{{ action.htmlAttributes }}" - label="{{ action.label|trans }}" label:class="action-label" renderLabelRaw /> + label="{{ action.label|trans }}" label:class="action-label" renderLabelRaw + htmlElement="{{ action.htmlElement }}" + name="{{ action.name }}"/> {% endfor %} diff --git a/tests/Controller/ActionsCrudControllerTest.php b/tests/Controller/ActionsCrudControllerTest.php index 7373db8880..a3e395d6ed 100644 --- a/tests/Controller/ActionsCrudControllerTest.php +++ b/tests/Controller/ActionsCrudControllerTest.php @@ -60,5 +60,10 @@ public function testFormAction() static::assertCount(1, $crawler->filter('form[id^="form-action9-"]')); static::assertCount(1, $crawler->filter('form[id^="form-action9-"] > .btn')); static::assertSame('POST', $crawler->filter('form[id^="form-action9-"]')->attr('method')); + + // use of 20 as there will be 1 on each of the line => by default 20 as defined in EasyAdminBundle\Config\Crud + static::assertCount(20, $crawler->filter('form[id^="form-action_form_entity-"]'), "There is no Action Entity form in the dropdown"); + static::assertCount(20, $crawler->filter('form[id^="form-action_form_entity-"] > button', "There is no Action Entity form button in the dropdown")); + static::assertSame('POST', $crawler->filter('form[id^="form-action_form_entity-"]')->attr('method'), "The method of the Action Entity form is not POST"); } } diff --git a/tests/Controller/InlineActionsCrudControllerTest.php b/tests/Controller/InlineActionsCrudControllerTest.php new file mode 100644 index 0000000000..0ecf56a5e4 --- /dev/null +++ b/tests/Controller/InlineActionsCrudControllerTest.php @@ -0,0 +1,51 @@ +client->followRedirects(); + $this->client->setServerParameters(['PHP_AUTH_USER' => 'admin', 'PHP_AUTH_PW' => '1234']); + + $this->categories = $this->entityManager->getRepository(Category::class); + } + + public function testCssClasses(): void + { + $crawler = $this->client->request('GET', $this->generateIndexUrl()); + + //TODO : see how to test the presence of the form into the inline actions + } + + public function testFormAction(): void + { + $crawler = $this->client->request('GET', $this->generateIndexUrl()); + + // use of 20 as there will be 1 on each of the line => by default 20 as defined in EasyAdminBundle\Config\Crud + $nbEntitiesPerPage = 20; + static::assertCount($nbEntitiesPerPage, $crawler->filter('form[id^="form-action_form_entity-"]')); + static::assertCount($nbEntitiesPerPage, $crawler->filter('form[id^="form-action_form_entity-"] > button')); + static::assertSame('POST', $crawler->filter('form[id^="form-action_form_entity-"]')->attr('method')); + } +} diff --git a/tests/TestApplication/src/Controller/ActionsCrudController.php b/tests/TestApplication/src/Controller/ActionsCrudController.php index 1c4d7d512d..7b172e29eb 100644 --- a/tests/TestApplication/src/Controller/ActionsCrudController.php +++ b/tests/TestApplication/src/Controller/ActionsCrudController.php @@ -45,6 +45,9 @@ public function configureActions(Actions $actions): Actions $action9 = Action::new('action9')->linkToCrudAction('')->createAsGlobalAction()->displayAsForm(); + // this tests the existence of the form action in an entity action + $actionFormEntity = Action::new('action_form_entity')->linkToCrudAction('')->displayAsForm(); + return $actions ->add(Crud::PAGE_INDEX, $action1) ->add(Crud::PAGE_INDEX, $action2) @@ -55,6 +58,7 @@ public function configureActions(Actions $actions): Actions ->add(Crud::PAGE_INDEX, $action7) ->add(Crud::PAGE_INDEX, $action8) ->add(Crud::PAGE_INDEX, $action9) + ->add(Crud::PAGE_INDEX, $actionFormEntity) ->update(Crud::PAGE_INDEX, Action::NEW, function (Action $action) { return $action->setIcon('fa fa-fw fa-plus')->setLabel(false); }) diff --git a/tests/TestApplication/src/Controller/InlineActionsCrudController.php b/tests/TestApplication/src/Controller/InlineActionsCrudController.php new file mode 100644 index 0000000000..d93649982b --- /dev/null +++ b/tests/TestApplication/src/Controller/InlineActionsCrudController.php @@ -0,0 +1,45 @@ +showEntityActionsInlined(true) + ; + } + + public function configureFields(string $pageName): iterable + { + return [ + TextField::new('name'), + ]; + } + + public function configureActions(Actions $actions): Actions + { + // this tests the existence of the form action in an entity action + $actionFormEntity = Action::new('action_form_entity')->linkToCrudAction('')->displayAsForm(); + + return $actions + ->add(Crud::PAGE_INDEX, $actionFormEntity) + ; + } +} From 114d353d6ce0bd3ff928583631944d18d22c948b Mon Sep 17 00:00:00 2001 From: Yannick Date: Fri, 4 Apr 2025 10:13:09 +0200 Subject: [PATCH 2/4] feat : add styling for inline action --- assets/css/easyadmin-theme/actions.css | 10 --------- assets/css/easyadmin-theme/datagrids.css | 27 ++++++++++++++++++++++-- assets/css/easyadmin-theme/theme.css | 1 - 3 files changed, 25 insertions(+), 13 deletions(-) delete mode 100644 assets/css/easyadmin-theme/actions.css diff --git a/assets/css/easyadmin-theme/actions.css b/assets/css/easyadmin-theme/actions.css deleted file mode 100644 index 6f31108518..0000000000 --- a/assets/css/easyadmin-theme/actions.css +++ /dev/null @@ -1,10 +0,0 @@ -.dropdown-actions { - .dropdown-menu { - - li > form > button.action-button { - all: unset; - cursor: pointer; - width: 100%; - } - } -} diff --git a/assets/css/easyadmin-theme/datagrids.css b/assets/css/easyadmin-theme/datagrids.css index 6dd3aff2ec..ef6bc3c02f 100644 --- a/assets/css/easyadmin-theme/datagrids.css +++ b/assets/css/easyadmin-theme/datagrids.css @@ -145,13 +145,29 @@ table.datagrid:not(.datagrid-empty) tr:not(.empty-row) td.actions.actions-as-dro .datagrid td.actions { text-align: right; } -.datagrid td.actions a:not(.dropdown-item) { +.datagrid td.actions a:not(.dropdown-item), +.datagrid td.actions form:not(.dropdown-item) { font-size: var(--font-size-sm); font-weight: 500; } -.datagrid td.actions a:not(.dropdown-item) + a:not(.dropdown-item) { + +.datagrid td.actions form:not(.dropdown-item) { + display: inline-block; + color: var(--link-color); +} + +.datagrid td.actions form:not(.dropdown-item) button { + all: unset; + cursor: pointer; + width: 100%; +} + +.datagrid td.actions a:not(.dropdown-item) + a:not(.dropdown-item), +.datagrid td.actions form:not(.dropdown-item) + a:not(.dropdown-item), +.datagrid td.actions a:not(.dropdown-item) + form:not(.dropdown-item) { margin-inline-start: 10px; } + .datagrid td.actions a:not(.dropdown-item) .action-icon { font-size: var(--font-size-base); margin-inline-end: 2px; @@ -205,6 +221,13 @@ table.datagrid:not(.datagrid-empty) tr:not(.empty-row) td.actions.actions-as-dro .datagrid .dropdown-actions .dropdown-menu { z-index: var(--zindex-900); } +.datagrid .dropdown-actions .dropdown-menu form button.action-button { + all: unset; + cursor: pointer; + width: 100%; +} + + .datagrid .ea-lightbox-thumbnail img { background: var(--white); border: 1px solid transparent; diff --git a/assets/css/easyadmin-theme/theme.css b/assets/css/easyadmin-theme/theme.css index a72a1f80dc..54aa9d70af 100644 --- a/assets/css/easyadmin-theme/theme.css +++ b/assets/css/easyadmin-theme/theme.css @@ -14,4 +14,3 @@ @import "./autocomplete.css"; @import "./errors.css"; @import "./pages.css"; -@import "./actions.css"; From fa83257ce32590cc60e2ea801feab07990d6f7aa Mon Sep 17 00:00:00 2001 From: Yannick Date: Fri, 4 Apr 2025 10:45:30 +0200 Subject: [PATCH 3/4] lint : fix linting issues --- tests/Controller/ActionsCrudControllerTest.php | 6 +++--- tests/Controller/InlineActionsCrudControllerTest.php | 2 +- .../src/Controller/InlineActionsCrudController.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Controller/ActionsCrudControllerTest.php b/tests/Controller/ActionsCrudControllerTest.php index a3e395d6ed..cfca8801aa 100644 --- a/tests/Controller/ActionsCrudControllerTest.php +++ b/tests/Controller/ActionsCrudControllerTest.php @@ -62,8 +62,8 @@ public function testFormAction() static::assertSame('POST', $crawler->filter('form[id^="form-action9-"]')->attr('method')); // use of 20 as there will be 1 on each of the line => by default 20 as defined in EasyAdminBundle\Config\Crud - static::assertCount(20, $crawler->filter('form[id^="form-action_form_entity-"]'), "There is no Action Entity form in the dropdown"); - static::assertCount(20, $crawler->filter('form[id^="form-action_form_entity-"] > button', "There is no Action Entity form button in the dropdown")); - static::assertSame('POST', $crawler->filter('form[id^="form-action_form_entity-"]')->attr('method'), "The method of the Action Entity form is not POST"); + static::assertCount(20, $crawler->filter('form[id^="form-action_form_entity-"]'), 'There is no Action Entity form in the dropdown'); + static::assertCount(20, $crawler->filter('form[id^="form-action_form_entity-"] > button', 'There is no Action Entity form button in the dropdown')); + static::assertSame('POST', $crawler->filter('form[id^="form-action_form_entity-"]')->attr('method'), 'The method of the Action Entity form is not POST'); } } diff --git a/tests/Controller/InlineActionsCrudControllerTest.php b/tests/Controller/InlineActionsCrudControllerTest.php index 0ecf56a5e4..43444c7073 100644 --- a/tests/Controller/InlineActionsCrudControllerTest.php +++ b/tests/Controller/InlineActionsCrudControllerTest.php @@ -35,7 +35,7 @@ public function testCssClasses(): void { $crawler = $this->client->request('GET', $this->generateIndexUrl()); - //TODO : see how to test the presence of the form into the inline actions + // TODO : see how to test the presence of the form into the inline actions } public function testFormAction(): void diff --git a/tests/TestApplication/src/Controller/InlineActionsCrudController.php b/tests/TestApplication/src/Controller/InlineActionsCrudController.php index d93649982b..252a61b0a9 100644 --- a/tests/TestApplication/src/Controller/InlineActionsCrudController.php +++ b/tests/TestApplication/src/Controller/InlineActionsCrudController.php @@ -24,7 +24,7 @@ public function configureCrud(Crud $crud): Crud return parent::configureCrud($crud) ->showEntityActionsInlined(true) ; - } + } public function configureFields(string $pageName): iterable { From a99ee3330cc05c09f276825468dbff7f6f633788 Mon Sep 17 00:00:00 2001 From: Yannick Date: Fri, 4 Apr 2025 11:59:47 +0200 Subject: [PATCH 4/4] feat : update aligning to #6833 --- templates/components/ActionMenu/ActionList/Item.html.twig | 6 +++--- templates/crud/index.html.twig | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/components/ActionMenu/ActionList/Item.html.twig b/templates/components/ActionMenu/ActionList/Item.html.twig index 8464a0cbe8..f10c002690 100644 --- a/templates/components/ActionMenu/ActionList/Item.html.twig +++ b/templates/components/ActionMenu/ActionList/Item.html.twig @@ -4,15 +4,15 @@ icon = null, url = null, htmlAttributes = {}, - htmlElement = "a", + type = "a", name = "" %}
  • - {% if htmlElement == "form" %} + {% if type == "form" %} {%- set form_id = 'form-' ~ name ~ '-' ~ random() -%}