From e57e208b22f95aa123ceb17ce8838290db239958 Mon Sep 17 00:00:00 2001 From: manuxi Date: Sun, 28 Mar 2021 15:42:29 +0200 Subject: [PATCH] EventSelectionContentType added; Clean up code --- src/Admin/EventAdmin.php | 8 ---- src/Admin/LocationAdmin.php | 5 --- src/Content/EventSelectionContentType.php | 50 +++++++++++++++++++++++ src/Repository/EventSeoRepository.php | 23 ----------- src/Resources/config/routes.yml | 5 --- src/Resources/config/services.xml | 19 ++++++--- 6 files changed, 63 insertions(+), 47 deletions(-) create mode 100644 src/Content/EventSelectionContentType.php delete mode 100644 src/Resources/config/routes.yml diff --git a/src/Admin/EventAdmin.php b/src/Admin/EventAdmin.php index f215ed1..3e2871c 100644 --- a/src/Admin/EventAdmin.php +++ b/src/Admin/EventAdmin.php @@ -19,26 +19,18 @@ class EventAdmin extends Admin { public const LIST_VIEW = 'app.event.list'; - public const ADD_FORM_VIEW = 'app.event.add_form'; - public const ADD_FORM_DETAILS_VIEW = 'app.event.add_form.details'; - public const EDIT_FORM_VIEW = 'app.event.edit_form'; - public const EDIT_FORM_DETAILS_VIEW = 'app.event.edit_form.details'; - public const SECURITY_CONTEXT = 'sulu.modules.events'; //seo,excerpt, etc public const EDIT_FORM_VIEW_SEO = 'app.event.edit_form.seo'; - public const EDIT_FORM_VIEW_EXCERPT = 'app.event.edit_form.excerpt'; private $viewBuilderFactory; - private $securityChecker; - private $webspaceManager; public function __construct( diff --git a/src/Admin/LocationAdmin.php b/src/Admin/LocationAdmin.php index 479e30f..42c798b 100644 --- a/src/Admin/LocationAdmin.php +++ b/src/Admin/LocationAdmin.php @@ -19,17 +19,12 @@ class LocationAdmin extends Admin { public const LIST_VIEW = 'app.location.list'; - public const ADD_FORM_VIEW = 'app.location.add_form'; - public const ADD_FORM_DETAILS_VIEW = 'app.location.add_form.details'; - public const EDIT_FORM_VIEW = 'app.location.edit_form'; - public const EDIT_FORM_DETAILS_VIEW = 'app.location.edit_form.details'; private $viewBuilderFactory; - private $securityChecker; public function __construct( diff --git a/src/Content/EventSelectionContentType.php b/src/Content/EventSelectionContentType.php new file mode 100644 index 0000000..132c87f --- /dev/null +++ b/src/Content/EventSelectionContentType.php @@ -0,0 +1,50 @@ +eventRepository = $eventRepository; + } + + /** + * @return Event[] + */ + public function getContentData(PropertyInterface $property): array + { + $ids = $property->getValue(); + $locale = $property->getStructure()->getLanguageCode(); + + $events = []; + foreach ($ids ?: [] as $id) { + $event = $this->eventRepository->findById((int) $id, $locale); + if ($event && $event->isEnabled()) { + $events[] = $event; + } + } + + return $events; + } + + /** + * @return mixed[] + */ + public function getViewData(PropertyInterface $property): array + { + return $property->getValue(); + } +} diff --git a/src/Repository/EventSeoRepository.php b/src/Repository/EventSeoRepository.php index c25cf06..2e2aad4 100644 --- a/src/Repository/EventSeoRepository.php +++ b/src/Repository/EventSeoRepository.php @@ -20,9 +20,6 @@ */ class EventSeoRepository extends ServiceEntityRepository { -// use DataProviderRepositoryTrait { -// findByFilters as parentFindByFilters; -// } public function __construct(ManagerRegistry $registry) { @@ -75,24 +72,4 @@ public function findById(int $id, string $locale): ?EventSeo return $eventSeo; } -// /** -// * @param mixed[] $filters -// */ -// public function findByFilters($filters, $page, $pageSize, $limit, $locale, $options = []) -// { -// $entities = $this->parentFindByFilters($filters, $page, $pageSize, $limit, $locale, $options); -// -// return array_map( -// function (EventSeo $entity) use ($locale) { -// return $entity->setLocale($locale); -// }, -// $entities -// ); -// } -// -// protected function appendJoins(QueryBuilder $queryBuilder, string $alias, string $locale): void -// { -// $queryBuilder->innerJoin($alias . '.translations', 'translation', Join::WITH, 'translation.locale = :locale'); -// $queryBuilder->setParameter('locale', $locale); -// } } diff --git a/src/Resources/config/routes.yml b/src/Resources/config/routes.yml deleted file mode 100644 index f11b0bc..0000000 --- a/src/Resources/config/routes.yml +++ /dev/null @@ -1,5 +0,0 @@ -event: - path: - en: /events/{id}/{slug} - de: /veranstaltungen/{id}/{slug} - controller: Manuxi\SuluEventBundle\Controller\Website\EventController::indexAction diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 7ff6eb2..92feb46 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -57,19 +57,26 @@ - + + + - - + - + + - + + + + + - + +