You are here

function admin_menu_flush_cache in Administration menu 8.3

Same name and namespace in other branches
  1. 6.3 admin_menu.inc \admin_menu_flush_cache()
  2. 6 admin_menu.inc \admin_menu_flush_cache()
  3. 7.3 admin_menu.inc \admin_menu_flush_cache()

Flush all caches or a specific one.

Parameters

$name: (optional) Name of cache to flush.

1 string reference to 'admin_menu_flush_cache'
admin_menu_menu in ./admin_menu.module
Implements hook_menu().

File

./admin_menu.inc, line 769
Menu builder functions for Administration menu.

Code

function admin_menu_flush_cache($name = NULL) {

  // @todo Update for built-in token handling; http://drupal.org/node/755584
  $token = drupal_container()
    ->get('request')->query
    ->get('token');
  if (!isset($token) || !drupal_valid_token($token, current_path())) {
    throw new AccessDeniedHttpException();
  }
  if (isset($name)) {
    $caches = module_invoke_all('admin_menu_cache_info');
    if (!isset($caches[$name])) {
      throw new NotFoundHttpException();
    }
  }
  else {
    $caches[$name] = [
      'title' => t('Every'),
      'callback' => 'drupal_flush_all_caches',
    ];
  }

  // Pass the cache to flush forward to the callback.
  $function = $caches[$name]['callback'];
  $function($name);
  \Drupal::messenger()
    ->addStatus(t('!title cache cleared.', [
    '!title' => $caches[$name]['title'],
  ]));

  // The JavaScript injects a destination request parameter pointing to the
  // originating page, so the user is redirected back to that page. Without
  // destination parameter, the redirect ends on the front page.
  drupal_goto();
}