You are here

function hook_responsive_menus_styles_alter in Responsive Menus 7

Same name and namespace in other branches
  1. 8 responsive_menus.api.php \hook_responsive_menus_styles_alter()

Alter any of the styles registered with Responsive Menus.

This is a very powerful hook that can allow you to: -Bypass a library's requirements. --e.g. Remove a style's requirement on jquery_update or libraries module. -Provide your own libraries or files. -Include additional files to load with a style. -Use a different form function for a style's settings. -Use a different function for building javascript settings.

Parameters

array $styles: Array of all the currently known styles. Options: name: string - Style's name. form: string - Function name to return Drupal FAPI array. js_files: array - Array of paths to JS files to load for this style. css_files: array - Array of paths to CSS files to load for this style. js_settings: string - Function name to build JS settings passed to drupal_add_js(). jquery_version: float - Minimum required jQuery version for this style. -- Note: This setting will require jquery_update module enabled unless the -- user checks "I will provide my own jQuery Library". use_libraries: boolean - TRUE / FALSE to use the Libraries module. library: string - Name of the library, used for Libraries module. selector: string - Text for the admin page describing which selector to use. file: string - Optional file with the form & js_settings callback functions.

Other notes: If you want to bypass the requirement on the Libraries module for a style, you can set 'use_libraries' => FALSE, and then use js_files & css_files to provide the path(s) to the files.

See the 2 examples below. First, showing all the available options. Note including js_files, css_files AND specifying use_libraries => TRUE would result in the Libraries module first trying to load the library, then Responsive Menus would drupal_add_[type] the files in js_files & css_files settings.

Second example is showing how to override the sidr style to lift Libraries module requirement to include your own files.

1 invocation of hook_responsive_menus_styles_alter()
responsive_menus_styles in ./responsive_menus.module
Gather available styles for Responsive Menus.

File

./responsive_menus.api.php, line 158
Hooks provided by the Responsive Menus module.

Code

function hook_responsive_menus_styles_alter(&$styles) {

  // Example showing all of the currently available fields.
  // Note, js_folder & css_folder are excluded until an alternative to glob() is
  // built into RM.
  $path = drupal_get_path('module', 'my_style_module') . '/styles';
  $styles['my_style'] = array(
    'name' => t('My Style'),
    'form' => 'responsive_menus_my_style_settings',
    'js_files' => array(
      $path . '/my_style/my_style.js',
      $path . '/my_style/my_other_style.js',
    ),
    'css_files' => array(
      $path . '/my_style/my_style.css',
    ),
    'js_settings' => 'responsive_menus_my_style_js_settings',
    'jquery_version' => 1.7,
    'use_libraries' => TRUE,
    'library' => 'my_style',
    'selector' => t('Text describing what selector to use.  e.g. ul'),
    // The file parameter can be left empty.  It will look in the .module file.
    'file' => $path . '/my_style/my_style.inc',
  );

  // In this next example, I will override the Sidr style to bypass the Libraries
  // module and provide my own files in my_module/responsive_menus_alter/sidr/.
  $path = drupal_get_path('module', 'my_module') . '/responsive_menus_alter';
  $styles['sidr'] = array(
    'use_libraries' => FALSE,
    'js_files' => array(
      $path . '/sidr/my_sidr.js',
    ),
    'css_files' => array(
      $path . '/sidr/my_sidr.css',
    ),
  );
}