You are here

public function DateTimeDayFieldItemList::defaultValuesFormValidate in Date time day 8

Validates the submitted default value.

Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow administrators to configure instance-level default value.

Parameters

array $element: The default value form element.

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The form state of the (entire) configuration form.

Overrides DateTimeFieldItemList::defaultValuesFormValidate

File

src/Plugin/Field/FieldType/DateTimeDayFieldItemList.php, line 82

Class

DateTimeDayFieldItemList
Represents a configurable entity datetimeday field.

Namespace

Drupal\date_time_day\Plugin\Field\FieldType

Code

public function defaultValuesFormValidate(array $element, array &$form, FormStateInterface $form_state) {
  if ($form_state
    ->getValue([
    'default_value_input',
    'default_date_type',
  ]) == static::DEFAULT_VALUE_CUSTOM) {
    $is_strtotime = @strtotime($form_state
      ->getValue([
      'default_value_input',
      'default_date',
    ]));
    if (!$is_strtotime) {
      $form_state
        ->setErrorByName('default_value_input][default_date', $this
        ->t('The relative default date value entered is invalid.'));
    }
  }
  if ($form_state
    ->getValue([
    'default_value_input',
    'default_start_time_type',
  ]) == static::DEFAULT_VALUE_CUSTOM) {
    $is_strtotime = @strtotime($form_state
      ->getValue([
      'default_value_input',
      'default_start_time',
    ]));
    if (!$is_strtotime) {
      $form_state
        ->setErrorByName('default_value_input][default_start_time', $this
        ->t('The relative default start time value entered is invalid.'));
    }
  }
  if ($form_state
    ->getValue([
    'default_value_input',
    'default_end_time_type',
  ]) == static::DEFAULT_VALUE_CUSTOM) {
    $is_strtotime = @strtotime($form_state
      ->getValue([
      'default_value_input',
      'default_end_time',
    ]));
    if (!$is_strtotime) {
      $form_state
        ->setErrorByName('default_value_input][default_end_time', $this
        ->t('The relative default end time value entered is invalid.'));
    }
  }
}