You are here

function webform_css_alter in Webform 6.x

Same name and namespace in other branches
  1. 8.5 includes/webform.libraries.inc \webform_css_alter()

Implements hook_css_alter().

File

includes/webform.libraries.inc, line 178
Webform libraries.

Code

function webform_css_alter(&$css, AttachedAssetsInterface $assets) {

  // Remove the stable.theme's off-canvas CSS reset for webform admin routes.
  // @see https://www.drupal.org/project/drupal/issues/2826722
  //
  // NOTE: Most admin themes correctly style jQuery UI dialogs because Drupal's
  // admin UI, especially Views, relies on them.
  $use_off_canvas = WebformDialogHelper::useOffCanvas();

  // @todo Remove once Claro theme support offcanvas tray.
  $is_claro_theme = \Drupal::service('webform.theme_manager')
    ->isActiveTheme('claro');
  $is_admin_route = \Drupal::service('router.admin_context')
    ->isAdminRoute();
  $is_webform_route = preg_match('/(^webform|^entity\\.webform|^entity\\.node\\.webform)/', \Drupal::routeMatch()
    ->getRouteName());
  if ($is_claro_theme || $use_off_canvas && $is_admin_route && $is_webform_route) {
    foreach ($css as $key => $item) {

      // @see 'core/misc/dialog/off-canvas
      // @see core/themes/stable/css/core/dialog/off-canvas
      if (strpos($key, '/off-canvas.') !== FALSE) {
        unset($css[$key]);
      }
    }
  }
  _webform_asset_alter($css, 'css');
}