Skip to content

Commit bfe764b

Browse files
committed
Wip on 5.x
1 parent 3b77106 commit bfe764b

File tree

22 files changed

+200
-141
lines changed

22 files changed

+200
-141
lines changed

Controller/AbstractCmsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected function getFinalTreeElement(array $slugs, array $elements)
5252
if ($element) {
5353
// Only for the first iteration
5454
$match = $previousElement
55-
? $element->getParent() && $previousElement->getSlug() === $element->getParent()->getSlug()
55+
? ($element->getParent() && $previousElement->getSlug() === $element->getParent()->getSlug())
5656
: true;
5757

5858
$previousElement = $element;

Controller/PageController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(PageRepository $pageRepository)
3030
$this->pageRepository = $pageRepository;
3131
}
3232

33-
public function indexAction(Request $request, string $slugs = '', string $_locale = null): Response
33+
public function indexAction(Request $request, string $slugs = '', ?string $_locale = null): Response
3434
{
3535
if (preg_match('~/$~', $slugs)) {
3636
return $this->redirect($this->generateUrl('orbitale_cms_page', ['slugs' => rtrim($slugs, '/')]));

Controller/PostsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(PageRepository $pageRepository)
3232
$this->pageRepository = $pageRepository;
3333
}
3434

35-
public function indexAction(Request $request, string $slugs = '', string $date = '', string $_date_format = null, string $_locale = null): Response
35+
public function indexAction(Request $request, string $slugs = '', string $date = '', ?string $_date_format = null, ?string $_locale = null): Response
3636
{
3737
if (!$this->isValidDate($date, $_date_format)) {
3838
throw $this->createNotFoundException("Invalid date format provided");

DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Configuration implements ConfigurationInterface
2727
/**
2828
* {@inheritdoc}
2929
*/
30-
public function getConfigTreeBuilder()
30+
public function getConfigTreeBuilder(): TreeBuilder
3131
{
3232
$treeBuilder = new TreeBuilder('orbitale_cms');
3333
$rootNode = $treeBuilder->getRootNode();

DependencyInjection/OrbitaleCmsExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class OrbitaleCmsExtension extends Extension
2727
/**
2828
* {@inheritdoc}
2929
*/
30-
public function load(array $configs, ContainerBuilder $container)
30+
public function load(array $configs, ContainerBuilder $container): void
3131
{
3232
$configuration = new Configuration();
3333
$config = $this->processConfiguration($configuration, $configs);

Entity/Category.php

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,15 @@
1212
namespace Orbitale\Bundle\CmsBundle\Entity;
1313

1414
use Doctrine\Common\Collections\ArrayCollection;
15-
use Doctrine\ORM\Event\LifecycleEventArgs;
16-
use Doctrine\ORM\Mapping as ORM;
15+
use Doctrine\ORM\Event\PreRemoveEventArgs;
1716
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
1817
use Symfony\Component\String\Slugger\AsciiSlugger;
1918
use Symfony\Component\Validator\Constraints as Assert;
2019

2120
/**
2221
* @UniqueEntity("slug")
23-
* @ORM\HasLifecycleCallbacks()
24-
* @ORM\MappedSuperclass(repositoryClass="Orbitale\Bundle\CmsBundle\Repository\CategoryRepository")
2522
*/
23+
#[UniqueEntity("slug")]
2624
abstract class Category
2725
{
2826
/**
@@ -33,46 +31,44 @@ abstract public function getId();
3331
/**
3432
* @var string
3533
*
36-
* @ORM\Column(name="name", type="string", length=255)
37-
*
3834
* @Assert\Type("string")
3935
* @Assert\NotBlank()
4036
*/
37+
#[Assert\Type("string")]
38+
#[Assert\NotBlank]
4139
protected $name;
4240

4341
/**
4442
* @var string
4543
*
46-
* @ORM\Column(name="slug", type="string", length=255, unique=true)
47-
*
4844
* @Assert\Type("string")
4945
* @Assert\NotBlank()
5046
*/
47+
#[Assert\Type("string")]
48+
#[Assert\NotBlank]
5149
protected $slug;
5250

5351
/**
5452
* @var string
5553
*
56-
* @ORM\Column(name="description", type="text", nullable=true)
57-
*
5854
* @Assert\Type("string")
5955
*/
56+
#[Assert\Type("string")]
6057
protected $description;
6158

6259
/**
6360
* @var bool
6461
*
65-
* @ORM\Column(name="enabled", type="boolean")
66-
*
6762
* @Assert\Type("bool")
6863
*/
64+
#[Assert\Type("bool")]
6965
protected $enabled = false;
7066

7167
/**
7268
* @var Category
73-
*
7469
* @Assert\Type(Category::class)
7570
*/
71+
#[Assert\Type(Category::class)]
7672
protected $parent;
7773

7874
/**
@@ -217,25 +213,16 @@ public function getTree(string $separator = '/'): string
217213
return trim($tree, $separator);
218214
}
219215

220-
/**
221-
* @ORM\PrePersist()
222-
* @ORM\PreUpdate()
223-
*/
224216
public function updateSlug(): void
225217
{
226218
if (!$this->slug) {
227219
$this->slug = mb_strtolower((new AsciiSlugger())->slug($this->name)->toString());
228220
}
229221
}
230222

231-
/**
232-
* @ORM\PreRemove()
233-
*
234-
* @param LifecycleEventArgs $event
235-
*/
236-
public function onRemove(LifecycleEventArgs $event): void
223+
public function onRemove(PreRemoveEventArgs $event): void
237224
{
238-
$em = $event->getEntityManager();
225+
$em = $event->getObjectManager();
239226
if (count($this->children)) {
240227
foreach ($this->children as $child) {
241228
$child->setParent(null);

Entity/Page.php

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,15 @@
1212
namespace Orbitale\Bundle\CmsBundle\Entity;
1313

1414
use Doctrine\Common\Collections\ArrayCollection;
15-
use Doctrine\ORM\Event\LifecycleEventArgs;
16-
use Doctrine\ORM\Mapping as ORM;
15+
use Doctrine\ORM\Event\PreRemoveEventArgs;
1716
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
1817
use Symfony\Component\String\Slugger\AsciiSlugger;
1918
use Symfony\Component\Validator\Constraints as Assert;
2019

2120
/**
2221
* @UniqueEntity("slug")
23-
* @ORM\HasLifecycleCallbacks()
24-
* @ORM\MappedSuperclass(repositoryClass="Orbitale\Bundle\CmsBundle\Repository\PageRepository")
2522
*/
23+
#[UniqueEntity("slug")]
2624
abstract class Page
2725
{
2826
/**
@@ -33,134 +31,125 @@ abstract public function getId();
3331
/**
3432
* @var string
3533
*
36-
* @ORM\Column(name="title", type="string", length=255)
37-
*
3834
* @Assert\Type("string")
3935
* @Assert\NotBlank()
4036
*/
37+
#[Assert\Type("string")]
38+
#[Assert\NotBlank]
4139
protected $title;
4240

4341
/**
4442
* @var string
4543
*
46-
* @ORM\Column(name="slug", type="string", length=255, unique=true)
47-
*
4844
* @Assert\Type("string")
4945
* @Assert\NotBlank()
5046
*/
47+
#[Assert\Type("string")]
48+
#[Assert\NotBlank]
5149
protected $slug;
5250

5351
/**
5452
* @var string
5553
*
56-
* @ORM\Column(name="page_content", type="text", nullable=true)
57-
*
5854
* @Assert\Type("string")
5955
*/
56+
#[Assert\Type("string")]
6057
protected $content;
6158

6259
/**
6360
* @var string
6461
*
65-
* @ORM\Column(name="meta_description", type="string", length=255, nullable=true)
66-
*
6762
* @Assert\Type("string")
6863
*/
64+
#[Assert\Type("string")]
6965
protected $metaDescription;
7066

7167
/**
7268
* @var string
7369
*
74-
* @ORM\Column(name="meta_title", type="string", length=255, nullable=true)
75-
*
7670
* @Assert\Type("string")
7771
*/
72+
#[Assert\Type("string")]
7873
protected $metaTitle;
7974

8075
/**
8176
* @var string
8277
*
83-
* @ORM\Column(name="meta_keywords", type="string", length=255, nullable=true)
84-
*
8578
* @Assert\Type("string")
8679
*/
80+
#[Assert\Type("string")]
8781
protected $metaKeywords;
8882

8983
/**
9084
* @var null|Category
9185
*
9286
* @Assert\Type(Category::class)
9387
*/
88+
#[Assert\Type(Category::class)]
9489
protected $category;
9590

9691
/**
9792
* @var string
9893
*
99-
* @ORM\Column(name="css", type="text", nullable=true)
100-
*
10194
* @Assert\Type("string")
10295
*/
96+
#[Assert\Type("string")]
10397
protected $css;
10498

10599
/**
106100
* @var string
107101
*
108-
* @ORM\Column(name="js", type="text", nullable=true)
109-
*
110102
* @Assert\Type("string")
111103
*/
104+
#[Assert\Type("string")]
112105
protected $js;
113106

114107
/**
115108
* @var \DateTimeImmutable
116109
*
117-
* @ORM\Column(name="created_at", type="datetime_immutable")
118-
*
119110
* @Assert\Type(\DateTimeImmutable::class)
120111
*/
112+
#[Assert\Type(\DateTimeImmutable::class)]
121113
protected $createdAt;
122114

123115
/**
124116
* @var bool
125117
*
126-
* @ORM\Column(name="enabled", type="boolean")
127-
*
128118
* @Assert\Type("bool")
129119
*/
120+
#[Assert\Type("bool")]
130121
protected $enabled = false;
131122

132123
/**
133124
* @var bool
134125
*
135-
* @ORM\Column(name="homepage", type="boolean")
136-
*
137126
* @Assert\Type("bool")
138127
*/
128+
#[Assert\Type("bool")]
139129
protected $homepage = false;
140130

141131
/**
142132
* @var string
143133
*
144-
* @ORM\Column(name="host", type="string", length=255, nullable=true)
145-
*
146134
* @Assert\Type("string")
147135
*/
136+
#[Assert\Type("string")]
148137
protected $host;
149138

150139
/**
151140
* @var string
152141
*
153-
* @ORM\Column(name="locale", type="string", length=6, nullable=true)
154-
*
155142
* @Assert\Type("string")
156143
*/
144+
#[Assert\Type("string")]
157145
protected $locale;
158146

159147
/**
160148
* @var null|Page
161149
*
162150
* @Assert\Type(Page::class)
163151
*/
152+
#[Assert\Type(Page::class)]
164153
protected $parent;
165154

166155
/**
@@ -380,23 +369,16 @@ public function getTree(string $separator = '/'): string
380369
return trim($tree, $separator);
381370
}
382371

383-
/**
384-
* @ORM\PrePersist()
385-
* @ORM\PreUpdate()
386-
*/
387372
public function updateSlug(): void
388373
{
389374
if (!$this->slug) {
390375
$this->slug = mb_strtolower((new AsciiSlugger())->slug($this->title)->toString());
391376
}
392377
}
393378

394-
/**
395-
* @ORM\PreRemove()
396-
*/
397-
public function onRemove(LifecycleEventArgs $event): void
379+
public function onRemove(PreRemoveEventArgs $event): void
398380
{
399-
$em = $event->getEntityManager();
381+
$em = $event->getObjectManager();
400382
if (count($this->children)) {
401383
foreach ($this->children as $child) {
402384
$child->setParent(null);

EventListener/DoctrineMappingListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(string $pageClass, string $categoryClass)
3838
$this->categoryClass = $categoryClass;
3939
}
4040

41-
public function getSubscribedEvents()
41+
public function getSubscribedEvents(): array
4242
{
4343
return [Events::loadClassMetadata];
4444
}

EventListener/LayoutsListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(array $layouts, Environment $twig)
3939
/**
4040
* {@inheritdoc}
4141
*/
42-
public static function getSubscribedEvents()
42+
public static function getSubscribedEvents(): array
4343
{
4444
return [
4545
KernelEvents::REQUEST => ['setRequestLayout', 1],
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
4+
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
5+
6+
<mapped-superclass
7+
name="Orbitale\Bundle\CmsBundle\Entity\Category"
8+
repository-class="Orbitale\Bundle\CmsBundle\Repository\CategoryRepository"
9+
table="orbitale_cms_categories"
10+
>
11+
<lifecycle-callbacks>
12+
<lifecycle-callback type="prePersist" method="updateSlug" />
13+
<lifecycle-callback type="preUpdate" method="updateSlug" />
14+
<lifecycle-callback type="preRemove" method="onRemove" />
15+
</lifecycle-callbacks>
16+
<field name="name" type="string" length="255" nullable="false" />
17+
<field name="slug" type="string" length="255" unique="true" nullable="false" />
18+
<field name="description" type="text" nullable="true" />
19+
<field name="enabled" type="boolean" nullable="false">
20+
<options>
21+
<option name="default">0</option>
22+
</options>
23+
</field>
24+
</mapped-superclass>
25+
26+
</doctrine-mapping>

0 commit comments

Comments
 (0)