You are here

public static function TimePickerWidget::fieldSettingsFinalNullCleanType in Date Popup Timepicker 8

Method deleting Null parameters before send to JS.

Parameters

array $settings: Non-filter parameters.

Return value

array Returned filtering Parameters for send to JS.

1 call to TimePickerWidget::fieldSettingsFinalNullCleanType()
TimePickerWidget::processFieldSettings in src/Plugin/Field/FieldWidget/TimePickerWidget.php
Function of typification options Timepicker.

File

src/Plugin/Field/FieldWidget/TimePickerWidget.php, line 480

Class

TimePickerWidget
Plugin implementation of the 'datetime_timepicker' widget.

Namespace

Drupal\date_popup_timepicker\Plugin\Field\FieldWidget

Code

public static function fieldSettingsFinalNullCleanType(array &$settings) {
  $new = $settings;

  // Convert boolean settings to boolean.
  $boolean = [
    'showLeadingZero',
    'showMinutesLeadingZero',
    'showHours',
    'showMinutes',
    'showCloseButton',
    'showNowButton',
    'showDeselectButton',
  ];
  foreach ($boolean as $key) {
    $new[$key] = (bool) $settings[$key];
  }

  // Final cleanup.
  $not_null = function ($el) {
    return isset($el);
  };
  foreach ([
    'hours',
    'minutes',
    'minTime',
    'maxTime',
  ] as $key) {
    $new[$key] = array_filter($settings[$key], $not_null);
    if (empty($new[$key])) {
      unset($new[$key]);
    }
  }
  if (!isset($new['rows'])) {

    // Make sure that NULL value is removed from settings.
    unset($new['rows']);
  }
  return $new;
}