Fix event sorting

Re-add `field_event_date` to sort the talks by their most recent event
date in their custom order.
This commit is contained in:
Oliver Davies 2024-05-02 23:13:23 +01:00
parent 6eed26a756
commit 9a96363ff7
7 changed files with 85 additions and 23 deletions

View file

@ -4,6 +4,7 @@ status: true
dependencies:
config:
- field.field.node.talk.body
- field.field.node.talk.field_event_date
- field.field.node.talk.field_events
- field.field.node.talk.field_slides
- field.field.node.talk.field_video
@ -112,4 +113,5 @@ content:
region: content
settings: { }
third_party_settings: { }
hidden: { }
hidden:
field_event_date: true

View file

@ -4,12 +4,14 @@ status: true
dependencies:
config:
- field.field.node.talk.body
- field.field.node.talk.field_event_date
- field.field.node.talk.field_events
- field.field.node.talk.field_slides
- field.field.node.talk.field_video
- node.type.talk
- views.view.events
module:
- datetime
- layout_builder
- layout_discovery
- speakerdeck_field
@ -92,6 +94,23 @@ third_party_settings:
items_per_page: none
weight: 5
additional: { }
ccf9bc4e-e750-4762-901a-766292184cd7:
uuid: ccf9bc4e-e750-4762-901a-766292184cd7
region: content
configuration:
id: 'field_block:node:talk:field_event_date'
label_display: '0'
context_mapping:
entity: layout_builder.entity
formatter:
type: datetime_default
label: above
settings:
timezone_override: ''
format_type: medium
third_party_settings: { }
weight: 6
additional: { }
third_party_settings: { }
id: node.talk.default
targetEntityType: node
@ -105,6 +124,15 @@ content:
third_party_settings: { }
weight: 101
region: content
field_event_date:
type: datetime_default
label: above
settings:
timezone_override: ''
format_type: medium
third_party_settings: { }
weight: 105
region: content
field_events:
type: entity_reference_entity_view
label: above

View file

@ -5,6 +5,7 @@ dependencies:
config:
- core.entity_view_mode.node.teaser
- field.field.node.talk.body
- field.field.node.talk.field_event_date
- field.field.node.talk.field_events
- field.field.node.talk.field_slides
- field.field.node.talk.field_video
@ -26,6 +27,7 @@ content:
weight: 0
region: content
hidden:
field_event_date: true
field_events: true
field_slides: true
field_video: true

View file

@ -0,0 +1,21 @@
uuid: c4294337-cdd3-4279-ba3f-55b135ec2399
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_event_date
- node.type.talk
module:
- datetime
id: node.talk.field_event_date
field_name: field_event_date
entity_type: node
bundle: talk
label: 'Event date'
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: datetime

View file

@ -0,0 +1,20 @@
uuid: 9e8d548e-b3a8-455e-b5e3-59eb7c56ca2e
langcode: en
status: true
dependencies:
module:
- datetime
- node
id: node.field_event_date
field_name: field_event_date
entity_type: node
type: datetime
settings:
datetime_type: date
module: datetime
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false

View file

@ -8,6 +8,7 @@ dependencies:
- system.menu.main
module:
- node
- opdavies_talks
- user
id: talks
label: 'Talks and workshops'
@ -95,17 +96,15 @@ display:
options: { }
empty: { }
sorts:
created:
id: created
table: node_field_data
field: created
event_sort:
id: event_sort
table: node__field_events
field: event_sort
relationship: none
group_type: group
admin_label: ''
entity_type: node
entity_field: created
plugin_id: date
order: DESC
plugin_id: event_sort
order: ASC
expose:
label: ''
field_identifier: ''

View file

@ -36,13 +36,11 @@ final class UpdateTalkNodeBeforeSave implements EventSubscriberInterface {
$talk = Talk::createFromNode($node);
$this->reorderEvents($talk);
$this->updateCreatedDate($talk);
$this->updateMostRecentEventDate($talk);
}
private function reorderEvents(Talk $talk): void {
$events = $talk->getEvents();
// If there is only one event, there's no need to sort them.
if ($events->count() === 1) {
return;
};
@ -62,18 +60,10 @@ final class UpdateTalkNodeBeforeSave implements EventSubscriberInterface {
->values();
}
private function updateCreatedDate(Talk $talk): void {
if (!$eventDate = $talk->findLatestEventDate()) {
return;
}
private function updateMostRecentEventDate(Talk $talk): void {
$mostRecentEventDate = $talk->findLatestEventDate();
$talkDate = Carbon::parse($eventDate)->getTimestamp();
if ($talkDate == $talk->getCreatedTime()) {
return;
}
$talk->setCreatedTime($talkDate);
$talk->set('field_event_date', $mostRecentEventDate);
}
}