You are here

public function ResponseSubscriber::forceAbsolutePaths in Advanced CSS/JS Aggregation 8.4

Same name and namespace in other branches
  1. 8.3 src/EventSubscriber/ResponseSubscriber.php \Drupal\advagg\EventSubscriber\ResponseSubscriber::forceAbsolutePaths()

Force absolute paths.

Parameters

\Symfony\Component\HttpKernel\Event\FilterResponseEvent $response: The response event object.

File

src/EventSubscriber/ResponseSubscriber.php, line 80

Class

ResponseSubscriber
Respond to event processes.

Namespace

Drupal\advagg\EventSubscriber

Code

public function forceAbsolutePaths(FilterResponseEvent $response) {

  // Skip if not enabled.
  if (!$this->config
    ->get('path.convert.absolute')) {
    return;
  }
  $response = $response
    ->getResponse();

  // Only process Html Responses.
  if (!$response instanceof HtmlResponse) {
    return;
  }
  $content = $response
    ->getContent();
  $pattern = '/(<script src="|url\\("|rel="stylesheet" href=")(\\/[a-zA-Z0-0].*")/';
  $response
    ->setContent(preg_replace_callback($pattern, [
    $this,
    'forceAbsolutePathsCallback',
  ], $content));
}