Skip to content

Commit 595716f

Browse files
author
Manuel Bertrams
committed
Constructor property promotion; EventDataItem Serializer with attributes; div. fixes
1 parent 6a0a90b commit 595716f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+233
-458
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
],
1919
"require": {
2020
"php": "^8.1",
21-
"doctrine/doctrine-bundle": "^2.12",
21+
"doctrine/doctrine-bundle": "^2.13",
2222
"phpcr/phpcr-migrations-bundle": "^1.6",
2323
"sulu/sulu": "^2.5",
2424
"sulu/automation-bundle": "^2.1",

src/Admin/EventAdmin.php

+5-16
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,15 @@ class EventAdmin extends Admin
3333
public const EDIT_FORM_VIEW_SEO = 'sulu_event.edit_form.seo';
3434
public const EDIT_FORM_VIEW_EXCERPT = 'sulu_event.edit_form.excerpt';
3535

36-
3736
public const EDIT_FORM_VIEW_SETTINGS = 'sulu_event.event.edit_form.settings';
3837
public const EDIT_FORM_VIEW_AUTOMATION = 'sulu_event.event.edit_form.automation';
3938

40-
private ViewBuilderFactoryInterface $viewBuilderFactory;
41-
private SecurityCheckerInterface $securityChecker;
42-
private WebspaceManagerInterface $webspaceManager;
43-
private ?AutomationViewBuilderFactoryInterface $automationViewBuilderFactory;
44-
4539
public function __construct(
46-
ViewBuilderFactoryInterface $viewBuilderFactory,
47-
SecurityCheckerInterface $securityChecker,
48-
WebspaceManagerInterface $webspaceManager,
49-
?AutomationViewBuilderFactoryInterface $automationViewBuilderFactory
50-
) {
51-
$this->viewBuilderFactory = $viewBuilderFactory;
52-
$this->securityChecker = $securityChecker;
53-
$this->webspaceManager = $webspaceManager;
54-
$this->automationViewBuilderFactory = $automationViewBuilderFactory;
55-
}
40+
private ViewBuilderFactoryInterface $viewBuilderFactory,
41+
private SecurityCheckerInterface $securityChecker,
42+
private WebspaceManagerInterface $webspaceManager,
43+
private ?AutomationViewBuilderFactoryInterface $automationViewBuilderFactory
44+
) {}
5645

5746
public function configureNavigationItems(NavigationItemCollection $navigationItemCollection): void
5847
{

src/Admin/Helper/WebspaceSelector.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,8 @@
88

99
class WebspaceSelector
1010
{
11-
12-
private WebspaceManagerInterface $webspaceManager;
13-
14-
public function __construct(WebspaceManagerInterface $webspaceManager)
15-
{
16-
$this->webspaceManager = $webspaceManager;
17-
}
11+
public function __construct(private WebspaceManagerInterface $webspaceManager)
12+
{}
1813

1914
public function getValues(): array
2015
{

src/Admin/LocationAdmin.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,10 @@ class LocationAdmin extends Admin
2626
public const EDIT_FORM_VIEW = 'sulu_event.location.edit_form';
2727
public const EDIT_FORM_DETAILS_VIEW = 'sulu_event.location.edit_form.details';
2828

29-
private ViewBuilderFactoryInterface $viewBuilderFactory;
30-
private SecurityCheckerInterface $securityChecker;
31-
3229
public function __construct(
33-
ViewBuilderFactoryInterface $viewBuilderFactory,
34-
SecurityCheckerInterface $securityChecker
35-
) {
36-
$this->viewBuilderFactory = $viewBuilderFactory;
37-
$this->securityChecker = $securityChecker;
38-
}
30+
private ViewBuilderFactoryInterface $viewBuilderFactory,
31+
private SecurityCheckerInterface $securityChecker
32+
) {}
3933

4034
/**
4135
* @param NavigationItemCollection $navigationItemCollection

src/Admin/SettingsAdmin.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,10 @@ class SettingsAdmin extends Admin
2121
public const FORM_VIEW = 'sulu_event.config.form';
2222
public const NAV_ITEM = 'sulu_event.config.title.navi';
2323

24-
private ViewBuilderFactoryInterface $viewBuilderFactory;
25-
private SecurityCheckerInterface $securityChecker;
26-
2724
public function __construct(
28-
ViewBuilderFactoryInterface $viewBuilderFactory,
29-
SecurityCheckerInterface $securityChecker
30-
) {
31-
$this->viewBuilderFactory = $viewBuilderFactory;
32-
$this->securityChecker = $securityChecker;
33-
}
25+
private ViewBuilderFactoryInterface $viewBuilderFactory,
26+
private SecurityCheckerInterface $securityChecker
27+
) {}
3428

3529
public function configureNavigationItems(NavigationItemCollection $navigationItemCollection): void
3630
{

src/Automation/PublishTaskHandler.php

+4-13
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,11 @@
1515

1616
class PublishTaskHandler implements AutomationTaskHandlerInterface
1717
{
18-
private EntityManagerInterface $entityManager;
19-
private TranslatorInterface $translator;
20-
private DomainEventCollectorInterface $domainEventCollector;
21-
2218
public function __construct(
23-
EntityManagerInterface $entityManager,
24-
TranslatorInterface $translator,
25-
DomainEventCollectorInterface $domainEventCollector
26-
)
27-
{
28-
$this->entityManager = $entityManager;
29-
$this->translator = $translator;
30-
$this->domainEventCollector = $domainEventCollector;
31-
}
19+
private EntityManagerInterface $entityManager,
20+
private TranslatorInterface $translator,
21+
private DomainEventCollectorInterface $domainEventCollector
22+
) {}
3223

3324
public function handle($workload): void
3425
{

src/Automation/UnpublishTaskHandler.php

+5-10
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,11 @@
1515

1616
class UnpublishTaskHandler implements AutomationTaskHandlerInterface
1717
{
18-
private EntityManagerInterface $entityManager;
19-
private TranslatorInterface $translator;
20-
private DomainEventCollectorInterface $domainEventCollector;
21-
22-
public function __construct(EntityManagerInterface $entityManager, TranslatorInterface $translator, DomainEventCollectorInterface $domainEventCollector)
23-
{
24-
$this->entityManager = $entityManager;
25-
$this->translator = $translator;
26-
$this->domainEventCollector = $domainEventCollector;
27-
}
18+
public function __construct(
19+
private EntityManagerInterface $entityManager,
20+
private TranslatorInterface $translator,
21+
private DomainEventCollectorInterface $domainEventCollector
22+
) {}
2823

2924
public function handle($workload): void
3025
{

src/Common/DoctrineListRepresentationFactory.php

+8-33
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,16 @@
1616

1717
class DoctrineListRepresentationFactory
1818
{
19-
private RestHelperInterface $restHelper;
20-
private ListRestHelperInterface $listRestHelper;
21-
private DoctrineListBuilderFactory $listBuilderFactory;
22-
private FieldDescriptorFactoryInterface $fieldDescriptorFactory;
23-
private WebspaceManagerInterface $webspaceManager;
24-
private EventTranslationRepository $eventTranslationRepository;
25-
private MediaManagerInterface $mediaManager;
26-
2719
public function __construct(
28-
RestHelperInterface $restHelper,
29-
ListRestHelperInterface $listRestHelper,
30-
DoctrineListBuilderFactory $listBuilderFactory,
31-
FieldDescriptorFactoryInterface $fieldDescriptorFactory,
32-
WebspaceManagerInterface $webspaceManager,
33-
EventTranslationRepository $eventTranslationRepository,
34-
MediaManagerInterface $mediaManager
35-
) {
36-
$this->restHelper = $restHelper;
37-
$this->listRestHelper = $listRestHelper;
38-
$this->listBuilderFactory = $listBuilderFactory;
39-
$this->fieldDescriptorFactory = $fieldDescriptorFactory;
40-
$this->webspaceManager = $webspaceManager;
41-
$this->eventTranslationRepository = $eventTranslationRepository;
42-
$this->mediaManager = $mediaManager;
43-
}
20+
private RestHelperInterface $restHelper,
21+
private ListRestHelperInterface $listRestHelper,
22+
private DoctrineListBuilderFactory $listBuilderFactory,
23+
private FieldDescriptorFactoryInterface $fieldDescriptorFactory,
24+
private WebspaceManagerInterface $webspaceManager,
25+
private EventTranslationRepository $eventTranslationRepository,
26+
private MediaManagerInterface $mediaManager
27+
) {}
4428

45-
/**
46-
* @param string $resourceKey
47-
* @param mixed[] $filters
48-
* @param mixed[] $parameters
49-
* @return PaginatedRepresentation
50-
*/
5129
public function createDoctrineListRepresentation(
5230
string $resourceKey,
5331
array $filters = [],
@@ -92,9 +70,6 @@ public function createDoctrineListRepresentation(
9270
);
9371
}
9472

95-
/**
96-
* @param mixed[]
97-
*/
9873
private function addImagesToListElements(array $listeElements, ?string $locale): array
9974
{
10075
$ids = array_filter(array_column($listeElements, 'image'));

src/Content/EventDataItem.php

+19-21
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,43 @@
44

55
namespace Manuxi\SuluEventBundle\Content;
66

7+
use Doctrine\ORM\EntityManagerInterface;
78
use JMS\Serializer\Annotation as Serializer;
89
use Manuxi\SuluEventBundle\Entity\Event;
10+
use Sulu\Bundle\MediaBundle\Entity\Media;
911
use Sulu\Component\SmartContent\ItemInterface;
1012

11-
/**
12-
* @Serializer\ExclusionPolicy("all")
13-
*/
13+
#[Serializer\ExclusionPolicy("all")]
1414
class EventDataItem implements ItemInterface
1515
{
16+
public function __construct(
17+
private Event $entity,
18+
private ?EntityManagerInterface $entityManager = null
19+
) {}
1620

17-
private Event $entity;
18-
19-
public function __construct(Event $entity)
20-
{
21-
$this->entity = $entity;
22-
}
23-
24-
/**
25-
* @Serializer\VirtualProperty
26-
*/
21+
#[Serializer\VirtualProperty]
2722
public function getId(): string
2823
{
2924
return (string) $this->entity->getId();
3025
}
3126

32-
/**
33-
* @Serializer\VirtualProperty
34-
*/
27+
#[Serializer\VirtualProperty]
3528
public function getTitle(): string
3629
{
3730
return (string) $this->entity->getTitle();
3831
}
3932

40-
/**
41-
* @Serializer\VirtualProperty
42-
*/
43-
public function getImage(): ?string
33+
#[Serializer\VirtualProperty]
34+
public function getImage(): ?int
4435
{
45-
return null;
36+
$imageId = $this->entity->getImages()['ids'][0];
37+
$image = $this->entityManager->getRepository(Media::class)->findById($imageId);;
38+
39+
if (!\array_key_exists('sulu-50x50', $thumbnails = $image->getThumbnails())) {
40+
return null;
41+
}
42+
43+
return $thumbnails['sulu-50x50'];
4644
}
4745

4846
public function getResource(): Event

0 commit comments

Comments
 (0)