You are here

function beautytips_add_beautytips in BeautyTips 8

Same name and namespace in other branches
  1. 6.2 beautytips.module \beautytips_add_beautytips()
  2. 6 beautytips.module \beautytips_add_beautytips()
  3. 7.2 beautytips.module \beautytips_add_beautytips()

This is the API. Call this function to add beautytips.

Parameters

array $options - See README.txt for details:

9 calls to beautytips_add_beautytips()
BeautytipsConfigForm::buildForm in src/Form/BeautytipsConfigForm.php
Form constructor.
BeautytipsManagerController::customStylesOverview in beautytips_manager/src/Controller/BeautytipsManagerController.php
Custom styles administration.
beautytips_drupal_help_main in includes/drupal_help.inc
Menu callback; prints a page listing a glossary of Drupal terminology. Beautytips added for the help links
beautytips_manager_page_attachments in beautytips_manager/beautytips_manager.module
Implements hook_page_attachments().
beautytips_page_attachments in ./beautytips.module
Implements hook_page_attachments().

... See full list

File

./beautytips.module, line 36
Provides API for adding beautytips to pages.

Code

function beautytips_add_beautytips(&$element, $options = NULL) {
  $settings = [
    'beautytips' => [],
  ];
  if (is_array($options) && count($options)) {
    foreach ($options as $beautytip => $content) {

      // Setup the settings array for adding js
      if (isset($content) && is_array($content)) {
        $settings['beautytips'][$beautytip] = $content;
        $settings['beautytips'][$beautytip]['style'] = isset($content['style']) ? $content['style'] : 'default';
        $keys_no_add = [
          'cssSelect',
          'style',
          'list',
          'text',
          'preEval',
          'ajaxDisableLink',
          'animate',
        ];
        foreach ($settings['beautytips'][$beautytip] as $key => $value) {

          // Ensure that numeric options are not passed as strings.
          $settings['beautytips'][$beautytip][$key] = is_numeric($value) ? (int) $value : $value;
          if (!in_array($key, $keys_no_add)) {
            $settings['beautytips'][$beautytip]['list'][] = $key;
          }
        }
      }
    }
  }
  beautytips_add_js($element);
  if (!empty($settings['beautytips'])) {
    $element['#attached']['drupalSettings']['beautytips'] = $settings['beautytips'];
  }
}