Problem/Motivation

My site is giving the following error: Warning: Undefined array key "all_day_format" in Drupal\office_hours\Plugin\Field\FieldType\OfficeHoursItemList->formatTimeSlots() (line 511 of /modules/contrib/office_hours/src/OfficeHoursFormatterTrait.php)

Steps to reproduce

Go to a node that does not have all_day_format but does have the office hours enabled. Then you will see the following notice in the log when visiting the node.

Proposed resolution

Apply patch / merge the following code.

Remaining tasks

Make a merge request.

User interface changes

None

API changes

None

Data model changes

None

CommentFileSizeAuthor
added-office-hours-fix.patch642 bytesremco hoeneveld
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Remco Hoeneveld created an issue. See original summary.

rishabjasrotia made their first commit to this issue’s fork.

rishabjasrotia’s picture

Status: Active » Needs review
abhiyanshu’s picture

Status: Needs review » Reviewed & tested by the community

The attached patch is working fine, and I am no longer getting the warning of an undefined array.
Moving it to RTBC. Thanks!

johnv’s picture

Status: Reviewed & tested by the community » Needs work

Wow, this is an example of fast cooperation.
Alas, the suggested patch/MR only repairs the symptom.
Following a 'root cause analysis' approach, the function formatTimeSlots(array $office_hours, array $settings, array $field_settings) receives the $settings array, which should have passed the OfficeHoursFOrmatterBase::defaultSettings() function, that fills the required field.
The correct patch should ensure that this happens.

johnv’s picture

Oh, and line 511 is not relevant for this issue in the dev version.
I guess, OP uses 1.17 version, not dev version. Please state correct version, then test with current dev version. The error should not appear (at least, I cannot reproduce the error.)

remco hoeneveld’s picture

Aah check thanks for letting us know ill test with latest version, i was indeed working with 1.17 version.

johnv’s picture

Status: Needs work » Postponed (maintainer needs more info)
johnv’s picture

Version: 8.x-1.x-dev » 8.x-1.19

For the same problem, I opened and fixed #3475522: Warning: Undefined array key "all_day_format" in OfficeHoursItemList->formatTimeSlots() (line 531 of \OfficeHoursFormatterTrait.php), having forgotten the existence of this issue.
Please check the latest version (1.19 or dev) and close the issue if the problem is solved, or re-open if not.

rishabjasrotia’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)