Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am trying to set office hours for a place that is closed for the summer. When I leave all the time fields blank nothing shows up when I publish the page. I have the "Show all days" selected under Managed Display. I would like to have the hours show "closed" instead of not publishing the hours at all.
What do I need to do to make this happen?
I have tried altering the "office_hours_field_is_empty" function in the .module file but it didn't seem to make any difference. Any help would be appreciated.
Comment | File | Size | Author |
---|---|---|---|
#4 | business_hours.png | 9.8 KB | johnv |
Comments
Comment #1
johnvI guess this is a valid feature request, given you have selected to show all days, even if they are closed.
However, for most entities, leaving all fields empty, just means that the entity has unknown, or no opening hours.
We'd need an extra option, I suppose, to distinguish etween the two.
For starters, you should change function office_hours_field_formatter_view(), and remove the first lines:
If you have something ready, please post your results!
Comment #2
mnshantz CreditAttribution: mnshantz commentedThat's great, thanks John!
Yes, I figured I would need to override the existing behaviour because in normal use cases that is what you would want.
Comment #3
johnvFor a definitive solution, we need a solution like here: #2044465: Add links 'clear' and 'apply to all' to Widget to improve usability
Comment #4
johnvLet's refocus this issue to adding a checkbox. See attached image.
Still need to figure out the exact usage. (what if: hours are filled and checkbox is set? Hours are empty and checkbox not set?)
Comment #5
smd_ksu CreditAttribution: smd_ksu commentedAgreed with checkbox application. Would allow you set a day to be closed without having to re-enter the time. Thinking of a school on spring break, they would set all the days as closed then reopen without having to setup each day over again.
Comment #6
johnvMoved as duplicate #2487460: Closed all week
Comment #7
johnvSee both linked issues for D7 and D8. It adds a 'comment' column to each time slot.
We can build upon that.
Comment #8
johnvComment #9
johnvlet's move this to the D8-version.
In the D8-version, we now have a hidden feature
'#empty' => t('This location has no opening hours.'),
in the formatters. We can add this to the settings page, and use it if necessary.Comment #10
johnvComment #11
johnvIssue #2860041: Cannot add comment when day is closed. is fixed.
You can now add a comment without a time.
Using the formatter setting "Group consecutive days with same hours into one set" , you can create 1 line for all week.
I guess the above change covers most of your needs.