You are here

public function DatePopupTimepickerTimepicker::processFieldSettings in Date Popup Timepicker 7

Process field settings set in UI for further use in #timepicker options.

For example settings may be sanitized, translated, etc.

Parameters

array $settings: Timepicked settings saved in field instanc.

array $element: Form API element structure to process.

array $form_state: Form state.

array $form: The whole form definition structure.

Return value

array Processed timepicker options.

Overrides DatePopupTimepicker::processFieldSettings

File

plugins/timepicker/timepicker.inc, line 678

Class

DatePopupTimepickerTimepicker
Class DatePopupTimepickerTimepicker.

Code

public function processFieldSettings(array $settings, array $element, array &$form_state, array $form) {
  $options = isset($settings['timepicker_options']) ? $settings['timepicker_options'] : array();
  if (!empty($options)) {

    // @todo Define this list somewhere else since it's used in the DatePopupTimepickerTimepicker::fieldSettingsFormSubmit() as well.
    // @todo Shorten code if possible.
    $groups = array(
      'boolean' => array(
        'showLeadingZero',
        'showMinutesLeadingZero',
        'showPeriod',
        'showPeriodLabels',
        'showHours',
        'showMinutes',
        'showCloseButton',
        'showNowButton',
        'showDeselectButton',
      ),
      'int' => array(
        'hours',
        'minutes',
        'rows',
        'hour',
        'minute',
        'interval',
        'starts',
        'ends',
      ),
      'no_filtering' => array(
        'timeSeparator',
        'periodSeparator',
      ),
    );

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

        // Do nothing.
      }
      else {

        // @todo Use filter_xss_admin() instead?
        $item = check_plain($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 $options;
}