You are here

function views_field_tooltip__insert_widget in Views Field Tooltip 7

Insert tooltip widget into a form.

1 call to views_field_tooltip__insert_widget()
views_field_tooltip_form_views_ui_config_item_form_alter in ./views_field_tooltip.module
Implements hook_form_FORM_ID_alter() for `views_ui_config_item_form`.

File

./views_field_tooltip.module, line 172
Shows tooltips on Views fields and labels.

Code

function views_field_tooltip__insert_widget(&$form, $title, $prefix, $weight, $tooltip, $info, $handler, $label = FALSE) {
  $fieldset = "{$prefix}_tooltip_settings";
  $form['options'][$fieldset] = array(
    '#type' => 'fieldset',
    '#title' => $title,
    '#weight' => $weight,
    '#collapsible' => TRUE,
    '#collapsed' => empty($tooltip['text']) && empty($tooltip['url']),
  );
  $form['options']["{$prefix}_tooltip_ajax"] = array(
    '#type' => 'checkbox',
    '#title' => t('Load from URL (dynamic content)'),
    '#description' => t('
      Check this box to specify a URL that will return the HTML tooltip.
      Otherwise, you can enter the tooltip text directly below.
    '),
    '#fieldset' => $fieldset,
    '#default_value' => @$tooltip['ajax'],
  );
  $form['options']["{$prefix}_tooltip_ajax_mode"] = array(
    '#type' => 'radios',
    '#title' => t('URL retrieval mode'),
    '#options' => array(
      0 => t('iFrame (include nested HTML page)'),
      1 => t('AJAX (include only page contents)'),
    ),
    0 => array(
      '#description' => t('An <a href="https://en.wikipedia.org/wiki/Framing_(World_Wide_Web)">iFrame</a> will be included, displaying the specified URL as a separate document (including styles and scripts).'),
    ),
    1 => array(
      '#description' => t('Use <a href="https://en.wikipedia.org/wiki/Ajax_(programming)">AJAX</a> to retrieve only the body HTML contents of the given URL and include them directly in the tooltip, as if they were given as the tooltip text.'),
    ),
    '#fieldset' => $fieldset,
    '#default_value' => empty($tooltip['ajax_mode']) ? 0 : 1,
    '#states' => array(
      'visible' => array(
        ":input[name=\"options[{$prefix}_tooltip_ajax]\"]" => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form['options']["{$prefix}_tooltip_url"] = array(
    '#type' => 'textfield',
    '#title' => t('Tooltip URL'),
    '#description' => t('Local or external URL of an HTML snippet tooltip. You may enter data from this view as per the "Replacement patterns" below. (External URLs might not work without special configuration on the external server, like <a href="https://en.wikipedia.org/wiki/Clickjacking#X-Frame-Options">X-Frame-Options</a> or <a href="https://en.wikipedia.org/wiki/Same-origin_policy#Cross-Origin_Resource_Sharing">Access-Control-Allow-Origin</a> headers.)'),
    '#fieldset' => $fieldset,
    '#dependency' => array(
      "edit-options-{$prefix}-tooltip-ajax" => array(
        1,
      ),
    ),
    '#attributes' => array(
      'class' => array(
        'dependent-options',
      ),
    ),
    '#default_value' => @$tooltip['url'],
  );
  $form['options']["{$prefix}_tooltip_text"] = array(
    '#type' => 'textarea',
    '#title' => t('Tooltip text'),
    '#description' => t('The text to display for this tooltip. You may include HTML. You may enter data from this view as per the "Replacement patterns" below.'),
    '#fieldset' => $fieldset,
    '#dependency' => array(
      "edit-options-{$prefix}-tooltip-ajax" => array(
        0,
      ),
    ),
    '#attributes' => array(
      'class' => array(
        'dependent-options',
      ),
    ),
    '#default_value' => @$tooltip['text'],
  );
  $form['options']["{$prefix}_tooltip_icon"] = array(
    '#type' => 'textfield',
    '#title' => t('Tooltip icon URL'),
    '#description' => t('Local or external URL of an image used to trigger the tooltip. You may enter data from this view as per the "Replacement patterns" below.'),
    '#fieldset' => $fieldset,
    '#default_value' => @$tooltip['icon'],
  );
  $form['options']["{$prefix}_tooltip_replacement_patterns"] = array(
    '#type' => 'fieldset',
    '#title' => t('Replacement patterns'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#value' => views_field_tooltip__get_replacement_help($handler, $label),
    '#fieldset' => $fieldset,
  );
  if (!empty($info)) {
    $form['options']["{$prefix}_tooltip_qtip"] = array(
      '#type' => 'textarea',
      '#title' => t('Tooltip style'),
      '#description' => t('Override global tooltip style settings for this field.'),
      '#fieldset' => $fieldset,
      '#default_value' => jsonpp(@$tooltip['qtip']),
    );
  }
  else {
    $form['options']["{$prefix}_tooltip_qtip"] = array(
      '#type' => 'value',
      '#value' => jsonpp(@$tooltip['qtip']),
    );
  }
}