Skip to content

Document easier custom operation definition #418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion core/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,9 @@ automatically instantiated and injected, without having to declare it explicitly
In the following example, the built-in `GET` operation is registered as well as a custom operation called `special`.
The `special` operation reference the Symfony route named `book_special`.

Since version 2.3, you can also use the route name as operation name by convention as shown in the next example
for `book_custom` if no `method` nor `route_name` attributes are specified.

```php
<?php
// src/Entity/Book.php
Expand All @@ -516,7 +519,8 @@ use ApiPlatform\Core\Annotation\ApiResource;
/**
* @ApiResource(itemOperations={
* "get",
* "special"={"route_name"="book_special"}
* "special"={"route_name"="book_special"},
* "book_custom",
* })
*/
class Book
Expand All @@ -534,6 +538,7 @@ App\Entity\Book:
get: ~
special:
route_name: 'book_special'
book_custom: ~
```

Or in XML:
Expand All @@ -552,6 +557,7 @@ Or in XML:
<itemOperation name="special">
<attribute name="route_name">book_special</attribute>
</itemOperation>
<itemOperation name="book_custom" />
</itemOperations>
</resource>
</resources>
Expand Down