1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Silverback\ApiComponentBundle\Entity\Content\Page; |
4
|
|
|
|
5
|
|
|
use ApiPlatform\Core\Annotation\ApiProperty; |
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
7
|
|
|
use Doctrine\ORM\Mapping as ORM; |
8
|
|
|
use Silverback\ApiComponentBundle\Entity\Content\AbstractContent; |
9
|
|
|
use Silverback\ApiComponentBundle\Entity\Layout\Layout; |
10
|
|
|
use Silverback\ApiComponentBundle\Entity\Route\Route; |
11
|
|
|
use Silverback\ApiComponentBundle\Entity\Route\RouteAwareInterface; |
12
|
|
|
use Silverback\ApiComponentBundle\Entity\Route\RouteAwareTrait; |
13
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class AbstractPage |
17
|
|
|
* @package Silverback\ApiComponentBundle\Entity\Content |
18
|
|
|
* @ORM\Entity() |
19
|
|
|
*/ |
20
|
|
|
abstract class AbstractPage extends AbstractContent implements RouteAwareInterface |
21
|
|
|
{ |
22
|
|
|
use RouteAwareTrait; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @ORM\Column() |
26
|
|
|
* @Groups({"content", "route", "component"}) |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $title; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @ORM\Column() |
33
|
|
|
* @Groups({"content", "route"}) |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $metaDescription; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @ORM\ManyToOne(targetEntity="Silverback\ApiComponentBundle\Entity\Content\Page\Page") |
40
|
|
|
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL") |
41
|
|
|
* @Groups({"route"}) |
42
|
|
|
* @var null|Page |
43
|
|
|
*/ |
44
|
|
|
protected $parent; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @ORM\ManyToOne(targetEntity="Silverback\ApiComponentBundle\Entity\Layout\Layout") |
48
|
|
|
* @ORM\JoinColumn(onDelete="SET NULL") |
49
|
|
|
* @ApiProperty() |
50
|
|
|
* @Groups({"content","route"}) |
51
|
|
|
* @var Layout|null |
52
|
|
|
*/ |
53
|
|
|
protected $layout; |
54
|
|
|
|
55
|
|
|
public function __construct() |
56
|
|
|
{ |
57
|
|
|
parent::__construct(); |
58
|
|
|
$this->routes = new ArrayCollection; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
|
|
public function getTitle(): string |
65
|
|
|
{ |
66
|
|
|
return $this->title; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $title |
71
|
|
|
*/ |
72
|
|
|
public function setTitle(string $title): void |
73
|
|
|
{ |
74
|
|
|
$this->title = $title; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
|
|
public function getMetaDescription(): string |
81
|
|
|
{ |
82
|
|
|
return $this->metaDescription ?: ''; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param string $metaDescription |
87
|
|
|
*/ |
88
|
|
|
public function setMetaDescription(string $metaDescription): void |
89
|
|
|
{ |
90
|
|
|
$this->metaDescription = $metaDescription; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return null|Page |
95
|
|
|
*/ |
96
|
|
|
public function getParent(): ?Page |
97
|
|
|
{ |
98
|
|
|
return $this->parent; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param null|Page $parent |
103
|
|
|
*/ |
104
|
|
|
public function setParent(?Page $parent): void |
105
|
|
|
{ |
106
|
|
|
$this->parent = $parent; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return Layout|null |
111
|
|
|
*/ |
112
|
|
|
public function getLayout(): ?Layout |
113
|
|
|
{ |
114
|
|
|
return $this->layout; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param Layout|null $layout |
119
|
|
|
*/ |
120
|
|
|
public function setLayout(?Layout $layout): void |
121
|
|
|
{ |
122
|
|
|
$this->layout = $layout; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @inheritdoc |
127
|
|
|
*/ |
128
|
|
|
public function getDefaultRoute(): string |
129
|
|
|
{ |
130
|
|
|
return $this->getTitle(); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @inheritdoc |
135
|
|
|
*/ |
136
|
|
|
public function getDefaultRouteName(): string |
137
|
|
|
{ |
138
|
|
|
return $this->getTitle(); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @inheritdoc |
143
|
|
|
*/ |
144
|
|
|
public function getParentRoute(): ?Route |
145
|
|
|
{ |
146
|
|
|
return $this->getParent() ? $this->getParent()->getRoutes()->first() : null; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
abstract public function isDynamic(): bool; |
150
|
|
|
} |
151
|
|
|
|