@@ -21,20 +21,38 @@ bin/console cache:clear # To refresh grid's cache
2121
2222Magic! Here is the generated grid.
2323
24+ {% code title="src/Grid/BookGrid.php" lineNumbers="true" %}
2425``` php
25- final class BookGrid extends AbstractGrid implements ResourceAwareGridInterface
26+ <?php
27+
28+ namespace App\Grid;
29+
30+ use App\Entity\Book;
31+ use Sylius\Bundle\GridBundle\Builder\Action\CreateAction;
32+ use Sylius\Bundle\GridBundle\Builder\Action\DeleteAction;
33+ use Sylius\Bundle\GridBundle\Builder\Action\ShowAction;
34+ use Sylius\Bundle\GridBundle\Builder\Action\UpdateAction;
35+ use Sylius\Bundle\GridBundle\Builder\ActionGroup\BulkActionGroup;
36+ use Sylius\Bundle\GridBundle\Builder\ActionGroup\ItemActionGroup;
37+ use Sylius\Bundle\GridBundle\Builder\ActionGroup\MainActionGroup;
38+ use Sylius\Bundle\GridBundle\Builder\Field\DateTimeField;
39+ use Sylius\Bundle\GridBundle\Builder\Field\StringField;
40+ use Sylius\Bundle\GridBundle\Builder\GridBuilderInterface;
41+ use Sylius\Bundle\GridBundle\Grid\AbstractGrid;
42+ use Sylius\Component\Grid\Attribute\AsGrid;
43+
44+ #[AsGrid(
45+ name: 'app_book',
46+ resourceClass: Book::class,
47+ )]
48+ final class BookGrid extends AbstractGrid
2649{
2750 public function __construct()
2851 {
2952 // TODO inject services if required
3053 }
3154
32- public static function getName(): string
33- {
34- return 'app_book';
35- }
36-
37- public function buildGrid(GridBuilderInterface $gridBuilder): void
55+ public function __invoke(GridBuilderInterface $gridBuilder): void
3856 {
3957 $gridBuilder
4058 // see https://github.com/Sylius/SyliusGridBundle/blob/master/docs/field_types.md
@@ -67,15 +85,14 @@ final class BookGrid extends AbstractGrid implements ResourceAwareGridInterface
6785 )
6886 ;
6987 }
70-
71- public function getResourceClass(): string
72- {
73- return Book::class;
74- }
7588```
89+ {% endcode %}
7690
7791Configure the ` index ` operation in your resource.
7892
93+ {% tabs %}
94+ {% tab title="Sylius" %}
95+ {% code title="src/Entity/Book.php" lineNumbers="true" %}
7996``` php
8097namespace App\Entity;
8198
@@ -87,10 +104,10 @@ use Sylius\Resource\Model\ResourceInterface;
87104#[AsResource(
88105 section: 'admin', // This will influence the route name
89106 routePrefix: '/admin',
90- templatesDir: '@SyliusAdminUi /crud', // This directory contains the generic template for your list
107+ templatesDir: '@SyliusAdmin/shared /crud', // This directory contains the generic template for your list
91108 operations: [
92- new Index( // This operation will add "index" operation for the books list
93- grid: BookGrid::class, // Use the grid class you have generated in previous step
109+ new Index( // This operation will add an "index" operation for the books list
110+ grid: BookGrid::class, // Use the grid class you've just generated above
94111 ),
95112 ],
96113)]
@@ -99,10 +116,37 @@ class Book implements ResourceInterface
99116 //...
100117}
101118```
119+ {% endcode %}
120+ {% endtab %}
102121
103- {% hint style="info" %}
104- Note: When you are in a Sylius project, the ` templatesDir ` path is: ` @SyliusAdmin/shared/crud `
105- {% endhint %}
122+ {% tab title="Sylius Stack" %}
123+ {% code title="src/Entity/Book.php" lineNumbers="true" %}
124+ ``` php
125+ namespace App\Entity;
126+
127+ use App\Grid\BookGrid;
128+ use Sylius\Resource\Metadata\AsResource;
129+ use Sylius\Resource\Metadata\Index;
130+ use Sylius\Resource\Model\ResourceInterface;
131+
132+ #[AsResource(
133+ section: 'admin', // This will influence the route name
134+ routePrefix: '/admin',
135+ templatesDir: '@SyliusAdminUi/crud', // This directory contains the generic template for your list
136+ operations: [
137+ new Index( // This operation will add an "index" operation for the books list
138+ grid: BookGrid::class, // Use the grid class you've just generated above
139+ ),
140+ ],
141+ )]
142+ class Book implements ResourceInterface
143+ {
144+ //...
145+ }
146+ ```
147+ {% endcode %}
148+ {% endtab %}
149+ {% endtabs %}
106150
107151Use the Symfony ` debug:router ` command to check the results.
108152
@@ -131,33 +175,61 @@ bin/console make:form
131175
132176Configure the ` create ` operation in your resource.
133177
178+ {% tabs %}
179+ {% tab title="Sylius" %}
180+ {% code title="src/Entity/Book.php" lineNumbers="true" %}
134181``` php
135182namespace App\Entity;
136183
137- use App\Form\BookType ;
184+ use App\Grid\BookGrid ;
138185use Sylius\Resource\Metadata\AsResource;
139- use Sylius\Resource\Metadata\Create ;
186+ use Sylius\Resource\Metadata\Index ;
140187use Sylius\Resource\Model\ResourceInterface;
141188
142189#[AsResource(
143190 section: 'admin', // This will influence the route name
144191 routePrefix: '/admin',
145- templatesDir: '@SyliusAdminUi/crud', // This directory contains the generic templates
146- formType: BookType::class, // The form type you have generated in previous step
192+ templatesDir: '@SyliusAdmin/shared/crud', // This directory contains the generic template for your list
147193 operations: [
148- // ...
149- new Create(), // This operation will add "create" operation for the book resource
194+ // ...
195+ new Create(), // This operation will add "create" operation for the book resource
150196 ],
151197)]
152198class Book implements ResourceInterface
153199{
154200 //...
155201}
156202```
203+ {% endcode %}
204+ {% endtab %}
157205
158- {% hint style="info" %}
159- Note: When you are in a Sylius project, the ` templatesDir ` path is: ` @SyliusAdmin/shared/crud `
160- {% endhint %}
206+ {% tab title="Sylius Stack" %}
207+ {% code title="src/Entity/Book.php" lineNumbers="true" %}
208+ ``` php
209+ namespace App\Entity;
210+
211+ use App\Grid\BookGrid;
212+ use Sylius\Resource\Metadata\AsResource;
213+ use Sylius\Resource\Metadata\Index;
214+ use Sylius\Resource\Model\ResourceInterface;
215+
216+ #[AsResource(
217+ section: 'admin', // This will influence the route name
218+ routePrefix: '/admin',
219+ templatesDir: '@SyliusAdminUi/crud', // This directory contains the generic template for your list
220+ operations: [
221+ //...
222+ new Create(), // This operation will add a "create" operation for the book resource
223+ ],
224+ )]
225+ class Book implements ResourceInterface
226+ {
227+ //...
228+ }
229+ ```
230+ {% endcode %}
231+ {% endtab %}
232+ {% endtabs %}
161233
162234Use the Symfony ` debug:router ` command to check the results.
163235
@@ -182,33 +254,61 @@ Ensure you already created the Symfony form type in the [previous section](basic
182254
183255Configure the ` update ` operation in your resource.
184256
257+ {% tabs %}
258+ {% tab title="Sylius" %}
259+ {% code title="src/Entity/Book.php" lineNumbers="true" %}
185260``` php
186261namespace App\Entity;
187262
188- use App\Form\BookType ;
263+ use App\Grid\BookGrid ;
189264use Sylius\Resource\Metadata\AsResource;
190- use Sylius\Resource\Metadata\Update ;
265+ use Sylius\Resource\Metadata\Index ;
191266use Sylius\Resource\Model\ResourceInterface;
192267
193268#[AsResource(
194269 section: 'admin', // This will influence the route name
195270 routePrefix: '/admin',
196- templatesDir: '@SyliusAdminUi/crud', // This directory contains the generic templates
197- formType: BookType::class, // The form type you have generated in previous chapter
271+ templatesDir: '@SyliusAdmin/shared/crud', // This directory contains the generic template for your list
198272 operations: [
199- // ...
200- new Update(), // This operation will add "update" operation for the book resource
273+ // ...
274+ new Update(), // This operation will add "update" operation for the book resource
201275 ],
202276)]
203277class Book implements ResourceInterface
204278{
205279 //...
206280}
207281```
282+ {% endcode %}
283+ {% endtab %}
208284
209- {% hint style="info" %}
210- Note: When you are in a Sylius project, the ` templatesDir ` path is: ` @SyliusAdmin/shared/crud `
211- {% endhint %}
285+ {% tab title="Sylius Stack" %}
286+ {% code title="src/Entity/Book.php" lineNumbers="true" %}
287+ ``` php
288+ namespace App\Entity;
289+
290+ use App\Grid\BookGrid;
291+ use Sylius\Resource\Metadata\AsResource;
292+ use Sylius\Resource\Metadata\Index;
293+ use Sylius\Resource\Model\ResourceInterface;
294+
295+ #[AsResource(
296+ section: 'admin', // This will influence the route name
297+ routePrefix: '/admin',
298+ templatesDir: '@SyliusAdminUi/crud', // This directory contains the generic template for your list
299+ operations: [
300+ //...
301+ new Update(), // This operation will add "update" operation for the book resource
302+ ],
303+ )]
304+ class Book implements ResourceInterface
305+ {
306+ //...
307+ }
308+ ```
309+ {% endcode %}
310+ {% endtab %}
311+ {% endtabs %}
212312
213313Use the Symfony ` debug:router ` command to check the results.
214314
@@ -231,32 +331,61 @@ Your route should look like this:
231331
232332Configure the ` show ` operation in your resource.
233333
334+ {% tabs %}
335+ {% tab title="Sylius" %}
336+ {% code title="src/Entity/Book.php" lineNumbers="true" %}
234337``` php
235338namespace App\Entity;
236339
237- use App\Form\BookType ;
340+ use App\Grid\BookGrid ;
238341use Sylius\Resource\Metadata\AsResource;
239- use Sylius\Resource\Metadata\Show ;
342+ use Sylius\Resource\Metadata\Index ;
240343use Sylius\Resource\Model\ResourceInterface;
241344
242345#[AsResource(
243346 section: 'admin', // This will influence the route name
244347 routePrefix: '/admin',
245- templatesDir: '@SyliusAdminUi/ crud', // This directory contains the generic templates
348+ templatesDir: '@SyliusAdmin/shared/ crud', // This directory contains the generic template for your list
246349 operations: [
247- // ...
248- new Show(), // This operation will add "show" operation for the book resource
350+ // ...
351+ new Show(), // This operation will add "show" operation for the book resource
249352 ],
250353)]
251354class Book implements ResourceInterface
252355{
253356 //...
254357}
255358```
359+ {% endcode %}
360+ {% endtab %}
256361
257- {% hint style="info" %}
258- Note: When you are in a Sylius project, the ` templatesDir ` path is: ` @SyliusAdmin/shared/crud `
259- {% endhint %}
362+ {% tab title="Sylius Stack" %}
363+ {% code title="src/Entity/Book.php" lineNumbers="true" %}
364+ ``` php
365+ namespace App\Entity;
366+
367+ use App\Grid\BookGrid;
368+ use Sylius\Resource\Metadata\AsResource;
369+ use Sylius\Resource\Metadata\Index;
370+ use Sylius\Resource\Model\ResourceInterface;
371+
372+ #[AsResource(
373+ section: 'admin', // This will influence the route name
374+ routePrefix: '/admin',
375+ templatesDir: '@SyliusAdminUi/crud', // This directory contains the generic template for your list
376+ operations: [
377+ //...
378+ new Update(), // This operation will add an "update" operation for the book resource
379+ ],
380+ )]
381+ class Book implements ResourceInterface
382+ {
383+ //...
384+ }
385+ ```
386+ {% endcode %}
387+ {% endtab %}
388+ {% endtabs %}
260389
261390Use the Symfony ` debug:router ` command to check the results.
262391
@@ -277,26 +406,24 @@ Now we need to configure the templates.
277406
278407{% tabs %}
279408{% tab title="YAML" %}
280- {% code lineNumbers="true" %}
409+ {% code title="config/packages/sylius_bootstrap_admin_ui.yaml" lineNumbers="true" %}
281410``` yaml
282- # config/packages/sylius_bootstrap_admin_ui.yaml
283- # ...
284411sylius_twig_hooks :
285412 hooks :
286413 # ...
287414 # This will create the body block
288415 ' sylius_admin.book.show.content ' :
289416 body :
290417 template : ' book/show/content/body.html.twig'
291-
292418` ` `
293419{% endcode %}
294420{% endtab %}
295421
296422{% tab title="PHP" %}
297- {% code lineNumbers="true" %}
423+ {% code title="config/packages/sylius_bootstrap_admin_ui.php" lineNumbers="true" %}
298424` ` ` php
299- // config/packages/sylius_bootstrap_admin_ui.php
425+ <?php
426+
300427declare(strict_types=1);
301428
302429namespace Symfony\Component\DependencyInjection\Loader\Configurator;
@@ -319,12 +446,11 @@ return static function (ContainerConfigurator $container): void {
319446{% endtab %}
320447{% endtabs %}
321448
449+ {% code title="templates/book/show/content/body.html.twig" lineNumbers="true" %}
322450``` twig
323451{% raw %}
324- {# templates/book/show/content/body.html.twig #}
325-
326452{% set book = hookable_metadata.context.book %}
327-
453+ {% endraw %}
328454<div class="page-body">
329455 <div class="container-xl">
330456 <div class="row">
@@ -336,8 +462,8 @@ return static function (ContainerConfigurator $container): void {
336462 </div>
337463 </div>
338464</div>
339- {% endraw %}
340465```
466+ {% endcode %}
341467
342468{% hint style="info" %}
343469Note that you can also [ replace the default title] ( page_titles.md ) .
0 commit comments