You are here

function _popup_descriptions_apply_popup_description in Popup 7

Same name and namespace in other branches
  1. 8 modules/popup_descriptions/includes/popup_descriptions.util.inc \_popup_descriptions_apply_popup_description()
  2. 7.x modules/popup_descriptions/includes/popup_descriptions.util.inc \_popup_descriptions_apply_popup_description()

Applies popup behaviour to the description of a form element

1 call to _popup_descriptions_apply_popup_description()
popup_descriptions_preprocess_form_element in modules/popup_descriptions/popup_descriptions.module
Implementation of hook_preprocess_form_element

File

modules/popup_descriptions/includes/popup_descriptions.util.inc, line 12

Code

function _popup_descriptions_apply_popup_description(&$element) {
  if (_popup_descriptions_enabled($element)) {
    $position = variable_get('description-popup-position');
    $element_title = isset($element['#title']) && trim($element['#title']) != '' ? $element['#title'] : variable_get('description-popup-title', '?');
    $title = $position == 'label' ? $element_title : variable_get('description-popup-title', '?');
    $popup = popup_element($title, $element['#description'], array(
      'format' => variable_get('description-popup-format'),
      'element-class' => 'popup-description',
      'empty-title',
    ));
    switch (variable_get('description-popup-position', 0)) {
      case 'label':
        $element['#title'] = $popup;
        unset($element['#description']);
        break;
      case 'prefix':
        isset($element['#field_prefix']) ? $element['#field_prefix'] .= $popup : ($element['#field_prefix'] = $popup);
        unset($element['#description']);
        break;
      case 'suffix':
        isset($element['#field_suffix']) ? $element['#field_suffix'] .= $popup : ($element['#field_suffix'] = $popup);
        unset($element['#description']);
        break;
      default:
        $element['#description'] = $popup;
        break;
    }
  }
}