Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Core / Routing / Enhancer / EntityRevisionRouteEnhancer.php
1 <?php
2
3 namespace Drupal\Core\Routing\Enhancer;
4
5 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
6 use Symfony\Component\HttpFoundation\Request;
7 use Symfony\Component\Routing\Route;
8
9 /**
10  * Adds _entity_revision to the request attributes, if possible.
11  */
12 class EntityRevisionRouteEnhancer implements RouteEnhancerInterface {
13
14   /**
15    * {@inheritdoc}
16    */
17   public function applies(Route $route) {
18     // Check whether there is any entity revision parameter.
19     $parameters = $route->getOption('parameters') ?: [];
20     foreach ($parameters as $info) {
21       if (isset($info['type']) && strpos($info['type'], 'entity_revision:') === 0) {
22         return TRUE;
23       }
24     }
25     return FALSE;
26   }
27
28   /**
29    * {@inheritdoc}
30    */
31   public function enhance(array $defaults, Request $request) {
32     /** @var \Symfony\Component\Routing\Route $route */
33     $route = $defaults[RouteObjectInterface::ROUTE_OBJECT];
34     $options = $route->getOptions();
35     if (isset($options['parameters'])) {
36       foreach ($options['parameters'] as $name => $details) {
37         if (!empty($details['type']) && strpos($details['type'], 'entity_revision:') !== FALSE) {
38           $defaults['_entity_revision'] = $defaults[$name];
39           break;
40         }
41       }
42     }
43
44     return $defaults;
45   }
46
47 }