Skip to content

Commit b91388f

Browse files
authored
Merge pull request #418 from antograssiot/custom_operation_configuratin
Document easier custom operation definition
2 parents 64d62d1 + 6ac3bfd commit b91388f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

core/operations.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,9 @@ automatically instantiated and injected, without having to declare it explicitly
507507
In the following example, the built-in `GET` operation is registered as well as a custom operation called `special`.
508508
The `special` operation reference the Symfony route named `book_special`.
509509

510+
Since version 2.3, you can also use the route name as operation name by convention as shown in the next example
511+
for `book_custom` if no `method` nor `route_name` attributes are specified.
512+
510513
```php
511514
<?php
512515
// src/Entity/Book.php
@@ -516,7 +519,8 @@ use ApiPlatform\Core\Annotation\ApiResource;
516519
/**
517520
* @ApiResource(itemOperations={
518521
* "get",
519-
* "special"={"route_name"="book_special"}
522+
* "special"={"route_name"="book_special"},
523+
* "book_custom",
520524
* })
521525
*/
522526
class Book
@@ -534,6 +538,7 @@ App\Entity\Book:
534538
get: ~
535539
special:
536540
route_name: 'book_special'
541+
book_custom: ~
537542
```
538543

539544
Or in XML:
@@ -552,6 +557,7 @@ Or in XML:
552557
<itemOperation name="special">
553558
<attribute name="route_name">book_special</attribute>
554559
</itemOperation>
560+
<itemOperation name="book_custom" />
555561
</itemOperations>
556562
</resource>
557563
</resources>

0 commit comments

Comments
 (0)