protected function processFile($css_asset) { $contents =
$this->
loadFile($css_asset['data'
], TRUE
);
if ($css_asset['media'
] !== 'print' &&
$css_asset['media'
] !== 'all'
) { $contents = '@media ' .
$css_asset['media'
] . '{' .
$contents . '}' . "\n";
} $contents =
$this->
clean($contents);
// 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 . '/';
// Anchor all paths in the CSS with its base URL, ignoring external and absolute paths and paths starting with '#'.
return preg_replace_callback('/url\(\s*[\'"]?(?![a-z]+:|\/+|#|%23)([^\'")]+)[\'"]?\s*\)/i',
[$this, 'rewriteFileURI'
],
$contents);
} /**
* Loads the stylesheet and resolves all @import commands.
*
* Loads a stylesheet and replaces @import commands with the contents of the
* imported file. Use this instead of file_get_contents when processing
* stylesheets.
*
* The returned contents are compressed removing white space and comments only
* when CSS aggregation is enabled. This optimization will not apply for
* color.module enabled themes with CSS aggregation turned off.
*
* Note: the only reason this method is public is so color.module can call it;
* it is not on the AssetOptimizerInterface, so future refactorings can make
* it protected.
*
* @param $file
* Name of the stylesheet to be processed.
* @param $optimize
* Defines if CSS contents should be compressed or not.
* @param $reset_basepath
* Used internally to facilitate recursive resolution of @import commands.
*
* @return string
* Contents of the stylesheet, including any resolved @import commands.
*/