Loading office_hours.api.php +26 −0 Original line number Diff line number Diff line Loading @@ -48,6 +48,32 @@ function hook_office_hours_current_time_alter(int &$time, EntityInterface $entit } } /** * Allows to alter the formatted time. * * This hook contains some re-formatting examples. Pick&Mix! * * @param string $formatted_time * A formatted time, e.g., '09:00-17:00'. */ function hook_office_hours_time_format_alter(string &$formatted_time) { // Remove separating space between time and ampm. $formatted_time = str_replace([' am',' pm'], ['am','pm'], $formatted_time); // Replace 'a.m.' by 'am'. $formatted_time = str_replace(['am','pm'], ['a.m.','p.m.'], $formatted_time); // Replace '9:00 am' by '9am'. (Separate lines to not destroy '16:00'.) $formatted_time = str_replace([':00 a'], [' a'], $formatted_time); $formatted_time = str_replace([':00 p'], [' p'], $formatted_time); // Convert 'Open all day'. // Translation can be managed on /admin/config/regional/translate. $formatted_time = str_replace(['12a.m.-12a.m.'], ['Around the clock'], $formatted_time); $formatted_time = str_replace(['00:00-24:00'], ['Around the clock'], $formatted_time); $formatted_time = str_replace(['Around the clock'], ['All day open'], $formatted_time); // Translate. Translations can be managed on /admin/config/regional/translate. $formatted_time = t($formatted_time); } /** * @} End of "addtogroup hooks". */ office_hours.module +7 −0 Original line number Diff line number Diff line Loading @@ -30,3 +30,10 @@ function office_hours_form_field_storage_config_edit_form_alter(&$form, FormStat + $form['cardinality_container']['cardinality']; } } /** * Implements hook_office_hours_time_format_alter(). */ //function office_hours_office_hours_time_format_alter(string &$formatted_time) { // // Only to test the alter hook in office_hours.api.php . //} src/OfficeHoursDateHelper.php +4 −1 Original line number Diff line number Diff line Loading @@ -200,7 +200,10 @@ class OfficeHoursDateHelper extends DateHelper { return ''; } return $start_time . $separator . $end_time; $formatted_time = $start_time . $separator . $end_time; \Drupal::moduleHandler()->alter('office_hours_time_format', $formatted_time); return $formatted_time; } /** Loading Loading
office_hours.api.php +26 −0 Original line number Diff line number Diff line Loading @@ -48,6 +48,32 @@ function hook_office_hours_current_time_alter(int &$time, EntityInterface $entit } } /** * Allows to alter the formatted time. * * This hook contains some re-formatting examples. Pick&Mix! * * @param string $formatted_time * A formatted time, e.g., '09:00-17:00'. */ function hook_office_hours_time_format_alter(string &$formatted_time) { // Remove separating space between time and ampm. $formatted_time = str_replace([' am',' pm'], ['am','pm'], $formatted_time); // Replace 'a.m.' by 'am'. $formatted_time = str_replace(['am','pm'], ['a.m.','p.m.'], $formatted_time); // Replace '9:00 am' by '9am'. (Separate lines to not destroy '16:00'.) $formatted_time = str_replace([':00 a'], [' a'], $formatted_time); $formatted_time = str_replace([':00 p'], [' p'], $formatted_time); // Convert 'Open all day'. // Translation can be managed on /admin/config/regional/translate. $formatted_time = str_replace(['12a.m.-12a.m.'], ['Around the clock'], $formatted_time); $formatted_time = str_replace(['00:00-24:00'], ['Around the clock'], $formatted_time); $formatted_time = str_replace(['Around the clock'], ['All day open'], $formatted_time); // Translate. Translations can be managed on /admin/config/regional/translate. $formatted_time = t($formatted_time); } /** * @} End of "addtogroup hooks". */
office_hours.module +7 −0 Original line number Diff line number Diff line Loading @@ -30,3 +30,10 @@ function office_hours_form_field_storage_config_edit_form_alter(&$form, FormStat + $form['cardinality_container']['cardinality']; } } /** * Implements hook_office_hours_time_format_alter(). */ //function office_hours_office_hours_time_format_alter(string &$formatted_time) { // // Only to test the alter hook in office_hours.api.php . //}
src/OfficeHoursDateHelper.php +4 −1 Original line number Diff line number Diff line Loading @@ -200,7 +200,10 @@ class OfficeHoursDateHelper extends DateHelper { return ''; } return $start_time . $separator . $end_time; $formatted_time = $start_time . $separator . $end_time; \Drupal::moduleHandler()->alter('office_hours_time_format', $formatted_time); return $formatted_time; } /** Loading