scroll_progress-9.1.x-dev/scroll_progress.module
scroll_progress.module
<?php
/**
* @file
* This file is used to write hooks that used in the module.
*/
use Drupal\Core\Cache\Cache;
/**
* Implements template_preprocess_html().
*/
function scroll_progress_preprocess_html(&$variables) {
/** @var \Drupal\scroll_progress\ScrollProgressHelperInterface $helper */
$helper = \Drupal::service('scroll_progress.helper');
$config = $helper->getConfiguration();
if (!isset($variables['#cache']['tags'])) {
$variables['#cache']['tags'] = [];
}
$variables['#cache']['tags'] = Cache::mergeTags($variables['#cache']['tags'], $config->getCacheTags());
if (!$helper->isEnabled()) {
return;
}
if ($helper->evaluate()) {
$selected_theme = $config->get('scroll_progress_theme');
$color = $config->get('scroll_progress_color');
$element = $config->get('element') ?: 'body';
$admin_context = \Drupal::service('router.admin_context');
if ($admin_context->isAdminRoute()) {
$admin_flag = $config->get('scroll_progress_load_on_admin_enabled');
if ($admin_flag == 1) {
$variables['#attached']['library'][] = 'scroll_progress/scroll_progress_' . $selected_theme . '_js';
$variables['#attached']['drupalSettings']['scroll_progress_color'] = $color;
$variables['#attached']['drupalSettings']['scroll_progress_element'] = $element;
}
}
else {
$variables['#attached']['library'][] = 'scroll_progress/scroll_progress_' . $selected_theme . '_js';
$variables['#attached']['drupalSettings']['scroll_progress_color'] = $color;
$variables['#attached']['drupalSettings']['scroll_progress_element'] = $element;
}
}
}
/**
* Implements hook_help().
*/
function scroll_progress_help($path, $arg) {
switch ($path) {
case 'help.page.scroll_progress':
$output = '<p>' . t('It provides a beautiful progress indicator for page scroll') . '</p>';
$output .= '<p>' . t('Current version of the module allows you to choose any of the 5 available Scroll themes.You can choose color scheme for indication.') . '</p>';
$output .= '<ul>' . t('Themes are as follow:');
$output .= '<li>' . t('Straight line') . '</li>';
$output .= '<li>' . t('Circular progress') . '</li>';
$output .= '<li>' . t('Animated progress') . '</li>';
$output .= '<li>' . t('Tooltip progress') . '</li>';
$output .= '<li>' . t('Bottom progress bar') . '</li>';
$output .= '</ul>';
return $output;
}
}
