You are here

function advagg_hooks_implemented in Advanced CSS/JS Aggregation 8.2

Same name and namespace in other branches
  1. 8.4 advagg.module \advagg_hooks_implemented()
  2. 8.3 advagg.module \advagg_hooks_implemented()
  3. 7.2 advagg.module \advagg_hooks_implemented()

Get back what hooks are implemented.

Parameters

bool $all: If TRUE get all hooks related to css/js files. if FALSE get only the subset of hooks that alter the filename/contents.

Return value

array List of hooks and what modules have implemented them.

2 calls to advagg_hooks_implemented()
advagg_current_hooks_hash_array in ./advagg.module
Get an array of all hooks and settings that affect aggregated files contents.
InfoForm::buildForm in src/Form/InfoForm.php
Form constructor.

File

./advagg.module, line 471
Advanced CSS/JS aggregation module.

Code

function advagg_hooks_implemented($all = TRUE) {
  $hooks =& drupal_static(__FUNCTION__);
  if ($hooks) {
    return $hooks;
  }
  $module_handler = \Drupal::moduleHandler();

  // Get hooks in use.
  $hooks = [
    'advagg_aggregate_grouping_alter' => [],
    'advagg_css_contents_alter' => [],
    'advagg_js_contents_alter' => [],
    'advagg_current_hooks_hash_array_alter' => [],
    'advagg_hooks_implemented' => [],
  ];
  if ($all) {
    $hooks += [
      'js_alter' => [],
      'css_alter' => [],
    ];
  }

  // Call hook_advagg_hooks_implemented_alter().
  $module_handler
    ->alter('advagg_hooks_implemented', $hooks, $all);

  // Cache module_implements as this will load up .inc files.
  $serialize_function = advagg_get_serializer();
  $cid = 'advagg_hooks_implemented:' . (int) $all . ':' . Crypt::hashBase64($serialize_function($hooks));
  $cache = \Drupal::cache('bootstrap')
    ->get($cid);
  if (!empty($cache->data)) {
    $hooks = $cache->data;
  }
  else {
    foreach ($hooks as $hook => $values) {
      $hooks[$hook] = $module_handler
        ->getImplementations($hook);

      // Also check themes as drupal_alter() allows for themes to alter things.
      $theme_keys = \Drupal::service('theme_handler')
        ->listInfo();
      if (!empty($theme_keys)) {
        foreach ($theme_keys as $theme_key => $info) {
          $function = $theme_key . '_' . $hook;
          if (function_exists($function)) {
            $hooks[$hook][] = $info['name'];
          }
        }
      }
    }
    \Drupal::cache('bootstrap')
      ->set($cid, $hooks, REQUEST_TIME + 600);
  }
  return $hooks;
}