Note, this is a clone of a previous issue - the problem I am having is the exact same as closed issue #3401667.

Problem/Motivation

Adding multiple Office Hours fields both configured with the "Exceptions" functionality doesn't work.
It seems like this might be a known issue in code, but I didn't find any reported issue in the issue queue.

Notice the @todo comment on line 23 here:
https://git.drupalcode.org/project/office_hours/-/blob/8.x-1.x/src/Plugi...

Steps to reproduce

  1. Add and configure an "Office Hours" field on a Content Type. Enable the "Exceptions" feature (field settings + widget)
  2. Add another "Office Hours" field on the same Content Type, also enabling the same settings as above.
  3. Populate both fields as needed
  4. Click "Add exception" in one of the widgets
  5. Notice that the exception row is added to the incorrect field. Interacting with the "Add exception" button on either field has sporadic results

Proposed resolution

The widget interactions should be tied to the field instance, not just "the first office hours field in the form".

Remaining tasks

Narrow-down the issue and come up with a route to fix it.

Comments

mikaylaflanagan created an issue. See original summary.

mikaylaflanagan’s picture

Issue summary: View changes
johnv’s picture

Indeed, I see many more problems:
- no problem with the 'Add exception' buttons
- both fields have the same title
- when first adding an exception one second field, then save, then add exception on other field, the value of first field is prefilled.

  • johnv committed 61c2ea1c on 8.x-1.x
    Issue #3519361: Multiple Office Hours fields on same Content Type breaks...
johnv’s picture

Status: Active » Fixed

The above commit should solve the problem.
Please test and report back. Then I will release a new version.

mikaylaflanagan’s picture

Hey - thanks for the reply!
Just tested this, getting WSOD and the following error in logs when trying to edit a node that has the office hour field.

'Error: Cannot access protected property Drupal\field\Entity\FieldConfig::$id in Drupal\office_hours\Plugin\Field\FieldType\OfficeHoursItemList->getPlugin() (line 276 of /modules/contrib/office_hours/src/Plugin/Field/FieldType/OfficeHoursItemList.php).'

Maybe helpful context:
Drupal Core: 10.4.5
PHP: 8.2

EDIT/UPDATE
I manually changed
$id = $field_definition->id;
to
$id = $field_definition->id();
on line 276 of Plugin/Field/FieldType/OfficeHoursItemList.php and things are working for me now on my test.

johnv’s picture

Oh, I am working on 8.3 I think I must go back to 8.2, because I get more such problems reported.

  • johnv committed 3fc212c0 on 8.x-1.x
    Issue #3519361 by mikaylaflanagan: Multiple Office Hours fields on same...
johnv’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.