Loading src/Element/OfficeHoursList.php +2 −2 Original line number Diff line number Diff line Loading @@ -98,7 +98,7 @@ class OfficeHoursList extends FormElement { } /** * Process an individual element. * Render API callback: Builds one OH-slot element. * * Build the form element. When creating a form using Form API #process, * note that $element['#value'] is already set. Loading Loading @@ -162,7 +162,7 @@ class OfficeHoursList extends FormElement { } /** * Render API callback: Validates the element. * Render API callback: Validates one OH-slot element. * * Implements a callback for _office_hours_elements(). * Loading src/OfficeHoursDateHelper.php +4 −5 Original line number Diff line number Diff line Loading @@ -89,22 +89,21 @@ class OfficeHoursDateHelper extends DateHelper { * @see https://www.php.net/manual/en/datetime.formats.time.php * * @param string $time * Time, in 24hr format '0800', '800', '08:00' or '8:00'. * Time, in 24hr format '0800', '800', '08:00', '8:00' or empty. * @param string $time_format * The requested time format. * @param bool $end_time * TRUE if the time is an End time of a time slot. * * @return string * The formatted time. * The formatted time, e.g., '08:00'. */ public static function format($time, $time_format, $end_time = FALSE) { // Convert '800' or '0800' to '08:00'. if (!mb_strlen($time)) { return NULL; } // Empty time field. (negative value) if (strstr($time, '-')) { // Empty time field (negative value). if ($time == -1) { return NULL; } Loading src/Plugin/Field/FieldWidget/OfficeHoursWidgetBase.php +17 −11 Original line number Diff line number Diff line Loading @@ -33,6 +33,10 @@ abstract class OfficeHoursWidgetBase extends WidgetBase { return $element; } public function extractFormValues(FieldItemListInterface $items, array $form, FormStateInterface $form_state) { parent::extractFormValues($items, $form, $form_state); } /** * {@inheritdoc} */ Loading @@ -50,19 +54,21 @@ abstract class OfficeHoursWidgetBase extends WidgetBase { // Get hours. Result can be NULL, '', 0000, or a proper time. $start = OfficeHoursDatetime::get($item['starthours'], 'Hi'); $end = OfficeHoursDatetime::get($item['endhours'], 'Hi'); // Cast the time to integer, to avoid core's error // "This value should be of the correct primitive type." // This is needed for e.g., 0000 and 0030. $item['starthours'] = isset($start) ? (int) $start : -1; $item['endhours'] = isset($end) ? (int) $end : -1; if ($item['comment']) { // Allow Empty time field with comment (#2070145). // In principle, this is prohibited by the database: value '' is not // allowed. The format is int(11). // Would changing the format to 'string' help? // Perhaps, but using '-1' (saved as '-001') works, too. if (!empty($item['comment'])) { $item['starthours'] = empty($start) ? -1 : $item['starthours']; $item['endhours'] = empty($end) ? -1 : $item['endhours']; $item['starthours'] = !empty($start) ? (int) $start : -1; $item['endhours'] = !empty($end) ? (int) $end : -1; } else { $item['starthours'] = isset($start) ? (int) $start : -1; $item['endhours'] = isset($end) ? (int) $end : -1; } } return $values; Loading src/Plugin/migrate/process/CSVOfficeHoursField.php +2 −2 Original line number Diff line number Diff line Loading @@ -128,13 +128,13 @@ class CSVOfficeHoursField extends OfficeHoursField { // Process Comment. else { $comment_key = ($i - 1) / 2; $item = &$office_hours[$comment_key]; $item = &$office_hours[(int) $comment_key]; $item['comment'] = trim($value[$i]); // Override empty values because it is not well handled if there // is a comment associated with a day. But if there is no comment // it has to be empty. if (!empty($item['comment'])) { if ($item['comment']) { $item['starthours'] = empty($item['starthours']) ? -1 : $item['starthours']; $item['endhours'] = empty($item['endhours']) ? -1 : $item['endhours']; } Loading Loading
src/Element/OfficeHoursList.php +2 −2 Original line number Diff line number Diff line Loading @@ -98,7 +98,7 @@ class OfficeHoursList extends FormElement { } /** * Process an individual element. * Render API callback: Builds one OH-slot element. * * Build the form element. When creating a form using Form API #process, * note that $element['#value'] is already set. Loading Loading @@ -162,7 +162,7 @@ class OfficeHoursList extends FormElement { } /** * Render API callback: Validates the element. * Render API callback: Validates one OH-slot element. * * Implements a callback for _office_hours_elements(). * Loading
src/OfficeHoursDateHelper.php +4 −5 Original line number Diff line number Diff line Loading @@ -89,22 +89,21 @@ class OfficeHoursDateHelper extends DateHelper { * @see https://www.php.net/manual/en/datetime.formats.time.php * * @param string $time * Time, in 24hr format '0800', '800', '08:00' or '8:00'. * Time, in 24hr format '0800', '800', '08:00', '8:00' or empty. * @param string $time_format * The requested time format. * @param bool $end_time * TRUE if the time is an End time of a time slot. * * @return string * The formatted time. * The formatted time, e.g., '08:00'. */ public static function format($time, $time_format, $end_time = FALSE) { // Convert '800' or '0800' to '08:00'. if (!mb_strlen($time)) { return NULL; } // Empty time field. (negative value) if (strstr($time, '-')) { // Empty time field (negative value). if ($time == -1) { return NULL; } Loading
src/Plugin/Field/FieldWidget/OfficeHoursWidgetBase.php +17 −11 Original line number Diff line number Diff line Loading @@ -33,6 +33,10 @@ abstract class OfficeHoursWidgetBase extends WidgetBase { return $element; } public function extractFormValues(FieldItemListInterface $items, array $form, FormStateInterface $form_state) { parent::extractFormValues($items, $form, $form_state); } /** * {@inheritdoc} */ Loading @@ -50,19 +54,21 @@ abstract class OfficeHoursWidgetBase extends WidgetBase { // Get hours. Result can be NULL, '', 0000, or a proper time. $start = OfficeHoursDatetime::get($item['starthours'], 'Hi'); $end = OfficeHoursDatetime::get($item['endhours'], 'Hi'); // Cast the time to integer, to avoid core's error // "This value should be of the correct primitive type." // This is needed for e.g., 0000 and 0030. $item['starthours'] = isset($start) ? (int) $start : -1; $item['endhours'] = isset($end) ? (int) $end : -1; if ($item['comment']) { // Allow Empty time field with comment (#2070145). // In principle, this is prohibited by the database: value '' is not // allowed. The format is int(11). // Would changing the format to 'string' help? // Perhaps, but using '-1' (saved as '-001') works, too. if (!empty($item['comment'])) { $item['starthours'] = empty($start) ? -1 : $item['starthours']; $item['endhours'] = empty($end) ? -1 : $item['endhours']; $item['starthours'] = !empty($start) ? (int) $start : -1; $item['endhours'] = !empty($end) ? (int) $end : -1; } else { $item['starthours'] = isset($start) ? (int) $start : -1; $item['endhours'] = isset($end) ? (int) $end : -1; } } return $values; Loading
src/Plugin/migrate/process/CSVOfficeHoursField.php +2 −2 Original line number Diff line number Diff line Loading @@ -128,13 +128,13 @@ class CSVOfficeHoursField extends OfficeHoursField { // Process Comment. else { $comment_key = ($i - 1) / 2; $item = &$office_hours[$comment_key]; $item = &$office_hours[(int) $comment_key]; $item['comment'] = trim($value[$i]); // Override empty values because it is not well handled if there // is a comment associated with a day. But if there is no comment // it has to be empty. if (!empty($item['comment'])) { if ($item['comment']) { $item['starthours'] = empty($item['starthours']) ? -1 : $item['starthours']; $item['endhours'] = empty($item['endhours']) ? -1 : $item['endhours']; } Loading