You are here

function _strongarm_lockdown in Strongarm 6

Recursive function that hunts down form elements that are likely to be related to strongarm'd variables and locks them down.

1 call to _strongarm_lockdown()
strongarm_form_alter in ./strongarm.module
Implementation of hook_form_alter().

File

./strongarm.admin.inc, line 123

Code

function _strongarm_lockdown(&$form, $pattern = '', $position = STRONGARM_PATTERN_PREFIX) {
  $var_conf = strongarm_get_conf();
  foreach (element_children($form) as $elem) {
    $children = element_children($form[$elem]);
    $key = $elem;
    $match = FALSE;
    if (isset($var_conf[$key])) {
      $match = TRUE;
    }
    else {
      if (!empty($pattern)) {
        $key = $position == STRONGARM_PATTERN_PREFIX ? "{$pattern}_{$key}" : "{$key}_{$pattern}";
        if (isset($var_conf[$key])) {
          $match = TRUE;
        }
      }
    }
    if ($match) {

      // If the default form value matches the strongarm value,
      // it is highly likely we have a match. Disable the field.
      if (isset($form[$elem]['#default_value']) && $var_conf[$key] == $form[$elem]['#default_value']) {
        $form[$elem]['#disabled'] = TRUE;
        $form[$elem]['#value'] = $form[$elem]['#default_value'];
      }
      if (!isset($form[$elem]['#attributes']['class'])) {
        $form[$elem]['#attributes']['class'] = "strongarm";
      }
      else {
        $form[$elem]['#attributes']['class'] .= " strongarm";
      }
      $altered = TRUE;
    }

    // If this is a tree'd element, recurse
    if (!empty($form[$elem]['#tree']) || !empty($children)) {
      $altered = _strongarm_lockdown($form[$elem], $pattern, $position) || $altered;
    }
  }
  return $altered;
}