1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Silverback\ApiComponentBundle\Entity\Content\Dynamic; |
4
|
|
|
|
5
|
|
|
use ApiPlatform\Core\Annotation\ApiResource; |
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
7
|
|
|
use Doctrine\Common\Collections\Collection; |
8
|
|
|
use Doctrine\ORM\Mapping as ORM; |
9
|
|
|
use Silverback\ApiComponentBundle\Entity\Content\Component\Content\Content; |
10
|
|
|
use Silverback\ApiComponentBundle\Entity\Content\Component\Hero\Hero; |
11
|
|
|
use Silverback\ApiComponentBundle\Entity\Content\FileInterface; |
12
|
|
|
use Silverback\ApiComponentBundle\Entity\Content\FileTrait; |
13
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
14
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
15
|
|
|
use Symfony\Component\Validator\Mapping\ClassMetadata; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* |
19
|
|
|
* @author Daniel West <[email protected]> |
20
|
|
|
* @ApiResource() |
21
|
|
|
* @ORM\Entity() |
22
|
|
|
* @ORM\AttributeOverrides({ |
23
|
|
|
* @ORM\AttributeOverride( |
24
|
|
|
* name="filePath", |
25
|
|
|
* column=@ORM\Column( |
26
|
|
|
* nullable=true |
27
|
|
|
* ) |
28
|
|
|
* ) |
29
|
|
|
* }) |
30
|
|
|
*/ |
31
|
|
|
class ArticlePage extends AbstractDynamicPage implements FileInterface |
32
|
|
|
{ |
33
|
|
|
use FileTrait; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @ORM\Column(type="string") |
37
|
|
|
* @Groups({"content", "component"}) |
38
|
|
|
* @var null|string |
39
|
|
|
*/ |
40
|
|
|
private $subtitle; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @ORM\Column(type="text") |
44
|
|
|
* @Groups({"content", "component"}) |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
private $content; |
48
|
|
|
|
49
|
5 |
|
public static function loadValidatorMetadata(ClassMetadata $metadata): void |
50
|
|
|
{ |
51
|
5 |
|
$metadata->addPropertyConstraint( |
52
|
5 |
|
'filePath', |
53
|
5 |
|
new Assert\Image() |
54
|
|
|
); |
55
|
|
|
|
56
|
5 |
|
$metadata->addPropertyConstraint( |
57
|
5 |
|
'title', |
58
|
5 |
|
new Assert\NotNull() |
59
|
|
|
); |
60
|
|
|
|
61
|
5 |
|
$metadata->addPropertyConstraint( |
62
|
5 |
|
'content', |
63
|
5 |
|
new Assert\NotNull() |
64
|
|
|
); |
65
|
5 |
|
} |
66
|
|
|
|
67
|
|
|
public function getComponentLocations(): Collection |
68
|
|
|
{ |
69
|
|
|
return new ArrayCollection( |
70
|
|
|
[ |
71
|
|
|
$this->getHeroComponent(), |
72
|
|
|
$this->getContentComponent() |
73
|
|
|
] |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
private function getHeroComponent() { |
78
|
|
|
$hero = new Hero(); |
79
|
|
|
$hero->setTitle($this->getTitle()); |
80
|
|
|
$hero->setSubtitle($this->subtitle); |
81
|
|
|
return $hero; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
private function getContentComponent() { |
85
|
|
|
$content = new Content(); |
86
|
|
|
$content->setContent($this->content); |
87
|
|
|
return $content; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param null|string $subtitle |
92
|
|
|
*/ |
93
|
2 |
|
public function setSubtitle(?string $subtitle): void |
94
|
|
|
{ |
95
|
2 |
|
$this->subtitle = $subtitle; |
96
|
2 |
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param string $content |
100
|
|
|
*/ |
101
|
2 |
|
public function setContent(string $content): void |
102
|
|
|
{ |
103
|
2 |
|
$this->content = $content; |
104
|
2 |
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return null|string |
108
|
|
|
*/ |
109
|
1 |
|
public function getSubtitle(): ?string |
110
|
|
|
{ |
111
|
1 |
|
return $this->subtitle; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
1 |
|
public function getContent(): string |
118
|
|
|
{ |
119
|
1 |
|
return $this->content; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|