diff --git a/config/packages/app_event_admin.yaml b/config/packages/app_event_admin.yaml index 0d8d410f..bcd798fa 100644 --- a/config/packages/app_event_admin.yaml +++ b/config/packages/app_event_admin.yaml @@ -4,3 +4,38 @@ sulu_admin: routes: list: 'app.get_event_list' detail: 'app.get_event' + field_type_options: + selection: + event_selection: + default_type: 'list_overlay' + resource_key: 'events' + view: + name: 'app.event.edit_form' + result_to_view: + id: 'id' + types: + list_overlay: + adapter: 'table' + list_key: 'events' + display_properties: + - 'name' + icon: 'su-calendar' + label: 'app.event_selection_label' + overlay_title: 'app.select_events' + single_selection: + single_event_selection: + default_type: 'list_overlay' + resource_key: 'events' + view: + name: 'app.event.edit_form' + result_to_view: + id: 'id' + types: + list_overlay: + adapter: 'table' + list_key: 'events' + display_properties: + - 'name' + icon: 'su-calendar' + empty_text: 'app.no_event_selected' + overlay_title: 'app.select_event' diff --git a/config/services.yaml b/config/services.yaml index 3877d370..1e27ef79 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -44,3 +44,9 @@ services: App\Content\Type\AlbumSelection: tags: [{name: 'sulu.content.type', alias: 'album_selection'}] + + App\Content\Type\SingleEventSelection: + tags: [ { name: 'sulu.content.type', alias: 'single_event_selection' } ] + + App\Content\Type\EventSelection: + tags: [ { name: 'sulu.content.type', alias: 'event_selection' } ] diff --git a/src/Content/Type/EventSelection.php b/src/Content/Type/EventSelection.php new file mode 100644 index 00000000..8595c20c --- /dev/null +++ b/src/Content/Type/EventSelection.php @@ -0,0 +1,53 @@ +entityManager = $entityManager; + + parent::__construct('event_selection', []); + } + + /** + * @return Event[] + */ + public function getContentData(PropertyInterface $property): array + { + $ids = $property->getValue(); + + if (empty($ids)) { + return []; + } + + $events = $this->entityManager->getRepository(Event::class)->findBy(['id' => $ids]); + + $idPositions = array_flip($ids); + usort($events, function (Event $a, Event $b) use ($idPositions) { + return $idPositions[$a->getId()] - $idPositions[$b->getId()]; + }); + + return $events; + } + + /** + * @return array|null> + */ + public function getViewData(PropertyInterface $property): array + { + return [ + 'ids' => $property->getValue(), + ]; + } +} diff --git a/src/Content/Type/SingleEventSelection.php b/src/Content/Type/SingleEventSelection.php new file mode 100644 index 00000000..0eb2ba92 --- /dev/null +++ b/src/Content/Type/SingleEventSelection.php @@ -0,0 +1,43 @@ +entityManager = $entityManager; + + parent::__construct('single_event_selection', null); + } + + public function getContentData(PropertyInterface $property): ?Event + { + $id = $property->getValue(); + + if (empty($id)) { + return null; + } + + return $this->entityManager->getRepository(Event::class)->find($id); + } + + /** + * @return array + */ + public function getViewData(PropertyInterface $property): array + { + return [ + 'id' => $property->getValue(), + ]; + } +} diff --git a/translations/admin.de.json b/translations/admin.de.json index f012133c..a1aa91e5 100644 --- a/translations/admin.de.json +++ b/translations/admin.de.json @@ -13,5 +13,9 @@ "app.select_album": "Album auswählen", "app.events": "Events", "app.start_date": "Startdatum", - "app.end_date": "Enddatum" + "app.end_date": "Enddatum", + "app.event_selection_label": "{count} {count, plural, =1 {Event} other {Events}} ausgewählt", + "app.select_events": "Events auswählen", + "app.no_event_selected": "Kein Event ausgewählt", + "app.select_event": "Event auswählen" } diff --git a/translations/admin.en.json b/translations/admin.en.json index 109345a2..ecc7c0b5 100644 --- a/translations/admin.en.json +++ b/translations/admin.en.json @@ -13,5 +13,9 @@ "app.select_album": "Select album", "app.events": "Events", "app.start_date": "Start Date", - "app.end_date": "End Date" + "app.end_date": "End Date", + "app.event_selection_label": "{count} {count, plural, =1 {event} other {events}} selected", + "app.select_events": "Select events", + "app.no_event_selected": "No event selected", + "app.select_event": "Select event" }