public static function OfficeHoursDatetime::isEmpty in Office Hours 8
Determines whether the data structure is empty.
Parameters
mixed $element: A string or array for time slot. Example from HTML5 input, without comments enabled.
array:3 [
"day" => "3"
"starthours" => array:1 [
"time" => "19:30"
]
"endhours" => array:1 [
"time" => ""
]
]
Return value
bool TRUE if the data structure is empty, FALSE otherwise.
4 calls to OfficeHoursDatetime::isEmpty()
- OfficeHoursDatetimeUnitTest::testDateTimeIsEmpty in tests/
src/ Unit/ OfficeHoursDatetimeUnitTest.php - Tests using entity fields of the datetime field type.
- OfficeHoursItem::isEmpty in src/
Plugin/ Field/ FieldType/ OfficeHoursItem.php - Determines whether the data structure is empty.
- OfficeHoursList::validateOfficeHoursSlot in src/
Element/ OfficeHoursList.php - Render API callback: Validates the element.
- OfficeHoursWidgetBase::massageFormValues in src/
Plugin/ Field/ FieldWidget/ OfficeHoursWidgetBase.php - Massages the form values into the format expected for field values.
File
- src/
Element/ OfficeHoursDatetime.php, line 173
Class
- OfficeHoursDatetime
- Provides a one-line HTML5 time element.
Namespace
Drupal\office_hours\ElementCode
public static function isEmpty($element) {
// Note: in Week-widget, day is <> '', in List-widget, day can be ''.
// And in Exception day, day can be ''.
// Note: test every change with Week/List widget and Select/HTML5 element!
if ($element === NULL) {
return TRUE;
}
if ($element === '') {
return TRUE;
}
if ($element === '-1') {
// Empty hours/minutes, but comment enabled.
return TRUE;
}
if (is_array($element)) {
if (isset($element['time'])) {
if ($element['time'] === '') {
return TRUE;
}
return FALSE;
}
if (!isset($element['day']) && !isset($element['time'])) {
return TRUE;
}
if ($element['day'] !== '' && strlen($element['day']) > 1) {
if (isset($element['day_delta']) && $element['day_delta'] == 0) {
// @todo Why is day_delta sometimes not set?
// First slot is never empty if an Exception date is set.
return FALSE;
}
if (isset($element['starthours']) && OfficeHoursDatetime::isEmpty($element['starthours']) && (isset($element['endhours']) && OfficeHoursDatetime::isEmpty($element['endhours'])) && (!isset($element['comment']) || empty($element['comment']))) {
return TRUE;
}
}
// Check normal weekday element.
if (isset($element['day']) && (int) $element['day'] < 7 && (isset($element['starthours']) && OfficeHoursDatetime::isEmpty($element['starthours'])) && (isset($element['endhours']) && OfficeHoursDatetime::isEmpty($element['endhours'])) && (!isset($element['comment']) || empty($element['comment']))) {
return TRUE;
}
// Check HTML5 datetime element.
if (isset($element['starthours']['time']) && OfficeHoursDatetime::isEmpty($element['starthours']['time']) && (isset($element['endhours']['time']) && OfficeHoursDatetime::isEmpty($element['endhours']['time'])) && (!isset($element['comment']) || empty($element['comment']))) {
return TRUE;
}
}
return FALSE;
}