public function PathProcessorImageStyles::processInbound in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/image/src/PathProcessor/PathProcessorImageStyles.php \Drupal\image\PathProcessor\PathProcessorImageStyles::processInbound()
Processes the inbound path.
Parameters
string $path: The path to process, with a leading slash.
\Symfony\Component\HttpFoundation\Request $request: The HttpRequest object representing the current request.
Return value
string The processed path.
Overrides InboundPathProcessorInterface::processInbound
File
- core/
modules/ image/ src/ PathProcessor/ PathProcessorImageStyles.php, line 51 - Contains \Drupal\image\PathProcessor\PathProcessorImageStyles.
Class
- PathProcessorImageStyles
- Defines a path processor to rewrite image styles URLs.
Namespace
Drupal\image\PathProcessorCode
public function processInbound($path, Request $request) {
$directory_path = $this->streamWrapperManager
->getViaScheme('public')
->getDirectoryPath();
if (strpos($path, '/' . $directory_path . '/styles/') === 0) {
$path_prefix = '/' . $directory_path . '/styles/';
}
elseif (strpos($path, '/system/files/styles/') === 0) {
$path_prefix = '/system/files/styles/';
}
else {
return $path;
}
// Strip out path prefix.
$rest = preg_replace('|^' . preg_quote($path_prefix, '|') . '|', '', $path);
// Get the image style, scheme and path.
if (substr_count($rest, '/') >= 2) {
list($image_style, $scheme, $file) = explode('/', $rest, 3);
// Set the file as query parameter.
$request->query
->set('file', $file);
return $path_prefix . $image_style . '/' . $scheme;
}
else {
return $path;
}
}