You are here

function devel_form_alter in Devel 5

Implementation of hook_form_alter().

File

./devel.module, line 475

Code

function devel_form_alter($form_id, &$form, $key_in = NULL) {
  if (user_access('access devel information') && variable_get('devel_form_weights', 0)) {
    $children = element_children($form);
    if (empty($children)) {
      if (isset($form['#type']) && !in_array($form['#type'], array(
        'value',
        'hidden',
      ))) {
        if (!isset($form['#title'])) {
          $form['#title'] = '';
        }
        $form['#title'] .= " (key={$key_in}, weight=" . (isset($form['#weight']) ? $form['#weight'] : 0) . ')';
      }
    }
    else {
      foreach (element_children($form) as $key) {

        // We need to add the weight to fieldsets.
        if (element_children($form[$key])) {

          // Which are a container of others.
          if (!isset($form[$key]['#title'])) {
            $form[$key]['#title'] = '';
          }
          $form[$key]['#title'] .= " (key={$key}, weight=" . (isset($form[$key]['#weight']) ? $form[$key]['#weight'] : 0) . ')';
        }
        devel_form_alter($form_id, $form[$key], $key);
      }
    }
  }
}