Mercurial > hg > isophonics-drupal-site
annotate core/modules/rest/src/EventSubscriber/RestConfigSubscriber.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 1fec387a4317 |
children |
rev | line source |
---|---|
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@14 | 40 // @see \Drupal\rest\Plugin\rest\resource\EntityResource::permissions() |
Chris@0 | 41 if ($saved_config->getName() === 'rest.settings' && $event->isChanged('bc_entity_resource_permissions')) { |
Chris@0 | 42 $this->routerBuilder->setRebuildNeeded(); |
Chris@0 | 43 } |
Chris@0 | 44 } |
Chris@0 | 45 |
Chris@0 | 46 /** |
Chris@0 | 47 * {@inheritdoc} |
Chris@0 | 48 */ |
Chris@0 | 49 public static function getSubscribedEvents() { |
Chris@0 | 50 $events[ConfigEvents::SAVE][] = ['onSave']; |
Chris@0 | 51 return $events; |
Chris@0 | 52 } |
Chris@0 | 53 |
Chris@0 | 54 } |