public function S3fsAdvAggSubscriber::processAssetContent in S3 File System 4.0.x
Same name and namespace in other branches
- 8.3 src/EventSubscriber/S3fsAdvAggSubscriber.php \Drupal\s3fs\EventSubscriber\S3fsAdvAggSubscriber::processAssetContent()
Process asset content for make urls compatible.
Parameters
\Drupal\advagg\Asset\AssetOptimizationEvent $asset: Asset to be processed.
Return value
mixed preg_replace_callback() formated return.
See also
\Drupal\Core\Asset\CssOptimizer::processFile()
1 call to S3fsAdvAggSubscriber::processAssetContent()
- S3fsAdvAggSubscriber::updateUrls in src/
EventSubscriber/ S3fsAdvAggSubscriber.php - Update asset urls to access static files that they aren't in S3 bucket.
File
- src/
EventSubscriber/ S3fsAdvAggSubscriber.php, line 68
Class
- S3fsAdvAggSubscriber
- Subscribe to asset optimization events and update assets urls.
Namespace
Drupal\s3fs\EventSubscriberCode
public function processAssetContent(AssetOptimizationEvent $asset) {
$content = $asset
->getContent();
$css_asset = $asset
->getAsset();
// Get the parent directory of this file, relative to the Drupal root.
$css_base_path = substr($css_asset['data'], 0, strrpos($css_asset['data'], '/'));
// Store base path.
$this->rewriteFileURIBasePath = $css_base_path . '/';
// Restore asset urls.
$content = str_replace('/' . $this->rewriteFileURIBasePath, "", $content);
return preg_replace_callback('/url\\(\\s*[\'"]?(?![a-z]+:|\\/+)([^\'")]+)[\'"]?\\s*\\)/i', [
$this,
'rewriteFileURI',
], $content);
}