You are here

function highcharttable_preprocess_page in HighchartTable 7

Implements hook_preprocess_page().

Many hooks qualify for what we do here...

File

./highcharttable.module, line 28
highcharttable.module

Code

function highcharttable_preprocess_page($variables) {
  $module_path = drupal_get_path('module', 'highcharttable');

  // Add some Javascript, with a group and weight such that it will run before
  // modules/contextual/contextual.js
  // We need this on all pages because we do not know a-priori whether the
  // page to be loaded will have HTML tables on it or not -- that is exactly
  // what this Javascript figures out!
  $js = $module_path . '/js/highcharttable.js';
  drupal_add_js($js, array(
    'group' => JS_LIBRARY,
    'weight' => -1,
  ));
  $global_settings = variable_get('highcharttable_global_settings', array());
  $path = current_path();
  if (user_access('configure chart decorations')) {
    $exclude_pages = isset($global_settings['contextual-links-exclude-pages']) ? $global_settings['contextual-links-exclude-pages'] : HIGHCHARTTABLE_CONTEXTUAL_LINKS_EXCLUDE_PAGES;
    if (highcharttable_match_path($path, $exclude_pages)) {
      $global_settings['contextual-links'] = 'off';
    }
  }
  else {
    $global_settings['contextual-links'] = 'off';
  }
  if ($global_settings['contextual-links'] != 'off') {
    drupal_add_css($module_path . '/css/highcharttable.css');
    if ($global_settings['contextual-links'] == '') {

      // Default core-style contexutual links behaviour.
      // These lines will do nothing, if already included by core Contextual.
      $contextual_path = drupal_get_path('module', 'contextual');
      drupal_add_css($contextual_path . '/contextual.css');
      drupal_add_js($contextual_path . '/contextual.js');
    }
  }

  // First, pass the global settings to the js.
  drupal_add_js(array(
    'highcharttable' => array(
      'global' => $global_settings,
    ),
  ), array(
    'type' => 'setting',
  ));

  // ... now pass the decorations too.
  $path_alias = drupal_get_path_alias($path);
  $decoration_settings = variable_get('highcharttable_decorations', array());
  foreach ($decoration_settings as $decoration) {
    if (!empty($decoration['pages-and-selector'])) {
      $include_pages = $decoration['pages-and-selector']['include-pages'];
      if (highcharttable_match_path($path, $include_pages) || highcharttable_match_path($path_alias, $include_pages)) {
        $settings = highcharttable_get_js_settings($global_settings, $decoration);
        drupal_add_js(array(
          'highcharttable' => $settings,
        ), array(
          'type' => 'setting',
        ));
        if (empty($is_loaded)) {
          $variant = empty($global_settings['use-patched-library']) ? NULL : 'patched';
          highcharttable_load_libs($variant);
          $is_loaded = TRUE;
        }
      }
    }
  }
}