1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the Silverback API Components Bundle Project |
||
5 | * |
||
6 | * (c) Daniel West <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | declare(strict_types=1); |
||
13 | |||
14 | namespace Silverback\ApiComponentsBundle\Entity\Utility; |
||
15 | |||
16 | use Doctrine\Common\Collections\ArrayCollection; |
||
17 | use Doctrine\Common\Collections\Collection; |
||
18 | use Doctrine\ORM\Mapping as ORM; |
||
19 | use Silverback\ApiComponentsBundle\Entity\Core\ComponentGroup; |
||
20 | use Symfony\Component\Serializer\Annotation\Groups; |
||
21 | |||
22 | /** |
||
23 | * @author Daniel West <[email protected]> |
||
24 | * |
||
25 | * @internal |
||
26 | */ |
||
27 | trait UiTrait |
||
28 | { |
||
29 | #[ORM\Column(nullable: true)] |
||
30 | public ?string $uiComponent = null; |
||
31 | |||
32 | #[ORM\Column(type: 'json', nullable: true)] |
||
33 | public ?array $uiClassNames = null; |
||
34 | |||
35 | /** |
||
36 | * @var Collection|ComponentGroup[] |
||
37 | */ |
||
38 | #[ORM\ManyToMany(targetEntity: ComponentGroup::class)] |
||
39 | #[Groups(['Route:manifest:read'])] |
||
40 | private Collection $componentGroups; |
||
41 | |||
42 | public function __construct() |
||
43 | { |
||
44 | $this->initComponentGroups(); |
||
45 | } |
||
46 | |||
47 | 9 | private function initComponentGroups(): void |
|
48 | { |
||
49 | 9 | $this->componentGroups = new ArrayCollection(); |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * @return Collection|ComponentGroup[] |
||
54 | */ |
||
55 | 1 | public function getComponentGroups() |
|
56 | { |
||
57 | 1 | return $this->componentGroups; |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * @return static |
||
62 | */ |
||
63 | public function setComponentGroups(iterable $componentGroups) |
||
64 | { |
||
65 | $this->componentGroups = new ArrayCollection(); |
||
66 | foreach ($componentGroups as $componentGroup) { |
||
67 | $this->addComponentGroup($componentGroup); |
||
68 | } |
||
69 | |||
70 | return $this; |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @return static |
||
75 | */ |
||
76 | public function addComponentGroup(ComponentGroup $componentGroup) |
||
77 | { |
||
78 | if (!$this->componentGroups->contains($componentGroup)) { |
||
79 | $this->componentGroups->add($componentGroup); |
||
80 | } |
||
81 | |||
82 | return $this; |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * @return static |
||
87 | */ |
||
88 | public function removeComponentGroup(ComponentGroup $componentGroup) |
||
89 | { |
||
90 | if ($this->componentGroups->contains($componentGroup)) { |
||
91 | $this->componentGroups->remove($componentGroup); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
92 | } |
||
93 | |||
94 | return $this; |
||
95 | } |
||
96 | } |
||
97 |