You are here

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

Function of typification options Timepicker.

Parameters

array $settings: Settings for JS Timepicker.

Return value

array return array of changed settings after typefications of all parameters.

2 calls to TimePickerWidget::processFieldSettings()
DateRangeTimePickerWidget::formElement in src/Plugin/Field/FieldWidget/DateRangeTimePickerWidget.php
Returns the form for a single field widget.
TimePickerWidget::formElement in src/Plugin/Field/FieldWidget/TimePickerWidget.php
Returns the form for a single field widget.

File

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

Class

TimePickerWidget
Plugin implementation of the 'datetime_timepicker' widget.

Namespace

Drupal\date_popup_timepicker\Plugin\Field\FieldWidget

Code

public static function processFieldSettings(array $settings) {
  $options = isset($settings) ? $settings : [];
  if (!empty($options)) {
    $groups = [
      'boolean' => [
        'showLeadingZero',
        'showMinutesLeadingZero',
        'showHours',
        'showMinutes',
        'showCloseButton',
        'showNowButton',
        'showDeselectButton',
      ],
      'int' => [
        'hours',
        'minutes',
        'rows',
        'hour',
        'minute',
        'interval',
        'starts',
        'ends',
      ],
      'no_filtering' => [],
    ];

    // Callback for the array_walk_recursive().
    $filter = function (&$item, $key, $groups) {
      if (in_array($key, $groups['boolean'], TRUE)) {
        if ($item !== NULL) {
          $item = (bool) $item;
        }
      }
      elseif (in_array($key, $groups['int'], TRUE)) {
        if ($item !== NULL) {
          $item = (int) $item;
        }
      }
      elseif (in_array($key, $groups['no_filtering'], TRUE)) {

        // Do nothing.
      }
      else {

        // @todo Use filter_xss_admin() instead?
        $item = Html::escape($item);
      }
    };

    // Filter user submitted settings since plugin builds output by just
    // concatenation of strings so it's possible, for example,
    // to insert html into labels.
    array_walk_recursive($options, $filter, $groups);
  }
  return self::fieldSettingsFinalNullCleanType($options);
}