You are here

public static function OfficeHoursItem::validateOfficeHoursSettings in Office Hours 8

Implements the #element_validate callback for storageSettingsForm().

Verifies the office hours limits. "Please note that this will work as long as the opening hours are not through midnight." "You may leave 'until' time empty. Use '00:00' for closing at midnight."

Parameters

array $element:

\Drupal\Core\Form\FormStateInterface $form_state:

File

src/Plugin/Field/FieldType/OfficeHoursItem.php, line 274

Class

OfficeHoursItem
Plugin implementation of the 'office_hours' field type.

Namespace

Drupal\office_hours\Plugin\Field\FieldType

Code

public static function validateOfficeHoursSettings(array $element, FormStateInterface &$form_state) {
  if (!empty($element['limit_end']['#value']) && $element['limit_end']['#value'] < $element['limit_start']['#value']) {
    $form_state
      ->setError($element['limit_start'], t('%start is later then %end.', [
      '%start' => $element['limit_start']['#title'],
      '%end' => $element['limit_end']['#title'],
    ]));
  }
}