comparison core/modules/rest/src/EventSubscriber/RestConfigSubscriber.php @ 0:4c8ae668cc8c

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