You are here

function qtip_field_field_widget_form_alter in qTip (Stylish jQuery Tooltips) 7.2

Implements hook_field_widget_form_alter().

File

modules/qtip_field/qtip_field.module, line 96

Code

function qtip_field_field_widget_form_alter(&$element, &$form_state, $context) {
  if (!_qtip_is_supported_field($context['field']['type'], $context['instance']['widget']['type'])) {
    return;
  }
  if (isset($context['instance']['qtip']) && $context['instance']['qtip']['text'] != 'none') {

    // Get type of field
    $field_type = $context['field']['type'];
    switch ($field_type) {
      case 'text':
      case 'number_decimal':
        $local_element =& $element['value'];
        break;

      // case 'image':
      //   $local_element =& $element[0];
      //   break;
      default:
        $local_element =& $element;
        break;
    }
    $local_element['#attributes']['class'][] = 'qtip-link';
    $tooltip_title = isset($context['instance']['qtip']['title']) ? $context['instance']['qtip']['title'] : '';
    $tooltip_text = '';

    // Get the Help text for the tooltip if that is what is supposed to be used
    switch ($context['instance']['qtip']['text']) {
      case 'description':
        if (isset($local_element['#description'])) {
          $tooltip_text = $local_element['#description'];

          // Remove the description since it will be displaying in the tooltip
          unset($local_element['#description']);
        }
        break;
      case 'filter':
        if (preg_match_all("/{qtip:\\s?([^\\|\\}]+)\\|([^\\}]*)?}/i", $local_element['#description'], $match)) {
          foreach ($match[0] as $key => $value) {
            $search[] = $match[0][$key];
            $title = '';
            $tooltip = $match[2][$key];
            if (strpos($tooltip, '|') !== FALSE) {
              list($title, $tooltip) = explode('|', $match[2][$key]);
            }
            $theme_variables = array(
              'instance' => $context['instance']['qtip']['instance'],
              'content' => $match[1][$key],
              'title' => $title,
              'tooltip' => $tooltip,
            );
            $replace[] = theme('qtip', $theme_variables);
          }
          $local_element['#description'] = str_replace($search, $replace, $local_element['#description']);
        }
        break;
      case 'custom':
        $tooltip_text = isset($context['instance']['qtip']['custom_text']) ? $context['instance']['qtip']['custom_text'] : '';
        break;
    }
    $local_element['#suffix'] = theme('qtip_form', array(
      'instance' => $context['instance']['qtip']['instance'],
      'title' => $tooltip_title,
      'tooltip' => $tooltip_text,
    ));
  }
}