You are here

public function UltimateCronPlugin::fallbackalize in Ultimate Cron 7.2

Process fallback form parameters.

Parameters

array $elements: Elements to process.

array $defaults: Default values to add to description.

bool $remove_non_fallbacks: If TRUE, non fallback elements will be removed.

File

./ultimate_cron.plugin.inc, line 655
Plugin framework for Ultimate Cron.

Class

UltimateCronPlugin
This is the base class for all Ultimate Cron plugins.

Code

public function fallbackalize(&$elements, &$values, $defaults, $remove_non_fallbacks = FALSE) {
  if (empty($elements)) {
    return;
  }
  foreach (element_children($elements) as $child) {
    $element =& $elements[$child];
    if (empty($element['#tree'])) {
      $param_values =& $values;
      $param_defaults =& $defaults;
    }
    else {
      $param_values =& $values[$child];
      $param_defaults =& $defaults[$child];
    }
    $this
      ->fallbackalize($element, $param_values, $param_defaults, $remove_non_fallbacks);
    if (empty($element['#type']) || $element['#type'] == 'fieldset') {
      continue;
    }
    if (!empty($element['#fallback'])) {
      if (!$remove_non_fallbacks) {
        if ($element['#type'] == 'radios') {
          $label = $this
            ->settingsLabel($child, $defaults[$child]);
          $element['#options'] = array(
            '' => t('Default (@default)', array(
              '@default' => $label,
            )),
          ) + $element['#options'];
        }
        elseif ($element['#type'] == 'select' && empty($element['#multiple'])) {
          $label = $this
            ->settingsLabel($child, $defaults[$child]);
          $element['#options'] = array(
            '' => t('Default (@default)', array(
              '@default' => $label,
            )),
          ) + $element['#options'];
        }
        elseif ($defaults[$child] !== '') {
          $element['#description'] .= ' ' . t('(Blank = @default).', array(
            '@default' => $this
              ->settingsLabel($child, $defaults[$child]),
          ));
        }
        unset($element['#required']);
      }
    }
    elseif (!empty($element['#type']) && $remove_non_fallbacks) {
      unset($elements[$child]);
    }
    elseif (!isset($element['#default_value']) || $element['#default_value'] === '') {
      $empty = $element['#type'] == 'checkbox' ? FALSE : '';
      $values[$child] = !empty($defaults[$child]) ? $defaults[$child] : $empty;
      $element['#default_value'] = $values[$child];
    }
  }
}