File tree Expand file tree Collapse file tree
assets/css/easyadmin-theme
TestApplication/src/Controller Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -575,7 +575,7 @@ a.user-menu-wrapper .user-details:hover {
575575}
576576.content-header .page-actions : empty { display : none; }
577577
578- .content-header .page-actions .btn + .btn {
578+ .content-header .page-actions : is ( .btn , form : has (. btn )) + : is ( .btn , form : has (. btn )) {
579579 margin-inline-start : 10px ;
580580}
581581
Original file line number Diff line number Diff line change @@ -158,6 +158,13 @@ public function displayAsButton(): self
158158 return $ this ;
159159 }
160160
161+ public function displayAsForm (): self
162+ {
163+ $ this ->dto ->setHtmlElement ('form ' );
164+
165+ return $ this ;
166+ }
167+
161168 public function setHtmlAttributes (array $ attributes ): self
162169 {
163170 $ this ->dto ->setHtmlAttributes ($ attributes );
Original file line number Diff line number Diff line change @@ -293,6 +293,8 @@ public function getAsConfigObject(): Action
293293
294294 if ('a ' === $ this ->htmlElement ) {
295295 $ action ->displayAsLink ();
296+ } elseif ('form ' === $ this ->htmlElement ) {
297+ $ action ->displayAsForm ();
296298 } else {
297299 $ action ->displayAsButton ();
298300 }
Original file line number Diff line number Diff line change 1515 {%- if action .label is not empty -%}<span class =" action-label" >{{ action .label | trans| raw }}</span >{%- endif -%}
1616 </span >
1717 </button >
18+ {% elseif ' form' == action .htmlElement %}
19+ {%- set form_id = ' form-' ~ action .name ~ ' -' ~ random () -%}
20+ {%- do action.setHtmlAttribute (' form' , form_id ) -%}
21+ <form action =" {{ action .linkUrl }}" method =" POST" id =" {{ form_id }}" >
22+ <button class =" {{ action .cssClass }}" {% for name , value in action .htmlAttributes %}{{ name }}=" {{ (value .trans is defined ? value | trans : value )| e (' html' ) }}" {% endfor %}>
23+ <span class =" btn-label" >
24+ {%- if action .icon %}<twig:ea:Icon name =" {{ action .icon }}" /> {% endif -%}
25+ {%- if action .label is not empty -%}<span class =" action-label" >{{ action .label | trans| raw }}</span >{%- endif -%}
26+ </span >
27+ </button >
28+ </form >
1829{% endif %}
Original file line number Diff line number Diff line change @@ -52,4 +52,13 @@ public function testDynamicLabels()
5252 static ::assertSame ('Action 7: Category 0 ' , $ crawler ->filter ('a.dropdown-item[data-action-name="action7"] ' )->text ());
5353 static ::assertSame ('Reset ' , $ crawler ->filter ('a.dropdown-item[data-action-name="action8"] ' )->text ());
5454 }
55+
56+ public function testFormAction ()
57+ {
58+ $ crawler = $ this ->client ->request ('GET ' , $ this ->generateIndexUrl ());
59+
60+ static ::assertCount (1 , $ crawler ->filter ('form[id^="form-action9-"] ' ));
61+ static ::assertCount (1 , $ crawler ->filter ('form[id^="form-action9-"] > .btn ' ));
62+ static ::assertSame ('POST ' , $ crawler ->filter ('form[id^="form-action9-"] ' )->attr ('method ' ));
63+ }
5564}
Original file line number Diff line number Diff line change @@ -43,6 +43,8 @@ public function configureActions(Actions $actions): Actions
4343 // this tests that the 'Reset' label is interpreted as a string and not as a callable to the PHP reset() function
4444 $ action8 = Action::new ('action8 ' )->linkToCrudAction ('' )->setLabel ('Reset ' );
4545
46+ $ action9 = Action::new ('action9 ' )->linkToCrudAction ('' )->createAsGlobalAction ()->displayAsForm ();
47+
4648 return $ actions
4749 ->add (Crud::PAGE_INDEX , $ action1 )
4850 ->add (Crud::PAGE_INDEX , $ action2 )
@@ -52,6 +54,7 @@ public function configureActions(Actions $actions): Actions
5254 ->add (Crud::PAGE_INDEX , $ action6 )
5355 ->add (Crud::PAGE_INDEX , $ action7 )
5456 ->add (Crud::PAGE_INDEX , $ action8 )
57+ ->add (Crud::PAGE_INDEX , $ action9 )
5558 ->update (Crud::PAGE_INDEX , Action::NEW , function (Action $ action ) {
5659 return $ action ->setIcon ('fa fa-fw fa-plus ' )->setLabel (false );
5760 })
You can’t perform that action at this time.
0 commit comments