Closed (fixed)
Project:
Office Hours
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
25 May 2011 at 07:47 UTC
Updated:
27 Mar 2013 at 10:24 UTC
Jump to comment: Most recent file
Comments
Comment #1
Jerome F commentedAn other solution for improvement in the process of filling in the office hours field could be http://drupal.org/node/1168172
Comment #2
johnvSome clarification: The default value which now appears on the field settings is provided by core and only supplies 1 value.
ATM Office Hours does supply default values, and has a strange thing here: we do not need 1 default value, but 7...
Comment #3
jonhattanTraced it down to field_ui.admin.inc:
I'm looking for a related issue in core. For a field like office_hours that manage multiple values as single, default values with multiple values just works. It's easy to test by removing last argument in the above function call.
Comment #4
johnvPerhaps we can override it with a hook_form_FORM_ID_alter() ?
Comment #5
jonhattanNo, since this is a direct call to _form a function, instead of via drupal_get_form().
The way to fix this is to provide a week widget instead of the hacky way the module provides the widget at present.
Comment #6
jonhattanFind attached a patch to convert the widget to a multivalued one.
Comment #7
jonhattanMinor fix to previous patch.
Comment #8
jonhattan$field['cardinality']is not set when first creating the field, and the widget is unable to build itself correctly. Hardcoded to 14.Comment #9
jonhattanIt doesn't play with monday as first day of week.
Comment #10
jonhattanAnother round. Now the widget is almost agnostic about the underlying implementation (0,1=sunday, 2,3=monday, etc).
In summary these are the changes proposed to convert the widget to a multivalued one:
1. Change the widget definition from
'multiple values' => FIELD_BEHAVIOR_DEFAULTto'multiple values' => FIELD_BEHAVIOR_CUSTOMso we are telling to Drupal that we handle the field when it's multivalued (always). So that Drupal will call ourhook_field_widget_form()implementation only once and not 14 times.2. due to previous point, our widget is no longer based on field_multiple_value_form(). To not reinvent the wheel, lets base our implementation on the relevant code from this function. I just copied and adapted some relevant lines into office_hours_field_widget_form().
3. Working with $items indexed by 14 keys for 7 days and 2 slots per day is a PITA, moreover, days needs a shift based in first day of week. There were a lot of spaghetti in the code relaying on #delta or #weight.
I got rid of all of this and introduced
dayanddaydelta. Day is a 0..6 value and daydelta 0..1, as present limitation to 14 values. Backend doesn't change for now. It could change in concordance to support a standard day number and more than 2 slots per day.Since backend is unaltered, we need to convert values after loading and before saving. For loading I introduced a new function:
office_hours_arrange_field_items()and a new data structure: a two level array based in day and day delta. See code for details. In a follow up issue I'll try to addapt the formatter to this new internal representation.OTOH, implemented
hook_field_presave()to addapt values to backend before saving.4. Last, theming. Instead of a hacky override of
theme_field_multiple_value_form()declared our owntheme_office_hours_week(). This is a very stripped down version oftheme_field_multiple_value_form()that transforms elements to table rows with no need for reordering.Comment #11
johnvFinally got time to test this promising patch, after reviewing your other patches.
However, too much has changed. Pleas provide a patch against latest version.
Comment #12
johnvThanks jonhattan. This is a very valuable patch.
It is committed in commit 9218429.
Comment #14
ubun2junky commentedJust wondering if there is any way to implement into this module a way you can also enter specific dates that would be an exception to regular hours. For example holidays. So I could have monday to friday open 9am to 5pm, but on july 4th that lands of a wednesday it would display closed instead of open from 9am to 5pm.
Comment #15
johnv@ubun2Junky, please do not hi-jack this issue.
Please search for open issues first, and if you cannot find one, open another.
Options:
#1743366: [Season Meta] Add "Seasonal Hours / Duration" feature
#1119406: Add a "description" feature
You can also add a textfield in your entity with the exceptions, and add it below the Office Hours.