You are here

function _simplemenu_add_menu in SimpleMenu 7

Same name and namespace in other branches
  1. 6 simplemenu.module \_simplemenu_add_menu()

\brief Add the simplemenu variable with the menu to be displayed.

This function loads the menu to be displayed and transforms it so it works with superfish.

If the cache version of the simplemenu JavaScript string cannot be created, then it is sent inline whether or not the user asked for it to be sent inline.

1 call to _simplemenu_add_menu()
simplemenu_init in ./simplemenu.module
Implements hook_init().

File

./simplemenu.module, line 74
Creates a simplemenu.

Code

function _simplemenu_add_menu() {

  // XXX -- should we put that in the settings instead? why put it in its own variable?
  $simplemenu = 'var simplemenu=' . drupal_json_encode(simplemenu_get_menu()) . ';';
  $has_file = variable_get('simplemenu_cache_menu', TRUE);
  if ($has_file) {
    $js_hash = drupal_hash_base64($simplemenu);
    $js_path = 'public://js';

    // same path as concatenated Core JS
    $js_filename = $js_path . '/simplemenu_' . $js_hash . '.js';
    if (!file_exists($js_filename)) {
      file_prepare_directory($js_path, FILE_CREATE_DIRECTORY);
      if (!file_unmanaged_save_data($simplemenu, $js_filename, FILE_EXISTS_REPLACE)) {
        $has_file = FALSE;
      }
    }
  }
  $options = array(
    'scope' => variable_get('simplemenu_menu_scope', 'footer'),
  );
  if ($has_file) {

    //$options['type'] = 'file'; -- default
    drupal_add_js($js_filename, $options);
  }
  else {

    // inline adds the value as is (untouched)
    $options['type'] = 'inline';
    drupal_add_js($simplemenu, $options);
  }
}