Loading README.txt +2 −2 Original line number Diff line number Diff line Loading @@ -56,7 +56,7 @@ Only default (out-of-the-box) Views functionality is provided. == USING VIEWS - SORT CRITERIA == Only default (out-of-the-box) Views functionality is provided. - To sort the times per day, add the 'day' sort criterion. - To sort the time slots per day, add the 'day' sort criterion. == USING VIEWS - CREATE A BLOCK PER NODE/ENTITY == Loading Loading @@ -103,7 +103,7 @@ To import data with the Feeds module, the following columns can be used: The day should be stated in full English name, or a day number where Sunday=0, Monday=1, etc. The hours can be formatted as hh:mm or hh.mm I suppose Feeds Tamper can help to format the times and/or day to the proper format. I suppose Feeds Tamper can help to format the time slots and/or day to the proper format. Here is an example file: nid;weekday;Hours_1;Hours_2 Loading src/Element/OfficeHoursDatetime.php +2 −2 Original line number Diff line number Diff line Loading @@ -107,8 +107,6 @@ class OfficeHoursDatetime extends Datetime { /** * Returns the data from a widget. * * @deprecated Use OfficeHoursDateHelper::format(). * * @param mixed $element * A string or array for time. * @param string $format Loading @@ -116,6 +114,8 @@ class OfficeHoursDatetime extends Datetime { * * @return string * Return value. * * @deprecated in 8.x-1.5 and replaced by OfficeHoursDateHelper::format(). */ public static function get($element, $format = 'Hi') { return OfficeHoursDateHelper::format($element, $format); Loading src/Plugin/Field/FieldFormatter/OfficeHoursFormatterBase.php +12 −6 Original line number Diff line number Diff line Loading @@ -108,6 +108,7 @@ abstract class OfficeHoursFormatterBase extends FormatterBase { ], '#default_value' => $settings['day_format'], ]; // @todo D8 Align with DateTimeDatelistWidget. $element['time_format'] = [ '#type' => 'select', '#title' => $this->t('Time notation'), Loading Loading @@ -154,8 +155,7 @@ abstract class OfficeHoursFormatterBase extends FormatterBase { $element['separator'] = [ '#title' => $this->t('Separators'), '#type' => 'details', '#collapsible' => TRUE, '#collapsed' => TRUE, '#open' => FALSE, ]; $element['separator']['days'] = [ '#type' => 'textfield', Loading Loading @@ -192,8 +192,7 @@ abstract class OfficeHoursFormatterBase extends FormatterBase { $element['current_status'] = [ '#title' => $this->t('Current status'), '#type' => 'details', '#collapsible' => TRUE, '#collapsed' => TRUE, '#open' => FALSE, '#description' => $this->t('Below strings <a>can be translated</a> when the <a href=":install">Interface Translation module</a> is installed.', [ Loading Loading @@ -228,8 +227,7 @@ abstract class OfficeHoursFormatterBase extends FormatterBase { $element['schema'] = [ '#title' => $this->t('Schema.org openingHours support'), '#type' => 'details', '#collapsible' => TRUE, '#collapsed' => TRUE, '#open' => FALSE, ]; $element['schema']['enabled'] = [ '#title' => $this->t('Enable Schema.org openingHours support'), Loading Loading @@ -274,10 +272,14 @@ abstract class OfficeHoursFormatterBase extends FormatterBase { * Add an 'openingHours' formatter from https://schema.org/openingHours. * * @param \Drupal\office_hours\Plugin\Field\FieldType\OfficeHoursItemListInterface $items * The office hours. * @param $langcode * The required language code. * @param array $elements * Elements. * * @return array * A formatter element. */ protected function addSchemaFormatter(OfficeHoursItemListInterface $items, $langcode, array $elements) { if (empty($this->settings['schema']['enabled'])) { Loading @@ -297,10 +299,14 @@ abstract class OfficeHoursFormatterBase extends FormatterBase { * Add a 'status' formatter before or after the hours, if necessary. * * @param \Drupal\office_hours\Plugin\Field\FieldType\OfficeHoursItemListInterface $items * The office hours. * @param $langcode * The required language code. * @param array $elements * Elements. * * @return array * A formatter element. */ protected function addStatusFormatter(OfficeHoursItemListInterface $items, $langcode, array $elements) { Loading src/Plugin/Field/FieldType/OfficeHoursItem.php +14 −14 Original line number Diff line number Diff line Loading @@ -146,14 +146,14 @@ class OfficeHoursItem extends FieldItemBase { '#description' => $description, ]; // @todo D8 Align with DateTimeDatelistWidget. // @todo D8 Move to widget settings. Align with DateTimeDatelistWidget. $element['time_format'] = [ '#type' => 'select', '#title' => t('Time notation'), '#options' => [ 'G' => t('24 hour time @example', ['@example' => '(9:00)']), 'H' => t('24 hour time @example', ['@example' => '(09:00)']), 'g' => t('12 hour time @example', ['@example' => '09:00 am)']), 'g' => t('12 hour time @example', ['@example' => '9:00 am)']), 'h' => t('12 hour time @example', ['@example' => '(09:00 am)']), ], '#default_value' => $settings['time_format'], Loading Loading @@ -244,7 +244,7 @@ class OfficeHoursItem extends FieldItemBase { 'day' => mt_rand(0, 6), 'starthours' => mt_rand(00, 23) * 100, 'endhours' => mt_rand(00, 23) * 100, 'comment' => mt_rand(0, 1) ? 'additional text' : '' 'comment' => mt_rand(0, 1) ? 'additional text' : '', ]; return $value; } Loading Loading @@ -361,7 +361,7 @@ class OfficeHoursItem extends FieldItemBase { $day = $value['day']; if ($day !== '') { // When Form is displayed the first time, $day is an integer. // When 'Add exception' is pressed, $day is a string "yyyy-mm-dd", // When 'Add exception' is pressed, $day is a string "yyyy-mm-dd". $day = is_numeric($day) ? $day : strtotime($day); // Convert day number to integer to get '0' for Sunday, not 'false'. $day = (int) $day; Loading tests/src/Unit/OfficeHoursDatetimeUnitTest.php +1 −0 Original line number Diff line number Diff line Loading @@ -95,6 +95,7 @@ class OfficeHoursDatetimeUnitTest extends UnitTestCase { * Helper function for 'end time' formatting. * * @return array * A list of test cases. */ public function providerGetEndTimes() { return [ Loading Loading
README.txt +2 −2 Original line number Diff line number Diff line Loading @@ -56,7 +56,7 @@ Only default (out-of-the-box) Views functionality is provided. == USING VIEWS - SORT CRITERIA == Only default (out-of-the-box) Views functionality is provided. - To sort the times per day, add the 'day' sort criterion. - To sort the time slots per day, add the 'day' sort criterion. == USING VIEWS - CREATE A BLOCK PER NODE/ENTITY == Loading Loading @@ -103,7 +103,7 @@ To import data with the Feeds module, the following columns can be used: The day should be stated in full English name, or a day number where Sunday=0, Monday=1, etc. The hours can be formatted as hh:mm or hh.mm I suppose Feeds Tamper can help to format the times and/or day to the proper format. I suppose Feeds Tamper can help to format the time slots and/or day to the proper format. Here is an example file: nid;weekday;Hours_1;Hours_2 Loading
src/Element/OfficeHoursDatetime.php +2 −2 Original line number Diff line number Diff line Loading @@ -107,8 +107,6 @@ class OfficeHoursDatetime extends Datetime { /** * Returns the data from a widget. * * @deprecated Use OfficeHoursDateHelper::format(). * * @param mixed $element * A string or array for time. * @param string $format Loading @@ -116,6 +114,8 @@ class OfficeHoursDatetime extends Datetime { * * @return string * Return value. * * @deprecated in 8.x-1.5 and replaced by OfficeHoursDateHelper::format(). */ public static function get($element, $format = 'Hi') { return OfficeHoursDateHelper::format($element, $format); Loading
src/Plugin/Field/FieldFormatter/OfficeHoursFormatterBase.php +12 −6 Original line number Diff line number Diff line Loading @@ -108,6 +108,7 @@ abstract class OfficeHoursFormatterBase extends FormatterBase { ], '#default_value' => $settings['day_format'], ]; // @todo D8 Align with DateTimeDatelistWidget. $element['time_format'] = [ '#type' => 'select', '#title' => $this->t('Time notation'), Loading Loading @@ -154,8 +155,7 @@ abstract class OfficeHoursFormatterBase extends FormatterBase { $element['separator'] = [ '#title' => $this->t('Separators'), '#type' => 'details', '#collapsible' => TRUE, '#collapsed' => TRUE, '#open' => FALSE, ]; $element['separator']['days'] = [ '#type' => 'textfield', Loading Loading @@ -192,8 +192,7 @@ abstract class OfficeHoursFormatterBase extends FormatterBase { $element['current_status'] = [ '#title' => $this->t('Current status'), '#type' => 'details', '#collapsible' => TRUE, '#collapsed' => TRUE, '#open' => FALSE, '#description' => $this->t('Below strings <a>can be translated</a> when the <a href=":install">Interface Translation module</a> is installed.', [ Loading Loading @@ -228,8 +227,7 @@ abstract class OfficeHoursFormatterBase extends FormatterBase { $element['schema'] = [ '#title' => $this->t('Schema.org openingHours support'), '#type' => 'details', '#collapsible' => TRUE, '#collapsed' => TRUE, '#open' => FALSE, ]; $element['schema']['enabled'] = [ '#title' => $this->t('Enable Schema.org openingHours support'), Loading Loading @@ -274,10 +272,14 @@ abstract class OfficeHoursFormatterBase extends FormatterBase { * Add an 'openingHours' formatter from https://schema.org/openingHours. * * @param \Drupal\office_hours\Plugin\Field\FieldType\OfficeHoursItemListInterface $items * The office hours. * @param $langcode * The required language code. * @param array $elements * Elements. * * @return array * A formatter element. */ protected function addSchemaFormatter(OfficeHoursItemListInterface $items, $langcode, array $elements) { if (empty($this->settings['schema']['enabled'])) { Loading @@ -297,10 +299,14 @@ abstract class OfficeHoursFormatterBase extends FormatterBase { * Add a 'status' formatter before or after the hours, if necessary. * * @param \Drupal\office_hours\Plugin\Field\FieldType\OfficeHoursItemListInterface $items * The office hours. * @param $langcode * The required language code. * @param array $elements * Elements. * * @return array * A formatter element. */ protected function addStatusFormatter(OfficeHoursItemListInterface $items, $langcode, array $elements) { Loading
src/Plugin/Field/FieldType/OfficeHoursItem.php +14 −14 Original line number Diff line number Diff line Loading @@ -146,14 +146,14 @@ class OfficeHoursItem extends FieldItemBase { '#description' => $description, ]; // @todo D8 Align with DateTimeDatelistWidget. // @todo D8 Move to widget settings. Align with DateTimeDatelistWidget. $element['time_format'] = [ '#type' => 'select', '#title' => t('Time notation'), '#options' => [ 'G' => t('24 hour time @example', ['@example' => '(9:00)']), 'H' => t('24 hour time @example', ['@example' => '(09:00)']), 'g' => t('12 hour time @example', ['@example' => '09:00 am)']), 'g' => t('12 hour time @example', ['@example' => '9:00 am)']), 'h' => t('12 hour time @example', ['@example' => '(09:00 am)']), ], '#default_value' => $settings['time_format'], Loading Loading @@ -244,7 +244,7 @@ class OfficeHoursItem extends FieldItemBase { 'day' => mt_rand(0, 6), 'starthours' => mt_rand(00, 23) * 100, 'endhours' => mt_rand(00, 23) * 100, 'comment' => mt_rand(0, 1) ? 'additional text' : '' 'comment' => mt_rand(0, 1) ? 'additional text' : '', ]; return $value; } Loading Loading @@ -361,7 +361,7 @@ class OfficeHoursItem extends FieldItemBase { $day = $value['day']; if ($day !== '') { // When Form is displayed the first time, $day is an integer. // When 'Add exception' is pressed, $day is a string "yyyy-mm-dd", // When 'Add exception' is pressed, $day is a string "yyyy-mm-dd". $day = is_numeric($day) ? $day : strtotime($day); // Convert day number to integer to get '0' for Sunday, not 'false'. $day = (int) $day; Loading
tests/src/Unit/OfficeHoursDatetimeUnitTest.php +1 −0 Original line number Diff line number Diff line Loading @@ -95,6 +95,7 @@ class OfficeHoursDatetimeUnitTest extends UnitTestCase { * Helper function for 'end time' formatting. * * @return array * A list of test cases. */ public function providerGetEndTimes() { return [ Loading