You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This bundle is shipped with a bridge for the [FOSUserBundle](https://github.com/FriendsOfSymfony/FOSUserBundle). If the FOSUserBundle is enabled, this bridges registers to the persist, update and delete events to pass user objects to the UserManager, before redispatching the event.
3
+
API Platform Core is shipped with a bridge for [FOSUserBundle](https://github.com/FriendsOfSymfony/FOSUserBundle). If the
4
+
FOSUser bundle is enabled, this bridge will use its `UserManager` to create, update and delete user resources.
4
5
5
6
## Creating a `User` entity with serialization groups
6
7
7
-
Here's an example of declaration of a [doctrine ORM User class](https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.rst#a-doctrine-orm-user-class). As shown you can use serialization groups to hide properties like `plainPassword` (only in read) and `password`. The properties shown are handled with the [`normalizationContext`](serialization-groups-and-relations.md#normalization), while the properties you can modify are handled with [`denormalizationContext`](serialization-groups-and-relations.md#denormalization).
8
+
Here's an example of declaration of a [Doctrine ORM User class](https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.rst#a-doctrine-orm-user-class).
9
+
You need to use serialization groups to hide some properties like `plainPassword` (only in read) and `password`. The properties
10
+
shown are handled with the [`normalization_context`](serialization-groups-and-relations.md#normalization), while the properties
11
+
you can modify are handled with [`denormalization_context`](serialization-groups-and-relations.md#denormalization).
8
12
9
13
First register the following service:
10
14
11
-
```yaml
12
-
# app/config/services.yml
13
-
14
-
resource.user:
15
-
parent: "api.resource"
16
-
arguments: [ "AppBundle\Entity\User" ]
17
-
calls:
18
-
- method: "initNormalizationContext"
19
-
arguments: [ { groups: [ "user_read" ] } ]
20
-
- method: "initDenormalizationContext"
21
-
arguments: [ { groups: [ "user_write" ] } ]
22
-
tags: [ { name: "api.resource" } ]
23
-
```
24
-
25
-
Then create your User entity with serialization groups:
26
-
27
15
```php
28
-
<?php
16
+
// src/AppBundle/Entity/User.php
29
17
30
18
namespace AppBundle\Entity;
31
19
20
+
use ApiPlatform\Core\Annotation\ApiResource;
32
21
use Doctrine\ORM\Mapping as ORM;
33
-
use FOS\UserBundle\Entity\User as BaseUser;
22
+
use FOS\UserBundle\Model\User as BaseUser;
23
+
use FOS\UserBundle\Model\UserInterface;
34
24
use Symfony\Component\Serializer\Annotation\Groups;
35
-
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
0 commit comments