Patched to Drupal 8.4.8 level. See https://www.drupal.org/sa-core-2018-004 and patch...
[yaffs-website] / web / core / lib / Drupal / Core / PathProcessor / PathProcessorFront.php
1 <?php
2
3 namespace Drupal\Core\PathProcessor;
4
5 use Drupal\Core\Config\ConfigFactoryInterface;
6 use Drupal\Core\Render\BubbleableMetadata;
7 use Symfony\Component\HttpFoundation\Request;
8 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
9
10 /**
11  * Processes the inbound path by resolving it to the front page if empty.
12  *
13  * @todo - remove ::processOutbound() when we remove UrlGenerator::fromPath().
14  */
15 class PathProcessorFront implements InboundPathProcessorInterface, OutboundPathProcessorInterface {
16
17   /**
18    * A config factory for retrieving required config settings.
19    *
20    * @var \Drupal\Core\Config\ConfigFactoryInterface
21    */
22   protected $config;
23
24   /**
25    * Constructs a PathProcessorFront object.
26    *
27    * @param \Drupal\Core\Config\ConfigFactoryInterface $config
28    *   A config factory for retrieving the site front page configuration.
29    */
30   public function __construct(ConfigFactoryInterface $config) {
31     $this->config = $config;
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   public function processInbound($path, Request $request) {
38     if ($path === '/') {
39       $path = $this->config->get('system.site')->get('page.front');
40       if (empty($path)) {
41         // We have to return a valid path but / won't be routable and config
42         // might be broken so stop execution.
43         throw new NotFoundHttpException();
44       }
45     }
46     return $path;
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
53     // The special path '<front>' links to the default front page.
54     if ($path === '/<front>') {
55       $path = '/';
56     }
57     return $path;
58   }
59
60 }