Skip to content

Commit 8b487df

Browse files
committed
Merge branch '2.2'
2 parents 3e0414b + 31607f3 commit 8b487df

16 files changed

+404
-61
lines changed

admin/authentication-support.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ process is similar for other authentication mechanisms. The `login_uri` is the f
77
The first step is to create a client to handle the authentication process:
88

99
```javascript
10-
// src/authClient.js
11-
import { AUTH_LOGIN, AUTH_LOGOUT, AUTH_ERROR, AUTH_CHECK } from 'admin-on-rest';
10+
// src/authProvider.js
11+
import { AUTH_LOGIN, AUTH_LOGOUT, AUTH_ERROR, AUTH_CHECK } from 'react-admin';
1212

1313
// Change this to be your own login check route.
1414
const login_uri = 'https://demo.api-platform.com/login_check';
@@ -61,7 +61,7 @@ Then, configure the `Admin` component to use the authentication client we just c
6161
import React from 'react';
6262
import parseHydraDocumentation from '@api-platform/api-doc-parser/lib/hydra/parseHydraDocumentation';
6363
import { HydraAdmin, hydraClient, fetchHydra as baseFetchHydra } from '@api-platform/admin';
64-
import authClient from './authClient';
64+
import authProvider from './authProvider';
6565
import { Redirect } from 'react-router-dom';
6666

6767
const entrypoint = 'https://demo.api-platform.com'; // Change this by your own entrypoint
@@ -70,7 +70,7 @@ const fetchHydra = (url, options = {}) => baseFetchHydra(url, {
7070
...options,
7171
headers: new Headers(fetchHeaders),
7272
});
73-
const restClient = api => hydraClient(api, fetchHydra);
73+
const hydraClient = api => hydraClient(api, fetchHydra);
7474
const apiDocumentationParser = entrypoint => parseHydraDocumentation(entrypoint, { headers: new Headers(fetchHeaders) })
7575
.then(
7676
({ api }) => ({ api }),
@@ -96,12 +96,12 @@ const apiDocumentationParser = entrypoint => parseHydraDocumentation(entrypoint,
9696
export default props => (
9797
<HydraAdmin
9898
apiDocumentationParser={apiDocumentationParser}
99-
authClient={authClient}
99+
authProvider={authProvider}
100100
entrypoint={entrypoint}
101-
restClient={restClient}
101+
dataProvider={hydraClient}
102102
/>
103103
);
104104
```
105105

106-
Refer to [the chapter dedicated to authentication in the Admin On Rest documentation](https://marmelab.com/admin-on-rest/Authentication.html)
106+
Refer to [the chapter dedicated to authentication in the React Admin documentation](https://marmelab.com/react-admin/Authentication.html)
107107
for more information.

admin/getting-started.md

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ the admin's domain to access it.
3535
To do so, update the value of the `CORS_ALLOW_ORIGIN` parameter in `api/.env` (it will be set to `^https?://localhost:?[0-9]*$`
3636
by default).
3737

38+
If you're not using the API Platform distribution, you will need to adjust the NelmioCorsBundle configuration to expose the `Link` HTTP header and to send proper CORS headers on the route under which the API will be served (`/api` by default).
39+
Here is a sample configuration (if you use the API Platform distribution, you can skip this step):
40+
41+
```yaml
42+
# config/packages/nelmio-cors.yaml
43+
44+
nelmio_cors:
45+
paths:
46+
'^/api/':
47+
origin_regex: true
48+
allow_origin: ['^http://localhost:[0-9]+'] # You probably want to change this regex to match your real domain
49+
allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
50+
allow_headers: ['Content-Type', 'Authorization']
51+
expose_headers: ['Link']
52+
max_age: 3600
53+
```
54+
3855
Clear the cache to apply this change:
3956
4057
$ docker-compose exec php bin/console cache:clear --env=prod
@@ -50,12 +67,12 @@ The API Platform's admin parses the Hydra documentation exposed by the API and t
5067
### Using Custom Components
5168

5269
In the following example, we change components used for the `description` property of the `books` resource to ones accepting HTML (respectively `RichTextField` that renders HTML markup and `RichTextInput`, a WYSWYG editor).
53-
(To use the `RichTextInput`, the `aor-rich-text-input` package is must be installed: `yarn add aor-rich-text-input`).
70+
(To use the `RichTextInput`, the `ra-input-rich-text` package is must be installed: `yarn add ra-input-rich-text`).
5471

5572
```javascript
5673
import React from 'react';
57-
import { RichTextField } from 'admin-on-rest';
58-
import RichTextInput from 'aor-rich-text-input';
74+
import { RichTextField } from 'react-admin';
75+
import RichTextInput from 'ra-input-rich-text';
5976
import { HydraAdmin } from '@api-platform/admin';
6077
import parseHydraDocumentation from '@api-platform/api-doc-parser/lib/hydra/parseHydraDocumentation';
6178
@@ -85,22 +102,21 @@ export default (props) => <HydraAdmin apiDocumentationParser={myApiDocumentation
85102
The `field` property of the `Field` class allows to set the component used to render a property in list and show screens.
86103
The `input` property allows to set the component to use to render the input used in create and edit screens.
87104

88-
Any [field](https://marmelab.com/admin-on-rest/Fields.html) or [input](https://marmelab.com/admin-on-rest/Inputs.html) provided by the Admin On Rest library can be used.
105+
Any [field](https://marmelab.com/react-admin/Fields.html) or [input](https://marmelab.com/react-admin/Inputs.html) provided by the React Admin library can be used.
89106

90-
To go further, take a look to the "[Including admin-on-rest on another React app](https://marmelab.com/admin-on-rest/CustomApp.html)" documentation page of Admin On Rest to learn how to use directly redux, react-router, and redux-saga along with components provided by this library.
107+
To go further, take a look to the "[Including react-admin on another React app](https://marmelab.com/react-admin/CustomApp.html)" documentation page of React Admin to learn how to use directly redux, react-router, and redux-saga along with components provided by this library.
91108

92109
### Managing Files and Images
93110

94111
In the following example, we will:
95-
* find every [ImageObject](http://schema.org/ImageObject) resources. For each [contentUrl](http://schema.org/contentUrl) fields, we will use [ImageField](https://marmelab.com/admin-on-rest/Fields.html#imagefield) as `field` and [ImageInput](https://marmelab.com/admin-on-rest/Inputs.html#imageinput) as `input`.
96-
* [ImageInput](https://marmelab.com/admin-on-rest/Inputs.html#imageinput) will return a [File](https://developer.mozilla.org/en/docs/Web/API/File) instance. In this example, we will send a multi-part form data to a special action (`https://demo.api-platform.com/images/upload`). The action will return the ID of the uploaded image. We will "replace" the [File](https://developer.mozilla.org/en/docs/Web/API/File) instance by the ID in `normalizeData`.
97-
* As `contentUrl` fields will return a string, we have to convert Hydra data to AOR data. This action will be done by `denormalizeData`.
112+
* find every [ImageObject](http://schema.org/ImageObject) resources. For each [contentUrl](http://schema.org/contentUrl) fields, we will use [ImageField](https://marmelab.com/react-admin/Fields.html#imagefield) as `field` and [ImageInput](https://marmelab.com/react-admin/Inputs.html#imageinput) as `input`.
113+
* [ImageInput](https://marmelab.com/react-admin/Inputs.html#imageinput) will return a [File](https://developer.mozilla.org/en/docs/Web/API/File) instance. In this example, we will send a multi-part form data to a special action (`https://demo.api-platform.com/images/upload`). The action will return the ID of the uploaded image. We will "replace" the [File](https://developer.mozilla.org/en/docs/Web/API/File) instance by the ID in `normalizeData`.
114+
* As `contentUrl` fields will return a string, we have to convert Hydra data to React Admin data. This action will be done by `denormalizeData`.
98115

99116
```javascript
100-
import { FunctionField, ImageField, ImageInput } from 'admin-on-rest/lib/mui';
101117
import React from 'react';
102-
import { RichTextField } from 'admin-on-rest';
103-
import RichTextInput from 'aor-rich-text-input';
118+
import { FunctionField, ImageField, ImageInput, RichTextField } from 'react-admin';
119+
import RichTextInput from 'ra-input-rich-text';
104120
import { HydraAdmin } from '@api-platform/admin';
105121
import parseHydraDocumentation from '@api-platform/api-doc-parser/lib/hydra/parseHydraDocumentation';
106122
@@ -208,7 +224,7 @@ export default class extends Component {
208224
render() {
209225
if (null === this.state.api) return <div>Loading...</div>;
210226

211-
return <AdminBuilder api={this.state.api} restClient={hydraClient(entrypoint)}/>
227+
return <AdminBuilder api={this.state.api} dataProvider={hydraClient(entrypoint)}/>
212228
}
213229
}
214230
```

admin/handling-relations-to-collections.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Let's customize the components used for the `authors` property:
7878

7979
```javascript
8080
import React, { Component } from 'react';
81-
import { ReferenceArrayField, SingleFieldList, ChipField, ReferenceArrayInput, SelectArrayInput } from 'admin-on-rest';
81+
import { ReferenceArrayField, SingleFieldList, ChipField, ReferenceArrayInput, SelectArrayInput } from 'react-admin';
8282
import { AdminBuilder, hydraClient } from '@api-platform/admin';
8383
import parseHydraDocumentation from 'api-doc-parser/lib/hydra/parseHydraDocumentation';
8484

@@ -115,7 +115,7 @@ export default class extends Component {
115115
render() {
116116
if (null === this.state.api) return <div>Loading...</div>;
117117

118-
return <AdminBuilder api={this.state.api} restClient={hydraClient({entrypoint: entrypoint, resources: this.state.resources})}/>
118+
return <AdminBuilder api={this.state.api} dataProvider={hydraClient({entrypoint: entrypoint, resources: this.state.resources})}/>
119119
}
120120
}
121121
```

admin/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ using [the API Platform framework](https://api-platform.com).
77
The generated administration is a 100% standalone Single-Page-Application with no coupling to the server part, according
88
to the API-first paradigm.
99

10-
API Platform Admin parses the Hydra documentation then uses the awesome [Admin On Rest](https://marmelab.com/admin-on-rest/)
10+
API Platform Admin parses the Hydra documentation then uses the awesome [React Admin](https://marmelab.com/react-admin/)
1111
library (and [React](https://facebook.github.io/react/)) to expose a nice, responsive, management interface (Create-Retrieve-Update-Delete)
1212
for all available resources.
1313

14-
You can also customize all screens by using Admin On Rest components and even raw JavaScript/React code.
14+
You can also customize all screens by using React Admin components and even raw JavaScript/React code.
1515

1616
## Features
1717

core/content-negotiation.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ It leverages the [`willdurand/negotiation`](https://github.com/willdurand/Negoti
55

66
By default, only the [JSON-LD](https://json-ld.org) format is enabled. However API Platform Core supports many more formats and can be extended.
77

8-
The framework natively supports JSON-LD, HAL, raw JSON, XML, YAML and CSV (YAML and CSV support is only available if you use Symfony 3.2+).
8+
The framework natively supports JSON-LD, GraphQL, JSONAPI, HAL, raw JSON, XML, YAML and CSV (YAML and CSV support is only available if you use Symfony 3.2+).
99

1010
Both XML and JSON formats are experimental and there are no assurance that we will not break them.
1111

@@ -19,16 +19,19 @@ Available formats are:
1919
Format | Format name | MIME types | Backward Compatibility guaranteed
2020
----------------------------------------------------------------|--------------|-------------------------------|----------------------------------------
2121
[JSON-LD](https://json-ld.org) | `jsonld` | `application/ld+json` | yes
22+
[GraphQL](graphql.md) | n/a | n/a | yes
23+
[JSONAPI](http://jsonapi.org/) | `jsonapi` | `application/vnd.api+json` | yes
2224
[HAL](http://stateless.co/hal_specification.html) | `jsonhal` | `application/hal+json` | yes
23-
JSON | `json` | `application/json` | no
24-
XML | `xml` | `application/xml`, `text/xml` | no
25-
HTML (API docs) | `html` | `text/html` | no
25+
[JSON](https://www.json.org/) | `json` | `application/json` | no
26+
[XML](https://www.w3.org/XML/) | `xml` | `application/xml`, `text/xml` | no
27+
[YAML](http://yaml.org/) | `yaml` | `application/x-yaml` | no
28+
[CSV](https://tools.ietf.org/html/rfc4180) | `csv` | `text/csv` | no
29+
[HTML](https://whatwg.org/) (API docs) | `html` | `text/html` | no
2630

27-
If the client requested format is not specified (if it's not supported, it will throw an HTTP bad format error), the response format will be the first format defined in the `formats` configuration key (see below).
31+
If the client requested format is not specified (if it's not supported, it will throw an HTTP bad request error), the response format will be the first format defined in the `formats` configuration key (see below).
2832
An example using the built-in XML support is available in [Behat specs](https://github.com/api-platform/core/blob/master/features/main/content_negotiation.feature).
2933

30-
The API Platform content negotiation system is extendable. Support for other formats (such as [JSONAPI](http://jsonapi.org/))
31-
can be added by [creating and registering appropriate encoders and, sometimes, normalizers](https://symfony.com/doc/current/serializer.html#adding-normalizers-and-encoders). Adding support for other
34+
The API Platform content negotiation system is extendable. Support for other formats can be added by [creating and registering appropriate encoders and, sometimes, normalizers](https://symfony.com/doc/current/serializer.html#adding-normalizers-and-encoders). Adding support for other
3235
standard hypermedia formats upstream is welcome. Don't hesitate to contribute by adding your encoders and normalizers
3336
to API Platform Core.
3437

@@ -45,12 +48,17 @@ api_platform:
4548
formats:
4649
jsonld: ['application/ld+json']
4750
jsonhal: ['application/hal+json']
51+
jsonapi: ['application/vnd.api+json']
4852
json: ['application/json']
4953
xml: ['application/xml', 'text/xml']
54+
yaml: ['application/x-yaml']
55+
csv: ['text/csv']
5056
html: ['text/html']
5157
myformat: ['application/vnd.myformat']
5258
```
5359
60+
To enable GraphQL support, [read the dedicated chapter](graphql.md).
61+
5462
Because the Symfony Serializer component is able to serialize objects in XML, sending an `Accept` HTTP header with the
5563
`text/xml` string as value is enough to retrieve XML documents from our API. However API Platform knows nothing about the
5664
`myformat` format. We need to register an encoder and optionally a normalizer for this format.

core/events.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Name | Event | Pre & Post hooks
8080
`DeserializeListener` | `kernel.request` | `PRE_DESERIALIZE`, `POST_DESERIALIZE`| 2 | deserialize data into a PHP entity (`GET`, `POST`, `DELETE`); update the entity retrieved using the data provider (`PUT`)
8181
`ValidateListener` | `kernel.view` | `PRE_VALIDATE`, `POST_VALIDATE` | 64 | [validate data](validation.md) (`POST`, `PUT`)
8282
`WriteListener` | `kernel.view` | `PRE_WRITE`, `POST_WRITE` | 32 | if using the Doctrine ORM, persist data (`POST`, `PUT`, `DELETE`)
83-
`SerializeListener` | `kernel.view` | None | 16 | serialize the PHP entity in string [according to the request format](content-negotiation.md)
83+
`SerializeListener` | `kernel.view` | `PRE_SERIALIZE`, `POST_SERIALIZE` | 16 | serialize the PHP entity in string [according to the request format](content-negotiation.md)
8484
`RespondListener` | `kernel.view` | `PRE_RESPOND`, `POST_RESPOND` | 8 | transform serialized to a `Symfony\Component\HttpFoundation\Response` instance
8585
`AddLinkHeaderListener` | `kernel.response` | None | 0 | add a `Link` HTTP header pointing to the Hydra documentation
8686
`ValidationExceptionListener` | `kernel.exception` | None | 0 | serialize validation exceptions in the Hydra format
@@ -101,6 +101,8 @@ Constant | Event | Priority |
101101
`POST_VALIDATE` | `kernel.view` | 63 |
102102
`PRE_WRITE` | `kernel.view` | 33 |
103103
`POST_WRITE` | `kernel.view` | 31 |
104+
`PRE_SERIALIZE` | `kernel.request` | 17 |
105+
`POST_SERIALIZE` | `kernel.request` | 15 |
104106
`PRE_RESPOND` | `kernel.view` | 9 |
105107
`POST_RESPOND` | `kernel.response` | 0 |
106108

0 commit comments

Comments
 (0)