Repository navigation
Expand file tree
/
Copy pathForm.php
More file actions
92 lines (85 loc) · 2.92 KB
/
Copy pathForm.php
File metadata and controls
92 lines (85 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/*
* This file is part of the Silverback API Components Bundle Project
*
* (c) Daniel West <daniel@silverback.is>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silverback\ApiComponentsBundle\Entity\Component;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use Doctrine\ORM\Mapping as ORM;
use Silverback\ApiComponentsBundle\Annotation as Silverback;
use Silverback\ApiComponentsBundle\ApiPlatform\Metadata\Resource\ContentWriteSecurityResourceMetadataCollectionFactory;
use Silverback\ApiComponentsBundle\DataProvider\StateProvider\FormStateProvider;
use Silverback\ApiComponentsBundle\Entity\Core\AbstractComponent;
use Silverback\ApiComponentsBundle\Entity\Utility\TimestampedTrait;
use Silverback\ApiComponentsBundle\Model\Form\FormView;
use Silverback\ApiComponentsBundle\Validator\Constraints as AcbAssert;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Mapping\ClassMetadata;
/**
* @author Daniel West <daniel@silverback.is>
*/
#[Silverback\Timestamped]
#[ORM\Entity]
#[ApiResource(
provider: FormStateProvider::class,
operations: [
new GetCollection(),
new Post(),
new Get(),
new Delete(),
new Put(),
new Patch(),
new Patch(
name: '_api_/forms/{id}/submit{._format}_patch',
uriTemplate: '/forms/{id}/submit{._format}',
read: true,
deserialize: false,
validate: false,
write: false,
serialize: true,
requirements: ['id' => '[^/]+'],
extraProperties: [ContentWriteSecurityResourceMetadataCollectionFactory::OPT_OUT_EXTRA_PROPERTY => false],
),
new Post(
name: '_api_/forms/{id}/submit{._format}_post',
uriTemplate: '/forms/{id}/submit{._format}',
read: true,
deserialize: false,
validate: false,
write: false,
serialize: true,
requirements: ['id' => '[^/]+'],
extraProperties: [ContentWriteSecurityResourceMetadataCollectionFactory::OPT_OUT_EXTRA_PROPERTY => false],
),
]
)]
class Form extends AbstractComponent
{
use TimestampedTrait;
#[ORM\Column(nullable: false)]
#[Assert\Length(max: 255)]
public string $formType;
#[ApiProperty(writable: false)]
public ?FormView $formView = null;
public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraints(
'formType',
[
new Assert\NotBlank(),
new AcbAssert\FormTypeClass(),
]
);
}
}