Hi Guys,

I refactored the display formatter and its settings. This should take care of all the uninitialized settings problems as well. Aside from removing the hard-coded CSS styling (bad form to include inline styling in the code), it should act exactly the same as what's currently in 7.x-1.x-dev

I've also added 2 features in my local copy. The first displays the current status (open/closed, displays text before or after and adds a CSS class to the currently active day(s)) and accounts for closing times past midnight. The second is using a tzfield to set the local timezone of the times (which is used in calculating the current status). Let me know if you want the patches for those as well.

Laz

Comments

Lazarus-Long’s picture

And a little bit of theming for good luck

dflitner’s picture

I would like that first feature you describe, especially adding a CSS class to the currently active day. Will try to test these patches and see how they work.

Lazarus-Long’s picture

StatusFileSize
new17.56 KB

Here's the patch from the current commit (d93cac3) for the status feature. It relies on the refactored display formatter, so that's included as well.

Ozeuss’s picture

I thought i commented on this issue and gave a patch...
0001 has been committed, cool!
0002- doesn't consider time format (ampm) display setting - we have this both on the widget and on the formatter level (for some reason...). Could you please add and reroll? thanks.

About the other 2 patches - Could you please add separate issues for these? that way it would be much easier for others to follow and review. Thanks!

Lazarus-Long’s picture

StatusFileSize
new13.61 KB

Hi Ozeuss,

Here's a rollup of the display formatter changes from the current 7.x-1.x head. Should also show AM/PM for 12 hour times now.

Lazarus-Long’s picture

StatusFileSize
new13.97 KB

Typo'd the hoursformat setting in the last patch. Ignore it

johnv’s picture

Status: Needs review » Needs work
StatusFileSize
new63.61 KB

Nice patch! shorter, cleaner code.
I couldn't apply the patch with git. Perhaps some problem with -p0 -p1 parameter?
Some things are broken:

 .oh-display-label {
   display: inline-block; /* give each label the same width, to align the hours. */
+  min-width: 11em;
 }

- The day-label-width is moved to css, which is a good thing. But in code an educated guess was made about the width, using $max_label_length. Your patch adds a fixed widht, which generates worse result for short lables. See attached printscreen.
- When one or more day have 'more hours', every day has a is empty 'more hours' displayed. See attached printscreen, left and right column, lower row. With compressed display, output is OK.

+function theme_office_hours_time_range($vars = array()) {
+  $vars += array(
+    'times' => array(
+      'start' => '',
+      'end' => '',
+    ),
+    'format' => 'G:i',
+    'separator' => ' - ',    "<-- new separator??
+  );

- Although the output seems OK, in above function, a new separator is defined. This is confusing. Can't you pass $settings['separator_hours_hours'] ?

- In the third line of the printscreen, the store has 7 open days. However, in column "Hours -grouped, compressed"only 5 are shown. Sat+Sun are not shown. (First-day-of-week was set to Monday).

+.oh-display-grouped  .oh-display-label{
+  min-width: 11em;

- This part comes from your other feature. I think t is missing from this one.

Lazarus-Long’s picture

The fixed label length was meant to be fixed with CSS classes. The default min-width should be 6em and the grouped min-width should be 11em.

The missing more-hours I'll take a look at later tonight.

The separator in theme_office_hours_time_range() is a default to fill in any missing values. $settings['separator_hours_hours'] is passed from theme_office_hours_formatter_default().

Missing days I'll look into.

Not sure what you mean by missing t? Something is not translated?

johnv’s picture

I meant : "I think it (+.oh-display-grouped .oh-display-label) is missing from this patch."

Lazarus-Long’s picture

Derp moment.

Yes, it is missing. I'll roll a new patch a little later.

johnv’s picture

StatusFileSize
new21.75 KB
new63.84 KB

When one or more day have 'more hours', every day has a is empty 'more hours' displayed

This is already happening in current -dev.
There is an error when entering the value 00 vs. ' ' in the widget/node. See attach screendumps.
Perhaps you can find the cause.

Lazarus-Long’s picture

I think I've tracked this down. I wasn't able to re-create the effect from just the 00 values, but I believe it had to do with 00:00 - 00:00 meaning "open all day" rather than "closed". Shouldn't matter if the times were the first or second set of times.

Second part was just the label.

$info['endday'] ? true : false; rather than $info['endday'] !== null ? true : false;.

Let me know how this goes.

Lazarus-Long’s picture

Status: Needs work » Needs review
johnv’s picture

See my patch attached.

- I've kept the programmed css-width.I've opened #1614206: How to set the label width correctly?, which you've already read.
- Check _office_hours_field_formatter_defaults(), for the use of array_merge() vs. drupal_array_merge_deep() vs. +
- I've ran the code through Coder, and removed most messages. Drupal doesn't like camelCase.

johnv’s picture

StatusFileSize
new16.46 KB

Here's the patch.

Lazarus-Long’s picture

StatusFileSize
new10.3 KB

Nice. I've made one more change. Both theme_ functions are in the theme.inc file now, and the formatter_view() function is in the .module. This way we can remove the module_load_include() for the theme file (and it will only be loaded by the theme system when needed).

Also, I noticed you removed the array_merge() from the default settings function. It won't matter for this feature, but when we start using sub-arrays in the settings (such as my status feature), it will need to use drupal_array_merge_deep instead. I haven't made any changes to it in this patch though.

Here's the patch, created after applying your patch in #15.

johnv’s picture

OK, we can put back drupal_array_merge_deep() if/when it has a function;
Shouldn't we move most of office_hours_field_formatter_view() to the theme-function, hence out of the module-file? This makes the .module file lighter.

Lazarus-Long’s picture

It may make the .module file lighter, but because the hook_field_formatter_view() is in the .theme.inc file, it has to be included when the .module file is loaded. This makes the .module effectively as large as both files combined, and includes one more file load at times that it may not actually be required (ie: loading editing pages)

johnv’s picture

I understand, that's why i meant move most of office_hours_field_formatter_view(), leaving plm. 15 lines in.

Lazarus-Long’s picture

The theme_ function should only be responsible for taking the data and displaying it, not for processing any of the information. Anything in that function has to be reimplemented by themers when they want to override the default theme/style.

The size of the .module file is already fairly small. I wouldn't worry too much about its size.

johnv’s picture

OK.

johnv’s picture

Status: Needs review » Fixed

OK, this is committed, see 25e93f0.

Lazarus-Long’s picture

Sweet. First attributed commit. Thanks mate.

johnv’s picture

Status: Fixed » Needs work

Something is wrong.

On existing installations the widget is fine.
But on a fresh installation (or disable, enable the module) only 1 line of hours is shown.

Try this:
- (re-enable) the module.
- add a OH field
- add/change a node --> only 1 line of hours is shown, without the table-formatting
- now copy version 1.0 of the module in the modules/office_hours/directory.
- refresh all caches on the page (add/change a node), now the widget looks fine.

johnv’s picture

Status: Needs work » Closed (fixed)