Skip to content

Commit a0dd799

Browse files
committed
Merge branch '2.3'
2 parents 37f5405 + 1fb40ed commit a0dd799

15 files changed

+233
-150
lines changed

admin/getting-started.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ const myApiDocumentationParser = entrypoint => parseHydraDocumentation(entrypoin
8383
const books = api.resources.find(({ name }) => 'books' === name);
8484
const description = books.fields.find(f => 'description' === f.name);
8585
86+
description.field = props => (
87+
<RichTextField {...props} source="description" />
88+
);
89+
8690
description.input = props => (
8791
<RichTextInput {...props} source="description" />
8892
);

admin/handling-relations-to-collections.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,50 @@ export default class extends Component {
120120
}
121121
```
122122

123+
124+
## Customizing an Icon
125+
126+
Now that our `authors` property is displaying the name instead of an 'id', let's change the icon shown in the list menu.
127+
128+
Just add an import statement from `@material-ui` for adding the icon, in this case, a user icon:
129+
130+
`import UserIcon from '@material-ui/icons/People';`
131+
132+
and add it to the `authors.icon` property
133+
134+
The code for just customizing the icon will be:
135+
136+
```javascript
137+
import React, { Component } from 'react';
138+
import { AdminBuilder, hydraClient } from '@api-platform/admin';
139+
import parseHydraDocumentation from '@api-platform/api-doc-parser/lib/hydra/parseHydraDocumentation';
140+
import UserIcon from '@material-ui/icons/People';
141+
142+
const entrypoint = 'https://demo.api-platform.com';
143+
144+
export default class extends Component {
145+
state = { api: null }
146+
147+
componentDidMount() {
148+
parseHydraDocumentation(entrypoint).then(({api}) => {
149+
const authors = books.fields.find(({ name }) => 'authors' === name)
150+
151+
// Set the icon
152+
authors.icon = UserIcon
153+
154+
this.setState({ api });
155+
}
156+
)
157+
}
158+
159+
render() {
160+
if (null === this.state.api) return <div>Loading...</div>;
161+
162+
return <AdminBuilder api={ this.state.api } dataProvider={ hydraClient(this.state.api) }/>
163+
}
164+
}
165+
```
166+
123167
## Using an Autocomplete Input for Relations
124168

125169
We'll make one last improvement to our admin: transforming the relation selector we just created to use autocompletion.

core/data-providers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ final class BlogPostItemDataProvider implements ItemDataProviderInterface, Restr
101101
return BlogPost::class === $resourceClass;
102102
}
103103
104-
public function getItem(string $resourceClass, $identifiers, string $operationName = null, array $context = []): ?BlogPost
104+
public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []): ?BlogPost
105105
{
106106
// Retrieve the blog post item from somewhere then return it or null if not found
107-
return new BlogPost($identifiers['id']);
107+
return new BlogPost($id);
108108
}
109109
}
110110
```

core/events.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,5 @@ attribute of an operation](operations.md#recommended-method)):
112112
Attribute | Type | Default | Description |
113113
---------------|--------|---------|--------------------------------------------------------------------------------------|
114114
`_api_receive` | `bool` | `true` | Enables or disables the `ReadListener`, `DeserializeListener` and `ValidateListener` |
115-
`_api_respond` | `bool` | `true` | Enables or disables `SerializeListener` |
116-
`_api_persist` | `bool` | `true` | Enables or disables `WriteLister` |
115+
`_api_respond` | `bool` | `true` | Enables or disables `SerializeListener`, `RespondListener` |
116+
`_api_persist` | `bool` | `true` | Enables or disables `WriteListener` |

core/external-vocabularies.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The generated JSON for products and the related context document will now use ex
3737
{
3838
"@context": "/contexts/Book",
3939
"@id": "/books/22",
40-
"@type": "https://schema.org/Product",
40+
"@type": "https://schema.org/Book",
4141
"name": "My awesome book"
4242
}
4343
```

core/filters.md

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
154154
155155
/**
156156
* @ApiResource()
157-
* @ApiFilter(SearchFilter::class, properties={"id": "exact", "price": "exact", "name": "partial"})
157+
* @ApiFilter(SearchFilter::class, properties={"id": "exact", "price": "exact", "description": "partial"})
158158
*/
159159
class Offer
160160
{
@@ -163,10 +163,9 @@ class Offer
163163
```
164164

165165
`http://localhost:8000/api/offers?price=10` will return all offers with a price being exactly `10`.
166-
`http://localhost:8000/api/offers?name=shirt` will return all offers with a description containing the word "shirt".
167-
`http://localhost:8000/api/offers?name[]=shirt&name[]=sweat` will return all offers with a description containing the word "shirt" or containing the word "sweat".
166+
`http://localhost:8000/api/offers?description=shirt` will return all offers with a description containing the word "shirt".
168167

169-
Filters can be combined together: `http://localhost:8000/api/offers?price=10&name=shirt`
168+
Filters can be combined together: `http://localhost:8000/api/offers?price=10&description=shirt`
170169

171170
It is possible to filter on relations too, if `Offer` has a `Product` relation:
172171

@@ -241,6 +240,7 @@ Use the default behavior of the DBMS | `null`
241240
Exclude items | `ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter::EXCLUDE_NULL` (`exclude_null`)
242241
Consider items as oldest | `ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter::INCLUDE_NULL_BEFORE` (`include_null_before`)
243242
Consider items as youngest | `ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter::INCLUDE_NULL_AFTER` (`include_null_after`)
243+
Always include items | `ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter::INCLUDE_NULL_BEFORE_AND_AFTER` (`include_null_before_and_after`)
244244

245245
For instance, exclude entries with a property value of `null`, with the following service definition:
246246

@@ -292,7 +292,7 @@ class Offer
292292
}
293293
```
294294

295-
Given that the collection endpoint is `/offers`, you can filter offers by boolean with the following query: `/offers?isAvailableGenericallyInMyCountry=true`.
295+
Given that the collection endpoint is `/offers`, you can filter offers with the following query: `/offers?isAvailableGenericallyInMyCountry=true`.
296296

297297
It will return all offers where `isAvailableGenericallyInMyCountry` equals `true`.
298298

@@ -324,7 +324,7 @@ class Offer
324324
}
325325
```
326326

327-
Given that the collection endpoint is `/offers`, you can filter offers by boolean with the following query: `/offers?sold=1`.
327+
Given that the collection endpoint is `/offers`, you can filter offers with the following query: `/offers?sold=1`.
328328

329329
It will return all offers with `sold` equals `1`.
330330

@@ -1006,42 +1006,6 @@ final class UserFilterConfigurator
10061006

10071007
Done: Doctrine will automatically filter all "UserAware" entities!
10081008

1009-
### Overriding Extraction of Properties from the Request
1010-
1011-
You can change the way the filter parameters are extracted from the request. This can be done by overriding the `extractProperties(\Symfony\Component\HttpFoundation\Request $request)`
1012-
method.
1013-
1014-
In the following example, we will completely change the syntax of the order filter to be the following: `?filter[order][property]`
1015-
1016-
```php
1017-
<?php
1018-
// api/src/Filter/CustomOrderFilter.php
1019-
1020-
namespace App\Filter;
1021-
1022-
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
1023-
use Symfony\Component\HttpFoundation\Request;
1024-
1025-
final class CustomOrderFilter extends OrderFilter
1026-
{
1027-
protected function extractProperties(Request $request): array
1028-
{
1029-
return $request->query->get('filter[order]', []);
1030-
}
1031-
}
1032-
```
1033-
1034-
Finally, register the custom filter:
1035-
1036-
```yaml
1037-
# api/config/services.yaml
1038-
services:
1039-
# ...
1040-
'App\Filter\CustomOrderFilter': ~
1041-
# Uncomment only if autoconfiguration isn't enabled
1042-
#tags: [ 'api_platform.filter' ]
1043-
```
1044-
10451009
## ApiFilter Annotation
10461010

10471011
The annotation can be used on a `property` or on a `class`.

core/form-data.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ final class DeserializeListener
4040

4141
public function onKernelRequest(GetResponseEvent $event): void {
4242
$request = $event->getRequest();
43-
if ($request->isMethodSafe() || $request->isMethod(Request::METHOD_DELETE)) {
43+
if ($request->isMethodSafe(false) || $request->isMethod(Request::METHOD_DELETE)) {
4444
return;
4545
}
4646

@@ -84,4 +84,4 @@ services:
8484
decorates: 'api_platform.listener.request.deserialize'
8585
arguments:
8686
$decorated: '@App\EventListener\DeserializeListener.inner'
87-
```
87+
```

core/graphql.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ Once enabled, you have nothing to do: your schema describing your API is automat
1414

1515
To enable GraphQL and GraphiQL interface in your API, simply require the [graphql-php](https://webonyx.github.io/graphql-php/) package using Composer and clear the cache one more time:
1616

17-
$ composer require webonyx/graphql-php && bin/console cache:clear
17+
```bash
18+
docker-compose exec php composer req webonyx/graphql-php && bin/console cache:clear
19+
```
1820

19-
You can now use GraphQL at the endpoint: `http://localhost/graphql`.
21+
You can now use GraphQL at the endpoint: `https://localhost:8443/graphql`.
2022

2123
## GraphiQL
2224

0 commit comments

Comments
 (0)