Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\rest\EventSubscriber;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Config\ConfigCrudEvent;
|
Chris@0
|
6 use Drupal\Core\Config\ConfigEvents;
|
Chris@0
|
7 use Drupal\Core\Routing\RouteBuilderInterface;
|
Chris@0
|
8 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
Chris@0
|
9
|
Chris@0
|
10 /**
|
Chris@0
|
11 * A subscriber triggering a route rebuild when certain configuration changes.
|
Chris@0
|
12 */
|
Chris@0
|
13 class RestConfigSubscriber implements EventSubscriberInterface {
|
Chris@0
|
14
|
Chris@0
|
15 /**
|
Chris@0
|
16 * The router builder.
|
Chris@0
|
17 *
|
Chris@0
|
18 * @var \Drupal\Core\Routing\RouteBuilderInterface
|
Chris@0
|
19 */
|
Chris@0
|
20 protected $routerBuilder;
|
Chris@0
|
21
|
Chris@0
|
22 /**
|
Chris@0
|
23 * Constructs the RestConfigSubscriber.
|
Chris@0
|
24 *
|
Chris@0
|
25 * @param \Drupal\Core\Routing\RouteBuilderInterface $router_builder
|
Chris@0
|
26 * The router builder service.
|
Chris@0
|
27 */
|
Chris@0
|
28 public function __construct(RouteBuilderInterface $router_builder) {
|
Chris@0
|
29 $this->routerBuilder = $router_builder;
|
Chris@0
|
30 }
|
Chris@0
|
31
|
Chris@0
|
32 /**
|
Chris@0
|
33 * Informs the router builder a rebuild is needed when necessary.
|
Chris@0
|
34 *
|
Chris@0
|
35 * @param \Drupal\Core\Config\ConfigCrudEvent $event
|
Chris@0
|
36 * The Event to process.
|
Chris@0
|
37 */
|
Chris@0
|
38 public function onSave(ConfigCrudEvent $event) {
|
Chris@0
|
39 $saved_config = $event->getConfig();
|
Chris@0
|
40 if ($saved_config->getName() === 'rest.settings' && $event->isChanged('bc_entity_resource_permissions')) {
|
Chris@0
|
41 $this->routerBuilder->setRebuildNeeded();
|
Chris@0
|
42 }
|
Chris@0
|
43 }
|
Chris@0
|
44
|
Chris@0
|
45 /**
|
Chris@0
|
46 * {@inheritdoc}
|
Chris@0
|
47 */
|
Chris@0
|
48 public static function getSubscribedEvents() {
|
Chris@0
|
49 $events[ConfigEvents::SAVE][] = ['onSave'];
|
Chris@0
|
50 return $events;
|
Chris@0
|
51 }
|
Chris@0
|
52
|
Chris@0
|
53 }
|