Skip to content

Commit

Permalink
EWPP-1983: Replace event date fields with timezone ones.
Browse files Browse the repository at this point in the history
  • Loading branch information
nagyad committed Feb 22, 2022
1 parent 17debd7 commit 607f4b3
Show file tree
Hide file tree
Showing 19 changed files with 123 additions and 55 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"openeuropa/behat-transformation-context": "~0.1",
"openeuropa/code-review": "^2.0",
"openeuropa/oe_contact_forms": "^1.2",
"openeuropa/oe_content": "dev-EPIC-EWPP-1539-Event-v2",
"openeuropa/oe_content": "dev-EWPP-1983",
"openeuropa/oe_corporate_blocks": "^4.4",
"openeuropa/oe_corporate_countries": "~2.0",
"openeuropa/oe_media": "^1.15",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
langcode: en
status: true
dependencies: { }
id: oe_event_long_date_hour_timezone
label: 'Event long date with hour and timezone'
locked: false
pattern: 'l j F Y, H:i T'

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
langcode: en
status: true
dependencies: { }
id: oe_event_programme_date_hour_timezone
label: 'Event programme date with hour with timezone'
locked: false
pattern: 'j M Y, h:i A T'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
langcode: en
status: true
dependencies: { }
id: oe_event_programme_date_timezone
label: 'Event programme date with timezone'
locked: false
pattern: 'j M Y T'
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ content:
weight: 1
label: above
settings:
timezone_override: ''
format_type: oe_event_long_date_hour
display_timezone: false
format_type: oe_event_long_date_hour_timezone
separator: '-'
third_party_settings: { }
type: daterange_default
type: daterange_timezone
region: content
oe_event_entrance_fee:
weight: 9
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
langcode: en
status: true
dependencies: { }
id: oe_event_long_date_hour_timezone
label: 'Event long date with hour and timezone'
locked: false
pattern: 'l j F Y, H:i T'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
langcode: en
status: true
dependencies: { }
id: oe_event_programme_date_hour_timezone
label: 'Event programme date with hour with timezone'
locked: false
pattern: 'j M Y, h:i A T'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
langcode: en
status: true
dependencies: { }
id: oe_event_programme_date_timezone
label: 'Event programme date with timezone'
locked: false
pattern: 'j M Y T'
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ function oe_theme_content_event_post_update_30001() {
'core.date_format.oe_event_programme_date',
'core.date_format.oe_event_programme_date_hour',
'core.date_format.oe_event_programme_hour',
'core.date_format.oe_event_programme_date_timezone',
'core.date_format.oe_event_programme_date_hour_timezone',
'core.date_format.oe_event_long_date_hour_timezone',
];
foreach ($date_formats as $date_format_name) {
$config = $storage->read($date_format_name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,11 @@ protected function getRenderableSubject(ContentEntityInterface $entity): array {
protected function getRenderableDates(ContentEntityInterface $entity): array {
return $this->entityTypeManager->getViewBuilder('node')->viewField($entity->get('oe_event_dates'), [
'label' => 'hidden',
'type' => 'daterange_default',
'type' => 'daterange_timezone',
'settings' => [
'format_type' => 'oe_event_date_hour',
'format_type' => 'oe_event_date_hour_timezone',
'separator' => '-',
'display_timezone' => FALSE,
],
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class ProgrammeExtraField extends EventExtraFieldBase {
/**
* Programme datetime format.
*/
const PROGRAMME_DATETIME_FORMAT = 'oe_event_programme_date_hour';
const PROGRAMME_DATETIME_FORMAT = 'oe_event_programme_date_hour_timezone';

/**
* Programme date format.
*/
const PROGRAMME_DATE_FORMAT = 'oe_event_programme_date';
const PROGRAMME_DATE_FORMAT = 'oe_event_programme_date_timezone';

/**
* Programme time format.
Expand Down Expand Up @@ -186,6 +186,7 @@ public function viewElements(ContentEntityInterface $entity) {
protected function generateEventProgrammeLabel(ProgrammeItemInterface $programme, ?string $previous_end_date = NULL): ?array {
$start_datetime = $programme->get('oe_event_programme_dates')->start_date;
$end_datetime = $programme->get('oe_event_programme_dates')->end_date;
$timezone = $programme->get('oe_event_programme_dates')->timezone;

$start_day = $this->dateFormatter->format($start_datetime->getTimestamp(), 'custom', 'Ymd');
$end_day = $this->dateFormatter->format($end_datetime->getTimestamp(), 'custom', 'Ymd');
Expand All @@ -196,16 +197,16 @@ protected function generateEventProgrammeLabel(ProgrammeItemInterface $programme
$end_date_format = $start_day === $end_day ? self::PROGRAMME_TIME_FORMAT : self::PROGRAMME_DATETIME_FORMAT;
$template = '{% trans %}{{ start_date }} - {{ end_date }}{% endtrans %}';
$context = [
'start_date' => $this->dateFormatter->format($start_datetime->getTimestamp(), $start_date_format),
'end_date' => $this->dateFormatter->format($end_datetime->getTimestamp(), $end_date_format),
'start_date' => $this->dateFormatter->format($start_datetime->getTimestamp(), $start_date_format, '', $timezone),
'end_date' => $this->dateFormatter->format($end_datetime->getTimestamp(), $end_date_format, '', $timezone),
];
// If the event program item running within 1 day and there are no
// other event program items in the current day coming before,
// show the date with time range within a day.
if ($start_date_format === self::PROGRAMME_DATETIME_FORMAT && $end_date_format === self::PROGRAMME_TIME_FORMAT) {
$template = '{% trans %}{{ start_day }},<br>{{ start_date }} - {{ end_date }}{% endtrans %}';
$context['start_day'] = $this->dateFormatter->format($start_datetime->getTimestamp(), self::PROGRAMME_DATE_FORMAT);
$context['start_date'] = $this->dateFormatter->format($start_datetime->getTimestamp(), self::PROGRAMME_TIME_FORMAT);
$context['start_day'] = $this->dateFormatter->format($start_datetime->getTimestamp(), self::PROGRAMME_DATE_FORMAT, '', $timezone);
$context['start_date'] = $this->dateFormatter->format($start_datetime->getTimestamp(), self::PROGRAMME_TIME_FORMAT, '', $timezone);
}

return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ public function viewElements(ContentEntityInterface $entity) {
// show different message.
if ($datetime_start->format('Ymd') === $request_datetime->format('Ymd')) {
$build['#description'] = $this->t('Registration will open today, @start_date.', [
'@start_date' => $this->dateFormatter->format($datetime_start->getTimestamp(), 'oe_event_date_hour'),
'@start_date' => $this->dateFormatter->format($datetime_start->getTimestamp(), 'oe_event_date_hour_timezone', '', $event->getRegistrationTimezone()),
]);
}
else {
$date_diff_formatted = $this->dateFormatter->formatDiff($this->requestTime, $datetime_start->getTimestamp(), ['granularity' => 1]);
$build['#description'] = $this->t('Registration will open in @time_left. You can register from @start_date, until @end_date.', [
'@time_left' => $date_diff_formatted,
'@start_date' => $this->dateFormatter->format($datetime_start->getTimestamp(), 'oe_event_date_hour'),
'@end_date' => $this->dateFormatter->format($datetime_end->getTimestamp(), 'oe_event_date_hour'),
'@start_date' => $this->dateFormatter->format($datetime_start->getTimestamp(), 'oe_event_date_hour_timezone', '', $event->getRegistrationTimezone()),
'@end_date' => $this->dateFormatter->format($datetime_end->getTimestamp(), 'oe_event_date_hour_timezone', '', $event->getRegistrationTimezone()),
]);
}

Expand All @@ -144,14 +144,14 @@ public function viewElements(ContentEntityInterface $entity) {
// show different message.
if ($datetime_end->format('Ymd') === $request_datetime->format('Ymd')) {
$build['#description'] = $this->t('Book your seat, the registration will end today, @end_date', [
'@end_date' => $this->dateFormatter->format($datetime_end->getTimestamp(), 'oe_event_date_hour'),
'@end_date' => $this->dateFormatter->format($datetime_end->getTimestamp(), 'oe_event_date_hour_timezone', '', $event->getRegistrationTimezone()),
]);
}
else {
$date_diff_formatted = $this->dateFormatter->formatDiff($this->requestTime, $datetime_end->getTimestamp(), ['granularity' => 1]);
$build['#description'] = $this->t('Book your seat, @time_left left to register, registration will end on @end_date', [
'@time_left' => $date_diff_formatted,
'@end_date' => $this->dateFormatter->format($datetime_end->getTimestamp(), 'oe_event_date_hour'),
'@end_date' => $this->dateFormatter->format($datetime_end->getTimestamp(), 'oe_event_date_hour_timezone', '', $event->getRegistrationTimezone()),
]);
}

Expand All @@ -167,7 +167,7 @@ public function viewElements(ContentEntityInterface $entity) {
if ($event->isRegistrationPeriodOver($this->requestDateTime)) {
$datetime_end = $event->getRegistrationEndDate();
$build['#description'] = $this->t('Registration period ended on @date', [
'@date' => $this->dateFormatter->format($datetime_end->getTimestamp(), 'oe_event_long_date_hour'),
'@date' => $this->dateFormatter->format($datetime_end->getTimestamp(), 'oe_event_long_date_hour_timezone', '', $event->getRegistrationTimezone()),
]);
$build['#show_button'] = FALSE;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{#
/**
* @file
* Theme override for the datetime-range-timezone template.
*
* @see \Drupal\datetime_range_timezone\Plugin\Field\FieldFormatter\DateRangeTimezone::viewElements()
*/
#}
<div class='daterange'>
<span class='daterange__date daterange__start-date'>{{ start_date }}</span>
<span class='daterange__separtor'> {{ separator }} </span>
<span class='daterange__date daterange__end-date'>{{ end_date }}</span>

{% if timezone %}
<span class='daterange__timezone'> {{ timezone }}</span>
{% endif %}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ public function testLivestreamDisplayDisclosing(): void {
'oe_event_dates' => [
'value' => $start_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'end_value' => $start_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'timezone' => 'Europe/Brussels',
],
'oe_event_online_dates' => [
'value' => $start_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'end_value' => $start_date->modify('+3 hours')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'timezone' => 'Europe/Brussels',
],
'oe_event_languages' => [
['target_id' => 'http://publications.europa.eu/resource/authority/language/EST'],
Expand Down
Loading

0 comments on commit 607f4b3

Please sign in to comment.