Skip to content

Commit 684b88e

Browse files
authored
Merge pull request #545 from itk-dev/hotfix/5319-event-details
5319: Added redirect to pretix date
2 parents e4fc2a8 + a690bbe commit 684b88e

File tree

4 files changed

+109
-2
lines changed

4 files changed

+109
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
88

9+
* [PR-545](https://github.com/itk-dev/deltag.aarhus.dk/pull/545)
10+
Fixed issue with public meeting details not being shown.
11+
912
## [4.12.0] - 2025-08-26
1013

1114
* [PR-543](https://github.com/itk-dev/deltag.aarhus.dk/pull/543)

web/modules/custom/hoeringsportal_public_meeting/hoeringsportal_public_meeting.services.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,10 @@ services:
77
tags:
88
- { name: event_subscriber }
99

10+
hoeringsportal_public_meeting.redirect_event_subscriber:
11+
class: Drupal\hoeringsportal_public_meeting\EventSubscriber\RedirectEventSubscriber
12+
tags:
13+
- { name: event_subscriber }
14+
1015
hoeringsportal_public_meeting.public_meeting_helper:
1116
class: Drupal\hoeringsportal_public_meeting\Helper\PublicMeetingHelper
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
3+
namespace Drupal\hoeringsportal_public_meeting\EventSubscriber;
4+
5+
use Drupal\node\NodeInterface;
6+
use Drupal\Core\Routing\RouteMatchInterface;
7+
use Drupal\Core\Routing\TrustedRedirectResponse;
8+
use Drupal\Core\Url;
9+
use Drupal\hoeringsportal_public_meeting\Helper\PublicMeetingHelper;
10+
use Drupal\itk_pretix\Plugin\Field\FieldType\PretixDate;
11+
use Symfony\Component\DependencyInjection\Attribute\Autowire;
12+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
13+
use Symfony\Component\HttpKernel\Event\RequestEvent;
14+
use Symfony\Component\HttpKernel\KernelEvents;
15+
16+
/**
17+
* An event subscriber.
18+
*/
19+
class RedirectEventSubscriber implements EventSubscriberInterface {
20+
21+
public function __construct(
22+
private readonly RouteMatchInterface $routeMatch,
23+
#[Autowire(service: 'hoeringsportal_public_meeting.public_meeting_helper')]
24+
private readonly PublicMeetingHelper $publicMeetingHelper,
25+
) {}
26+
27+
/**
28+
* Redirect to first upcoming date (or first date)
29+
*/
30+
public function redirectToDate(RequestEvent $event) {
31+
// Redirect to a date if viewing a pretix meeting with no specific pretix
32+
// date requested.
33+
if ('entity.node.canonical' === $this->routeMatch->getRouteName()
34+
|| ('hoeringsportal_public_meeting.public_meeting_date' === $this->routeMatch->getRouteName()
35+
&& (int) $this->routeMatch->getParameter('dates_delta') < 0)) {
36+
/** @var \Drupal\node\NodeInterface $node */
37+
$node = $this->routeMatch->getParameter('node');
38+
if ($this->publicMeetingHelper->isPublicMeeting($node) && $this->publicMeetingHelper->hasPretixSignUp($node)) {
39+
$datesDelta = $this->getNextDatesDelta($node);
40+
if (NULL !== $datesDelta) {
41+
$url = Url::fromRoute(
42+
'hoeringsportal_public_meeting.public_meeting_date',
43+
[
44+
'node' => $node->id(),
45+
'dates_delta' => $datesDelta,
46+
]
47+
);
48+
$event->setResponse(new TrustedRedirectResponse($url->toString(TRUE)
49+
->getGeneratedUrl()));
50+
}
51+
}
52+
}
53+
}
54+
55+
/**
56+
* Get next dates delta if any.
57+
*
58+
* The "next dates delta" is the delta of an upcoming date if any or of the
59+
* first date.
60+
*/
61+
private function getNextDatesDelta(NodeInterface $node): ?int {
62+
$getDelta = static function (PretixDate $date): ?int {
63+
$delta = (int) $date->getName();
64+
65+
return $delta > -1 ? $delta : NULL;
66+
};
67+
68+
// Check if we have a context with an upcoming date.
69+
$context = $this->publicMeetingHelper->getPublicMeetingContext($node);
70+
if (isset($context['upcoming'])) {
71+
if ($data = reset($context['upcoming'])) {
72+
$delta = $getDelta($data);
73+
if (NULL !== $delta) {
74+
return $delta;
75+
}
76+
}
77+
}
78+
79+
$dates = $this->publicMeetingHelper->getPretixDates($node);
80+
if ($date = $dates->first()) {
81+
$delta = $getDelta($date);
82+
if (NULL !== $delta) {
83+
return $delta;
84+
}
85+
}
86+
87+
return NULL;
88+
}
89+
90+
/**
91+
* {@inheritdoc}
92+
*/
93+
public static function getSubscribedEvents() {
94+
return [
95+
KernelEvents::REQUEST => [['redirectToDate']],
96+
];
97+
}
98+
99+
}

web/modules/custom/hoeringsportal_public_meeting/templates/hoeringsportal-public-meeting-summary.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434

3535
{% if variables is defined %}
3636
<h5 class="mt-3">{{ 'Date'|t }}</h5>
37-
{{ variables.time_from_value|date('U')|format_date('hoeringsportal_date_long') }}
37+
{{ variables.time_from|date('U')|format_date('hoeringsportal_date_long') }}
3838

3939
<h5 class="mt-3">{{ 'Time'|t }}</h5>
40-
{{ variables.time_from_value|date('U')|format_date('hoeringsportal_time') }} - {{ variables.time_to_value|date('U')|format_date('hoeringsportal_time') }}
40+
{{ variables.time_from|date('U')|format_date('hoeringsportal_time') }} - {{ variables.time_to|date('U')|format_date('hoeringsportal_time') }}
4141
{% elseif node.field_last_meeting_time[0] is defined %}
4242
<h5 class="mt-3">{{ 'Date'|t }}</h5>
4343
{{ node.field_last_meeting_time[0].date|date('U')|format_date('hoeringsportal_date_long') }}

0 commit comments

Comments
 (0)