4

I'm trying to disable the CSS styles from the layout discovery module in my theme.info.yml file. I've tried several options, but I can't seem to get it to work. This is what I have now.

libraries-override:
  core/layout_discovery:
    css:
      theme:
        core/modules/layout_discovery/layouts/twocol/twocol.css: false

The CSS styles can be removed using stylesheets-remove at the moment, but that property has been deprecated. It does seem work at the moment, though.

I would like to find the proper way to remove the CSS stules using libraries-override, if I can.

stylesheets-remove:
  - core/modules/layout_discovery/layouts/onecol/onecol.css
0

3 Answers 3

5

Seems you are missing a starting / on the full path. And the name of the overriding library looks wrong as well. There's no library core/layout_discovery. It must be layout_discovery/twocol instead.

libraries-override:
  layout_discovery/twocol:
    css:
      theme:
        /core/modules/layout_discovery/layouts/twocol/twocol.css: false

Source: Overriding and extending libraries


Alternatively, unsetting libraries via hook_page_attachments_alter() does the trick as well. Here comes a working code snippet to be placed in your theme's *.theme file. Replacy MYTHEME with the machine name of your theme.

/**
 * Implements hook_page_attachments_alter().
 */
function MYTHEME_page_attachments_alter(array &$attachments) {

  foreach ($attachments['#attached']['library'] as $key => $library) {

    // Install the Devel submodule Kint for debugging.
    // Check all libs:
    // ksm($attachments['#attached']['library']);

    // Here I disable the core base library.
    // Looks pretty ugly afterwards.
    if ($library == 'system/base') {
      unset($attachments['#attached']['library'][$key]);
    }

    // So for you it must be like following.
    // Simply try to find the right name via ksm($library);
    // or the other ksm() command from above.
    if ($library == 'layout_discovery/twocol') {
      unset($attachments['#attached']['library'][$key]);
    }
  }
}
2

I wanted to reduce count of http-requests and unset all unnecessary Drupal core css-files. Finally, this configuration works:

libraries-override:    
  layout_discovery/onecol: false

It should be added in file MY_THEME_NAME.info.yml
Do not forget "clear all caches" on 'admin/config/development/performance' page.

0

It was difficult to identify the correct library to exclude, using hook_css_alter made it easy for me to exclude a specific file.

function THEME_css_alter(&$css) {
  $cssfile= "core/themes/stable/css/core/vertical-tabs.css";
  if ($css[$cssfile]) {
    unset($css[$cssfile]);
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.