File tree Expand file tree Collapse file tree 5 files changed +95
-2
lines changed
Expand file tree Collapse file tree 5 files changed +95
-2
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of the Sylius package.
5+ *
6+ * (c) Sylius Sp. z o.o.
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ declare (strict_types=1 );
13+
14+ namespace Sylius \Bundle \GridBundle \Builder \Action ;
15+
16+ final class TwigAction
17+ {
18+ public static function create (
19+ string $ name ,
20+ string $ template ,
21+ array $ options = [],
22+ ): ActionInterface {
23+ $ action = Action::create ($ name , $ name );
24+
25+ $ options = array_merge ($ options , ['template ' => $ template ]);
26+ $ action ->setOptions ($ options );
27+
28+ return $ action ;
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of the Sylius package.
5+ *
6+ * (c) Sylius Sp. z o.o.
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ declare (strict_types=1 );
13+
14+ namespace spec \Sylius \Bundle \GridBundle \Builder \Action ;
15+
16+ use PhpSpec \ObjectBehavior ;
17+ use Sylius \Bundle \GridBundle \Builder \Action \ActionInterface ;
18+ use Sylius \Bundle \GridBundle \Builder \Action \TwigAction ;
19+
20+ final class TwigActionSpec extends ObjectBehavior
21+ {
22+ function it_is_initializable (): void
23+ {
24+ $ this ->shouldHaveType (TwigAction::class);
25+ }
26+
27+ function it_builds_create_actions (): void
28+ {
29+ $ action = $ this ::create (name: 'dummy ' , template: 'path/to/dummy/template ' );
30+
31+ $ action ->shouldHaveType (ActionInterface::class);
32+ $ action ->toArray ()->shouldReturn ([
33+ 'type ' => 'dummy ' ,
34+ 'options ' => [
35+ 'template ' => 'path/to/dummy/template ' ,
36+ ],
37+ ]);
38+ }
39+
40+ function it_builds_create_action_with_options (): void
41+ {
42+ $ action = $ this ::create (name: 'dummy ' , template: 'path/to/dummy/template ' , options: ['custom ' => true ]);
43+
44+ $ action ->shouldHaveType (ActionInterface::class);
45+ $ action ->toArray ()->shouldReturn ([
46+ 'type ' => 'dummy ' ,
47+ 'options ' => [
48+ 'custom ' => true ,
49+ 'template ' => 'path/to/dummy/template ' ,
50+ ],
51+ ]);
52+ }
53+ }
Original file line number Diff line number Diff line change @@ -58,7 +58,9 @@ sylius_grid:
5858 actions :
5959 item :
6060 show :
61- type : show
61+ type : custom_show
62+ options :
63+ template : ' grid/action/show.html.twig'
6264 limits : [10, 5, 15]
6365
6466 app_author :
Original file line number Diff line number Diff line change 1515use App \Entity \Book ;
1616use App \Grid \Builder \AttributeNationalityFilter ;
1717use App \Grid \Builder \NationalityFilter ;
18+ use Sylius \Bundle \GridBundle \Builder \Action \TwigAction ;
19+ use Sylius \Bundle \GridBundle \Builder \ActionGroup \ItemActionGroup ;
1820use Sylius \Bundle \GridBundle \Builder \Field \CallableField ;
1921use Sylius \Bundle \GridBundle \Builder \Field \StringField ;
2022use Sylius \Bundle \GridBundle \Builder \Filter \EntityFilter ;
7779 ->setSortable (true , 'price.currencyCode ' )
7880 ->setOption ('vars ' , ['th_class ' => 'text-end ' ]),
7981 )
82+ ->addActionGroup (
83+ ItemActionGroup::create (
84+ TwigAction::create ('custom_show ' , 'grid/action/show.html.twig ' ),
85+ ),
86+ )
8087 ->setLimits ([10 , 5 , 15 ]),
8188 );
8289};
Original file line number Diff line number Diff line change 1919use Sylius \Bundle \GridBundle \Builder \Action \CreateAction ;
2020use Sylius \Bundle \GridBundle \Builder \Action \DeleteAction ;
2121use Sylius \Bundle \GridBundle \Builder \Action \ShowAction ;
22+ use Sylius \Bundle \GridBundle \Builder \Action \TwigAction ;
2223use Sylius \Bundle \GridBundle \Builder \Action \UpdateAction ;
2324use Sylius \Bundle \GridBundle \Builder \ActionGroup \ItemActionGroup ;
2425use Sylius \Bundle \GridBundle \Builder \ActionGroup \MainActionGroup ;
@@ -98,7 +99,7 @@ public function buildGrid(GridBuilderInterface $gridBuilder): void
9899 )
99100 ->addActionGroup (
100101 ItemActionGroup::create (
101- ShowAction ::create ([
102+ TwigAction ::create (name: ' custom_show ' , template: ' grid/action/show.html.twig ' , options: [
102103 'link ' => [
103104 'route ' => 'app_book_show ' ,
104105 ],
You can’t perform that action at this time.
0 commit comments