Sort order of Same day time slots is lost

Created on 23 June 2023, over 1 year ago
Updated 30 January 2024, 10 months ago

Problem/Motivation

I recently updated from 8.x-1.5 to 8.x-1.11.
When I edit and save a node with multiple time slots in the same day the sorting of the timeslots is lost.
Editing and saving again sometimes restores the correct order - it seems a little bit random.

I checked my field table in the database and saw that the delta values for the same day had changed.

Steps to reproduce

  • Set up a node with an office_hours field
  • Edit the node, add multiple timeslots to the same day and save
  • Check delta values in the field table
  • Edit and save again.
  • Re-check delta values in the field table

Proposed resolution

I think the sorting is done in public static function sort(OfficeHoursItem $a, OfficeHoursItem $b) in src/Plugin/Field/FieldType/OfficeHoursItemBase.php.
The code there only compares $a->day and $b_day, returning 0 (i.e. "same") for all entries on the same day.
By this all differences in starthours and endhours are ignored.

I think we should compare starthours and endhours if the day is the same.

The function sort() was introduced in 🐛 Sort exception days from soonest to latest Fixed so I reference that issue.

Remaining tasks

Review patch.

User interface changes

Timeslots of the same day will be correctly sorted in display and form.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Fixed

Version

1.11

Component

Code

Created by

🇩🇪Germany gngn

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024