qtools_profiler-8.x-1.x-dev/qtools_profiler.module

qtools_profiler.module
<?php

/**
 * @file
 * Module hooks.
 */

use Drupal\Core\Render\Element;
use Drupal\Core\Url;
use Drupal\qtools_profiler\PerformanceService;

/**
 * Preprocess page output, add profiler preview libriary.
 */
function qtools_profiler_preprocess_page(&$variables) {
  // For preview iframes unset everything except content part.
  $route = \Drupal::request()->attributes->get('_route');
  if (strpos($route, 'qtools_profiler.preview') !== FALSE) {
    foreach (Element::children($variables['page']) as $key) {
      if ($key != 'content') {
        unset($variables['page'][$key]);
      }
    }
  }
}

/**
 * Implements hook_toolbar_alter().
 */
function qtools_profiler_toolbar_alter(&$items) {
  $route = \Drupal::request()->attributes->get('_route');
  if (strpos($route, 'qtools_profiler.preview') !== FALSE) {
    $items = [];
  }
}

/**
 * Implements hook_cron().
 */
function qtools_profiler_cron() {
  /** @var \Drupal\qtools_profiler\PerformanceService $performanceService */
  $performanceService = \Drupal::service('qtools_profiler.performance');
  $ttl = $performanceService->confGet('cleanup');
  if (!empty($ttl)) {
    $count = $performanceService->cleanup(time() - $ttl);
    \Drupal::logger('qtools_profiler')->notice('@count records was cleaned up.', ['@count' => $count]);
  }
}

/**
 * Implements hook_cache_flush().
 */
function qtools_profiler_cache_flush() {
  // Do same routine as on cron runs.
  qtools_profiler_cron();
}

/**
 * Implements hook_theme().
 */
function qtools_profiler_theme() {
  return [
    'qtools_profiler_preview_iframe' => [
      'render element' => 'element',
      'variables' => [
        'build_path' => '',
      ],
    ],
  ];
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc