PathProcessorFiles.php 766 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace Drupal\system\PathProcessor;
  3. use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
  4. use Symfony\Component\HttpFoundation\Request;
  5. /**
  6. * Defines a path processor to rewrite file URLs.
  7. *
  8. * As the route system does not allow arbitrary amount of parameters convert
  9. * the file path to a query parameter on the request.
  10. */
  11. class PathProcessorFiles implements InboundPathProcessorInterface {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public function processInbound($path, Request $request) {
  16. if (strpos($path, '/system/files/') === 0 && !$request->query->has('file')) {
  17. $file_path = preg_replace('|^\/system\/files\/|', '', $path);
  18. $request->query->set('file', $file_path);
  19. return '/system/files';
  20. }
  21. return $path;
  22. }
  23. }