3

I need an open hours widget that outputs something like:

  • Mon 8:00am to 5:00pm
  • Tue 8:00am to 5:00pm
  • Wen 8:00am to 5:00pm
  • Thu 8:00am to 5:00pm
  • Fri 8:00am to 5:00pm
  • Sat 11:00am to 3:pm
  • Sun Closed

I think the best way to do this is create a three column field table with day of week, open and close columns. Then create a field widget form with three drop down boxes and a formatter that puts it all together.

Has somebody already done this in Drupal 7? If not, does anybody have any ideas on how to do this best?

4 Answers 4

3

I would check out the Office Hours module. It has a dev version for D7, you can either help finish the port, or at the least pick up some ideas on how to best accomplish this.

1
  • 2
    Unfortunately, the Office Hours module is super buggy in Drupal 7.
    – Adam S
    Commented May 3, 2011 at 18:39
3

I used Tablefield for this. Haven't seen the Office Hours module, will have to give it a spin. Tablefield is a bit more generic, but it's relatively stable (not sure if Office Hours is stable yet)

3

I couldn't get the Office Hours module to work in Drupal 7. I just went ahead and used the Field API to create a simple module that does what I need without a lot of overhead. If you're curious, I committed it to GitHub at adam-s/hours. I'll probably add more validation and jQuery to make it more user friendly as time goes on.

1
  • 2
    This looks really good, you should contact the maintainer of Office Hours to collaborate! Commented May 6, 2011 at 21:47
1

I would suggest the timefield module used together with the built-in 'add more' / 'add extra' fields functionality of data entry for Drupal fields in content types.

Download, install and enable the timefield module.

Add a field of type timefield to your content type.

Then configure to allow the user to add one or more fields of this type by going here on your site: admin/structure/types/manage/YOUR CONTENT TYPE/fields/field_times - here there is an option where you can specify unlimited - which means no limit to the range of times you can add.

Where YOUR CONTENT TYPE is the name of your content type that you should insert here.

Then as an ordinary user, when you go to enter times when creating new content/editing existing content, you can add extra timefield fields for each different range of times. Another nice thing about time field is that it can be configured to provide checkboxes for each day where the opening times are the same - to save you having to enter in the same time for each day. See example here:

adding multiple time ranges

In the manage display for your content type, admin/structure/types/manage/YOUR CONTENT TYPE/display I recommend you choose the List of times Format setting for your timefield field as the other options, Duration and Calendar work but are not as readable in my opinion for displaying opening times, but experiment as you desire! If you do use List of times for your display you will find that this nicely (well in my opinion) lays out days where the opening hours are the same. See example here:

listed times

I also looked at opening_hours and the 2 problems I had with this were: 1) no documentation and 2) the functionality for entering the times appears to be deliberately in a separate place from the other fields of the content type - not intuitive for some users perhaps. The functionality available through one of the tabs. I also looked at office_hours and found this simply did not work (at time of writing) if hours for more than one day were entered - issue raised: https://drupal.org/node/2043237

Just an interest item, optional, only for your information: For even more advanced opening times that depend on certain times of the year, one might also be interested in the availability_calendars and seeing how these could be made to interoperate for schedules that have irregularities (e.g. closed all of August, or closed on public holidays etc). I haven't tried anything with this availability_calendars module yet but just thought I'd mention it, it's not necessary at all for to solve the question asker's problem here nor for other folks here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.