You are here

function beautytips_add_beautytips in BeautyTips 7.2

Same name and namespace in other branches
  1. 8 beautytips.module \beautytips_add_beautytips()
  2. 6.2 beautytips.module \beautytips_add_beautytips()
  3. 6 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()
beautytips_admin in ./beautytips.admin.inc
Menu callback - beautytips admin settings form
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_init in ./beautytips.module
Implements hook_init().
beautytips_manager_custom_styles_form in ./beautytips_manager.admin.inc
Form for editing a custom beautytip style.
beautytips_manager_init in ./beautytips_manager.module
Implements hook_init().

... See full list

File

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

Code

function beautytips_add_beautytips($options = NULL) {
  $settings = [
    'beautytips' => [],
  ];
  $js_added = drupal_add_js($data = NULL, 'setting');
  if (count($options)) {
    foreach ($options as $beautytip => $content) {

      // Ensure the js settings are not added more than once
      if (isset($js_added['settings']['data']) && is_array($js_added['settings']['data'])) {
        foreach ($js_added['settings']['data'] as $setting) {
          if (isset($setting['beautytips'])) {
            if (array_key_exists($beautytip, $setting['beautytips'])) {
              unset($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'] : variable_get('beautytips_default_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();
  if (!empty($settings['beautytips'])) {
    drupal_add_js($settings, 'setting');
  }
}