You are here

function hook_advagg_modify_js_pre_render_alter in Advanced CSS/JS Aggregation 7.2

Allow other modules to modify $children and $elements before rendering.

Parameters

array $children: An array of children elements.

array $elements: A render array containing:

  • #items: The JavaScript items as returned by drupal_add_js() and altered by drupal_get_js().
  • #group_callback: A function to call to group #items. Following this function, #aggregate_callback is called to aggregate items within the same group into a single file.
  • #aggregate_callback: A function to call to aggregate the items within the groups arranged by the #group_callback function.

See also

advagg_modify_js_pre_render()

advagg_js_compress_advagg_modify_js_pre_render_alter()

Related topics

2 functions implement hook_advagg_modify_js_pre_render_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

advagg_js_compress_advagg_modify_js_pre_render_alter in advagg_js_compress/advagg_js_compress.module
Implements hook_advagg_modify_js_pre_render_alter().
advagg_mod_advagg_modify_js_pre_render_alter in advagg_mod/advagg_mod.module
Implements hook_advagg_modify_js_pre_render_alter().
1 invocation of hook_advagg_modify_js_pre_render_alter()
advagg_modify_js_pre_render in ./advagg.module
Callback for pre_render so elements can be modified before they are rendered.

File

./advagg.api.php, line 499
Hooks provided by the AdvAgg module.

Code

function hook_advagg_modify_js_pre_render_alter(array &$children, array &$elements) {

  // Get variables.
  $aggregate_settings['variables']['advagg_js_compressor'] = variable_get('advagg_js_compress_inline', ADVAGG_JS_COMPRESS_INLINE);
  $aggregate_settings['variables']['advagg_js_compress_max_ratio'] = variable_get('advagg_js_compress_max_ratio', ADVAGG_JS_COMPRESS_MAX_RATIO);

  // Do nothing if the compressor is disabled.
  if (empty($aggregate_settings['variables']['advagg_js_compressor'])) {
    return;
  }

  // Do nothing if the page is not cacheable and inline compress if not
  // cacheable is not checked.
  if (!variable_get('advagg_js_compress_inline_if_not_cacheable', ADVAGG_JS_COMPRESS_INLINE_IF_NOT_CACHEABLE) && !drupal_page_is_cacheable()) {
    return;
  }

  // Compress any inline JS.
  module_load_include('inc', 'advagg_js_compress', 'advagg_js_compress.advagg');
  foreach ($children as &$values) {
    if (!empty($values['#value'])) {
      $contents = $values['#value'];
      $filename = drupal_hash_base64($contents);
      advagg_js_compress_prep($contents, $filename, $aggregate_settings, FALSE);
      $values['#value'] = $contents;
    }
  }
  unset($values);
}