respondjs-8.x-1.x-dev/respondjs.module
respondjs.module
<?php
/**
* @file
* Contains respondjs.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function respondjs_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.respondjs':
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('It allows browsers without native MQ support to have a rudimentary ability to process CSS wrapped in max- and min-width MQs.') . '</p>';
return $output;
}
}
/**
* Implements hook_page_top().
*/
function respondjs_page_top(&$page_top) {
$page_top['#attached'] = [
'library' => [
'respondjs/respondjs',
],
];
$config = \Drupal::configFactory()->getEditable('respondjs.settings');
if (empty($config->get('warn'))) {
$preprocessed = \Drupal::config('system.performance')->get('css.preprocess');
$route = \Drupal::routeMatch()->getRouteObject();
$is_admin = \Drupal::service('router.admin_context')->isAdminRoute($route);
if ($preprocessed === FALSE && $is_admin === TRUE) {
\Drupal::messenger()->addError(t('The Respond.js module is enabled, but CSS aggregation is disabled. The script cannot function until <a href="/admin/config/development/performance">CSS aggregation is enabled</a>.'), 'error');
}
}
}
