Score:1

What's the equivalent of drupal_build_css_cache()?

de flag

Our client uses an external website for some of their pages. This provider does not enable us to theme their website directly, but they do allow us to load a single JS file from the Drupal site that we maintain.

We create this JS file through a Drupal route/controller, assembling the header and footer blocks, including CSS and JS files, and inserting them into the content by appending them to the appropriate elements.

We've ported all of the functionality to Drupal 8 from 7 and it's more efficient than before. However, we used to use drupal_build_css_cache() to aggregate the subset of CSS files from themes and modules that we need before injecting them into the website's head.

Keeping in mind that all we're delivering to the external website is a single JS file (so we can't attach a library in the usual way), is there a way of programatically creating an aggregated CSS file in Drupal 8, as that function used to do?

Score:2
fr flag

drupal_build_css_cache() is a Drupal 7 function that was removed very early in the Drupal 8 development cycle. The change notices back then weren't very good, so simply searching for that function name won't find anything. (Change notices may be found at https://www.drupal.org/list-changes). The relevant change notice is Pluggable CSS & JS preprocessing (aggregation/minification)

This does not say what drupal_build_css_cache() was replaced with, but searching the code of the patch that removed the function shows that the code of that function is now in the asset.css.collection_optimizer service (implemented in \Drupal\Core\Asset\CssCollectionOptimizer)

fr flag
The question does not ask about clearing caches, it asks about aggregating CSS. Your answer does not address the question.
Geat avatar
de flag
As anonymous states above, that's not even remotely close to what I was asking.
misterdidi avatar
de flag
Your answer explains how to use core functions to clear the cache. This is not what OP asked for. Thanks for taking time to post an answer anyway.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.