Note: This Feature is now ready.
Your feedback is highly appreciated. For example, Do you want the regular weekdays to disappear, when a season hits in, or when any season is maintained?

Problem/Motivation

We need seasonal office hours for our databases of restaurants and tourist destinations.
It would contain the following fields:

fields description period office_hours
Regular hours Regular empty (?) for always mo-fr 09:00-17:00
Season Summer 2012 1-jul-2012/31-aug-2012 mo-fr 14:00-17:00
Exception 1 Eastern 2012 1-apr-2012 closed
Exception 2 Christmas 25-dec-20nn closed


Proposed resolutions and alternatives

  • 1. create a submodule of office_hours providing a field_collection comprised of several fields.
  • 2. create formatter for the provided field_collection that shows the office_hours corresponding to the matching season for today.
  • 3. See also the (install file of the) Measured Value Field module. This is a composite field using the composing field types.
  • 4. Version 8.x-1.8 of this modue will contain Seasons and Exceptions.
    Alternatives
  1. this can already be implemented using the Field collection module;
  2. add an 'office_fields_addendum' textfield to the entity, describing the exceptions. Show the field together with the office_hours field;
  3. #2862302: [Season] Add Recurrence Rule for Views (Full)Calendar integration (ISO-8601 or RRULE)

Examples:

  • Seasonal Opening hours
  • Seasonal Opening Hours 2
  • Seasonal Opening Hours 3

Remaining tasks

- Decide which implementation to use.
- Implement exceptions (Dates or periods that are excluded from the opening times, like holidays, X-mas).
Suppose two field_collections 'Regular' and 'Summer 2012'. You don't want to change Regular each time. During 'Summer 2012', how to suppress the 'Regular' times?
- Implement seasons;
- #2862302: [Season] Add Recurrence Rule for Views (Full)Calendar integration (ISO-8601 or RRULE)
- #3335549: Refactor 'Weekwidget with exceptions' as Widget of Widgets

User interface changes

n/a

n/a

Original report by ASMBL

I was wondering about options in the Field Settings that would allow for seasonal hours. This could be broadened to applicable period so as to not limit it, and account for a great variety of options. Something along the lines of:
- Are these hours applicable to a range of dates or period? y/n
- Single or multiple periods? (creates desired number of tables)
- Enter the applicable dates, and title of period(s) (ie Winter hours, Summer school, Spring Production, Fall Winter Programs):

These conditions could also be entered from the Add Content form to give client control. Something like:
- Expose these options during content creation? y/n

Comments

jonhattan’s picture

Component: User interface » Code

I think of a submodule of office_hours providing a field_collection comprised of a date field and an office_hours field.
A formatter for the provided field_collection would show the office_hours corresponding to the matching season for today.

antonín slejška’s picture

StatusFileSize
new16.9 KB

We need seasonal office hours for our databases of restaurants and tourist destinations (www.ceskesvycarsko.cz). It could look like:
Only local images are allowed.

gunwald’s picture

I agree to that, but maybe we could find a more general solution: We could use a date field (on the same node) to add dates or periods that are excluded from the opening times. I am thinking about holidays and so on. What do you think?

antonín slejška’s picture

StatusFileSize
new10 KB

I'm not sure if it would be enough user friendly even for non-technically educated editors :-)
Here is some example what we need to solve (and it can be even more complicated):
Opening hours Děčín
http://turistika.ceskesvycarsko.cz/en/locations/decin-chateau

johnv’s picture

@Antonín Slejška , a work-around might be to create a field_collection with Date field and office_hours field (like jonhattan proposes, but without separate submodule).

antonín slejška’s picture

Thank you John! It is absolutely simple and straightforward solution. I'm going to implement it.

antonín slejška’s picture

Thank you John! It is absolutely simple and straightforward solution. I'm going to implement it.

antonín slejška’s picture

I created a field_collection including an office_hours field. If I use the office_hours field separately, then it works exactly according to the configuration. See the picture:
Office hours separately
But when I use it in the field collection, then the "Add more hours" link is not displayed and the selected granularity of time is ignored. See the picture:
Office hours in field collection

If I use the separate field in the same form as the field collection, then both fields are displayed correctly. It was tested on two Drupal 7 sites with the same results.

johnv’s picture

@Antonín Slejška, please search/open another issue for problems with field_collection. So we can use this issue for the original request.
If you use the dev-version, field_collection must work. See #1689296-12: Add more hours link won't work with Field collection module
I tested just now, and there is some widget problem, but works correctly.

johnv’s picture

Title: Seasonal Hours / Duration » Add "Seasonal Hours / Duration" feature

Updated issue summary.
More clarifying title.

johnv’s picture

Issue summary: View changes

Updated Issue summary.

johnv’s picture

Issue summary: View changes

Add table layout

johnv’s picture

Issue summary: View changes

update table layout

johnv’s picture

Issue summary: View changes

described new alternative with textfield.

alan d.’s picture

StatusFileSize
new30.95 KB
new41.49 KB

The above approach didn't work for me, and I manually handled this. But it would be great to be passing in some more context to the theme_office_hours_field_formatter_default() so hackers like myself can implement our own solutions:

includes/office_hours.formatter.inc

  $element[] = array(
    '#markup' => theme(
      'office_hours_field_formatter_default',
      array(
        'element'  => $items,
        'display'  => $display,
        'days'     => $days,
        'settings' => $settings,
        'daynames' => $daynames,
        'open'     => $open,
        'timezone' => $timezone,
+        'entity_type' => $entity_type,
+        'entity' => $entity,
+        'instance' => $instance,
      )
    ),
  );

Or if you are feeling generous, in office_hours_field_formatter_view():

  // Allow other modules to alter the days before the calculations are done. 
  drupal_alter('office_hours_field_formatter_view', $items , array(
    'entity_type' => $entity_type,
    'entity' => $entity,
    'field' => $field,
    'instance' =>$instance,
    'langcode' => $langcode,
    'display' => $display,
  ));

  // Initialize formatter settings.
  $settings = _office_hours_field_formatter_defaults($display['settings']);

It still was fairly painful to implement what I wanted, I used a simple textarea to store the public holidays (no Field Collection on this site) and way too much custom coding / time wasted...

I couldn't seem to hook into the field prior to the processing, so I created a custom formatter to decorate this modules formatter, i.e. only custom code was via hook_field_formatter_view();

  if ($entity_type == 'bean' && $entity->type == 'office_hours') {
    module_load_include('inc', 'acorncustom', 'includes/office_hours');
    _acorncustom_field_attach_bean_office_hours_view_alter($entity);
    $items = field_items($entity_type, $entity, $field['field_name']);
  }
  return office_hours_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display);

Then overrode the theming function with the above hack to provide the context to control the final output.

FYI, a couple of screenshots are attached of the final result before theming.

The last bits are node nid's to link to a view page if they are being displayed there. (i.e. date(s)|label|nid)

marcoka’s picture

alan d.’s picture

lol, duh. The usage stats pushed me here :(

Oh well, it was an interesting side project for the weekend, and it is working nicely with a relatively simply UI to add upcoming dates easily, or I should say, quickly. One hack (#2508755: Provide more context to the theming function.) and one custom formatter which would be redundant with #2508753: Add drupal_alter() to allow users to update the items before viewing.

johnv’s picture

FWIW, the drupal_alter() from #11 is now implemented in dev-version or the next 1.5 version.

johnv’s picture

Component: Code » Code - widget
johnv’s picture

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

Pushing to D8.
ITMT, both D7 and D8 versions have a 'comment' field on each time slot. That might suffice for some use cases.

zenimagine’s picture

Why not add paragraph to the module? Would not it be easier ?

https://www.drupal.org/project/paragraphs

and

https://www.drupal.org/project/calendar

johnv’s picture

Please elaborate.

zenimagine’s picture

The "Field collection" module has not received an update for a long time and it is written on the module page that it will be obsolete and replaced by "Paragraph".

http://drupal.org/project/field_collection

zenimagine’s picture

Hello, is this functionality planned for the next version? Thank you

johnv’s picture

Hi I have no active plans for this feature. I need a good architecture, first. Perhaps the D9-version would be a good start, when we can change the data model using proper times, instead of 4-character strings to store the times.

johnv’s picture

Title: Add "Seasonal Hours / Duration" feature » Add "Seasonal Hours / Duration" feature (aka Exception)
johnv’s picture

Issue tags: +exception
johnv’s picture

Title: Add "Seasonal Hours / Duration" feature (aka Exception) » Add "Seasonal Hours / Duration" feature
zenimagine’s picture

StatusFileSize
new122.93 KB

It would be to enter the responsive schedules on the Olivero theme, which is now the default theme of Drupal 9

johnv’s picture

johnv’s picture

Title: Add "Seasonal Hours / Duration" feature » [Season Meta] Add "Seasonal Hours / Duration" feature
johnv’s picture

Priority: Normal » Major
johnv’s picture

Issue summary: View changes
johnv’s picture

Issue summary: View changes

To all followers,
I have created some new issues, in order to capture your feedback:
#3336378: [Season] Add season widgets, which contains a proof of concept.
#3336385: [Season] Add Seasonal formatter, which is completely blank.

Your feedback is highly appreciated.

johnv’s picture

Issue summary: View changes
johnv’s picture

Issue tags: +seasonal

As per #3336378: [Season] Add season widgets, the extended widget is now extended with Seasons, which can be activated using a field setting.

It is not ready for production sites, yet. If you are able to contribute that is appreciated. There is no need to only mention the omissions.

Also, the formatter needs to be adjusted. For that, more code maintenance must be done in #3340671: [Season] Formatter: Make better use of Item and ItemList.

johnv’s picture

Issue summary: View changes
johnv’s picture

Version: 8.x-1.x-dev » 8.x-1.7
Issue summary: View changes
Status: Active » Fixed

Status: Fixed » Closed (fixed)

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