You are here

function label_help_form_alter in Label Help 7

Same name and namespace in other branches
  1. 8 label_help.module \label_help_form_alter()

Implements hook_form_alter().

1 call to label_help_form_alter()
label_help_form_profile2_form_alter in ./label_help.module
Implements hook_orm_profile2_form_alter().

File

./label_help.module, line 17
This is the file description for the Label Help module.

Code

function label_help_form_alter(&$form, &$form_state, $form_id) {
  $children = array_intersect_key($form, array_flip(element_children($form)));
  foreach ($children as $key => $item) {
    if (is_array($item) && isset($item['#language']) && isset($item[$item['#language']]) && isset($form['#entity_type']) && isset($form['#bundle']) && ($instance = field_info_instance($form['#entity_type'], $key, $form['#bundle']))) {
      if (!isset($instance['widget']['settings']['label_help_description'])) {
        continue;
      }
      $theme_option = array(
        'description at top' => $instance['widget']['settings']['label_help_description'],
      );

      // Put comments above the label for field forms of type 'container'
      // that are specifically configured.
      if (isset($item['#type']) && $item['#type'] == 'container' && isset($item[$item['#language']][0])) {

        // For reasons best known to the lunatics who designed the Forms API,
        // $form[$key][$item['#language']][0]['#theme_options'] has to be set to get
        // this working for textarea fields, and
        // form[$key][$item['#language']][0]['value']['#theme_options'] has to be set
        // to get this working for one-line text fields, and
        // form[$key][$item['#language']][0]['default']['#theme_options'] has to be set
        // to get this working for some other fields.
        if (isset($form[$key][$item['#language']][0]['default'])) {
          $form[$key][$item['#language']][0]['default']['#theme_options'] = $theme_option;
        }
        elseif (isset($form[$key][$item['#language']][0]['value'])) {
          $form[$key][$item['#language']][0]['value']['#theme_options'] = $theme_option;
        }
        elseif (isset($form[$key][$item['#language']][0]['target_id'])) {
          $form[$key][$item['#language']][0]['target_id']['#theme_options'] = $theme_option;
        }
        elseif (isset($form[$key][$item['#language']][0]['tid'])) {
          $form[$key][$item['#language']][0]['tid']['#theme_options'] = $theme_option;
        }
        else {
          $form[$key][$item['#language']][0]['#theme_options'] = $theme_option;
        }
      }
      else {
        $form[$key][$item['#language']]['#theme_options'] = $form[$key][$item['#language']]['value']['#theme_options'] = $theme_option;
      }
    }
  }
}