TextimagePathProcessor.php in Textimage 8.3
File
src/PathProcessor/TextimagePathProcessor.php
View source
<?php
namespace Drupal\textimage\PathProcessor;
use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Symfony\Component\HttpFoundation\Request;
class TextimagePathProcessor implements InboundPathProcessorInterface {
protected $streamWrapperManager;
public function __construct(StreamWrapperManagerInterface $stream_wrapper_manager) {
$this->streamWrapperManager = $stream_wrapper_manager;
}
public function processInbound($path, Request $request) {
$public_directory_path = $this->streamWrapperManager
->getViaScheme('public')
->getDirectoryPath();
if (strpos($path, '/' . $public_directory_path . '/textimage_store/') === 0) {
$path_prefix = '/' . $public_directory_path . '/textimage_store';
$rest = preg_replace('|^' . preg_quote($path_prefix . '/', '|') . '|', '', $path);
$request->query
->set('file', $rest);
return $path_prefix;
}
elseif (strpos($path, '/system/files/textimage_store/') === 0) {
$path_prefix = '/system/files/textimage_store';
$rest = preg_replace('|^' . preg_quote($path_prefix . '/', '|') . '|', '', $path);
$request->query
->set('file', $rest);
return $path_prefix;
}
elseif (strpos($path, '/' . $public_directory_path . '/textimage/') === 0) {
$path_prefix = '/' . $public_directory_path . '/textimage';
$rest = preg_replace('|^' . preg_quote($path_prefix . '/', '|') . '|', '', $path);
if (substr_count($rest, '/') >= 1) {
list($image_style, $text) = explode('/', $rest, 2);
$request->query
->set('text', $text);
return $path_prefix . '/' . $image_style;
}
else {
return $path;
}
}
else {
return $path;
}
}
}