You are here

formtips.module in Form Tips 8

Form tips module uses JS to move form descriptions to tooltips.

File

formtips.module
View source
<?php

/**
 * @file
 * Form tips module uses JS to move form descriptions to tooltips.
 */

/**
 * Implements hook_page_bottom().
 */
function formtips_page_bottom(array &$page_bottom) {
  $settings = \Drupal::config('formtips.settings');
  $enabled_themes = $settings
    ->get('formtips_themes');
  $current_theme = \Drupal::service('theme.manager')
    ->getActiveTheme()
    ->getName();
  if (!empty($enabled_themes) && !array_key_exists($current_theme, $enabled_themes)) {
    return;
  }
  $js_settings = [
    'formtips' => [
      'selectors' => explode("\r\n", $settings
        ->get('formtips_selectors')),
      'interval' => $settings
        ->get('formtips_interval'),
      'sensitivity' => $settings
        ->get('formtips_sensitivity'),
      'timeout' => $settings
        ->get('formtips_timeout'),
      'max_width' => $settings
        ->get('formtips_max_width'),
      'trigger_action' => $settings
        ->get('formtips_trigger_action'),
    ],
  ];
  if ($settings
    ->get('formtips_trigger_action') == 'hover' && $settings
    ->get('formtips_hoverintent')) {
    $page_bottom['formtips']['#attached']['library'][] = 'formtips/hoverintent';
  }
  $page_bottom['formtips']['#attached']['library'][] = 'formtips/formtips';
  $page_bottom['formtips']['#attached']['drupalSettings'] = $js_settings;

  // Add cachability metadata.

  /** @var Drupal\Core\Render\Renderer $renderer */
  $renderer = \Drupal::service('renderer');
  $renderer
    ->addCacheableDependency($page_bottom['formtips'], $settings);
}

Functions

Namesort descending Description
formtips_page_bottom Implements hook_page_bottom().