- Issue created by @vasyok
- Assigned to abhiyanshu
- 🇮🇳India abhiyanshu
@VasyOK,
It seems like you've made some indentation issue.
Proper indentation is crucial for the code to be parsed correctly.Please follow-up with the below code, Hope it works.
Your code should look like this with correct indentation:
libraries-override:
jquery_ui/core:
css:
component:
assets/vendor/jquery.ui/themes/base/theme.css: false
assets/vendor/jquery.ui/themes/base/accordion.css: falseNOTE :-
In the above corrected code,
The component section is properly indented under css.
The CSS files you want to disable (theme.css and accordion.css) are correctly indented under component.
With this indentation, Drupal should be able to recognize and apply the libraries-override configuration as intended, disabling the specified CSS files from the jQuery UI library. - 🇺🇦Ukraine vasyok
Solution referensed from https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21...
add function to mytheme.theme
function mytheme_css_alter(&$css, \Drupal\Core\Asset\AttachedAssetsInterface $assets, \Drupal\Core\Language\LanguageInterface $language) { unset($css['modules/contrib/jquery_ui/assets/vendor/jquery.ui/themes/base/theme.css']); unset($css['core/assets/vendor/jquery.ui/themes/base/theme.css']); unset($css['modules/contrib/jquery_ui/assets/vendor/jquery.ui/themes/base/accordion.css']); }
- @abhiyanshu_rawat opened merge request.
- 🇮🇳India abhiyanshu
Hi @VasyOk,
However, based on your reference,
Here's a more flexible and maintenance-friendly approach using the array_filter function to conditionally unset CSS files./** * Implements hook_css_alter(). */ function mytheme_css_alter(&$css, \Drupal\Core\Asset\AttachedAssetsInterface $assets) { // List the CSS files you want to remove. $css_to_remove = [ 'modules/contrib/jquery_ui/assets/vendor/jquery.ui/themes/base/theme.css', 'core/assets/vendor/jquery.ui/themes/base/theme.css', 'modules/contrib/jquery_ui/assets/vendor/jquery.ui/themes/base/accordion.css', ]; // Unset the specified CSS files. $css = array_filter($css, function ($key) use ($css_to_remove) { return !in_array($key, $css_to_remove); }, ARRAY_FILTER_USE_KEY); }
It uses an array of file paths to remove and then filters the $css array to keep only the files that are not in the list of files to remove.
Make sure to clear the Drupal cache after adding or updating this code in your theme's mytheme.theme file.
The above code allows you to easily add or remove CSS files from the list as needed without altering the structure of the code. - Status changed to Fixed
over 1 year ago 12:17pm 28 September 2023 Automatically closed - issue fixed for 2 weeks with no activity.
- Status changed to Fixed
over 1 year ago 1:28pm 18 October 2023