@@ -108,6 +108,7 @@ public function onRedirect(QuantRedirectEvent $event) {
108108 */
109109 public function onOutput (QuantEvent $ event ) {
110110
111+ $ config = \Drupal::config ('quant.settings ' );
111112 $ path = $ event ->getLocation ();
112113 $ content = $ event ->getContents ();
113114 $ meta = $ event ->getMetadata ();
@@ -177,14 +178,40 @@ public function onOutput(QuantEvent $event) {
177178 $ fileOnDisk = str_replace ('/system/files ' , $ privatePath , $ file );
178179 }
179180
181+ // Check if the file has changed.
180182 if (isset ($ item ['existing_md5 ' ])) {
181183 if (file_exists ($ fileOnDisk ) && md5_file ($ fileOnDisk ) == $ item ['existing_md5 ' ]) {
182184 continue ;
183185 }
184186 }
185187
186- // If the file exists we send it directly to quant otherwise we add it
187- // to the queue to generate assets on the next run.
188+ // In Drupal 10.1, work around CSS/JS aggregation issues.
189+ // Only process internal CSS/JS files.
190+ $ check_file = (str_ends_with ($ file , 'css ' ) || str_ends_with ($ file , 'js ' )) && !str_starts_with ($ item ['original_path ' ], 'http ' );
191+ if (!file_exists ($ fileOnDisk ) && $ check_file ) {
192+
193+ // Do an HTTP request for the full file path to generate the file.
194+ // The `original_path` has the necessary query parameters.
195+ $ local_server = $ config ->get ('local_server ' ) ?: 'http://localhost ' ;
196+ $ url = $ local_server . $ item ['original_path ' ];
197+
198+ // Set the headers.
199+ $ headers ['Host ' ] = $ config ->get ('host_domain ' ) ?: $ _SERVER ['SERVER_NAME ' ];
200+
201+ // If using basic auth, the credentials must already be in the host.
202+ $ response = \Drupal::httpClient ()->get ($ url , [
203+ 'http_errors ' => FALSE ,
204+ 'headers ' => $ headers ,
205+ 'allow_redirects ' => FALSE ,
206+ 'verify ' => boolval ($ config ->get ('ssl_cert_verify ' )),
207+ ]);
208+ if ($ response ->getStatusCode () != 200 ) {
209+ $ this ->logger ->error ("Error retrieving file for route: $ url " );
210+ }
211+ }
212+
213+ // If the file exists, send it directly to Quant; otherwise, add it to the
214+ // queue to generate assets on the next run.
188215 if (file_exists ($ fileOnDisk )) {
189216 $ this ->eventDispatcher ->dispatch (new QuantFileEvent ($ fileOnDisk , $ item ['full_path ' ] ?? $ file ), QuantFileEvent::OUTPUT );
190217 }
@@ -204,7 +231,7 @@ public function onOutput(QuantEvent $event) {
204231 $ xpath = new \DOMXPath ($ document );
205232
206233 $ xpath_selectors = [];
207- $ links_config = \Drupal:: config ( ' quant.settings ' ) ->get ('xpath_selectors ' );
234+ $ links_config = $ config ->get ('xpath_selectors ' );
208235
209236 foreach (explode (PHP_EOL , $ links_config ) as $ links_line ) {
210237 $ xpath_selectors [] = trim ($ links_line );
0 commit comments