You are here

class RestConfigSubscriber in Drupal 8

A subscriber triggering a route rebuild when certain configuration changes.

Hierarchy

  • class \Drupal\rest\EventSubscriber\RestConfigSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of RestConfigSubscriber

1 string reference to 'RestConfigSubscriber'
rest.services.yml in core/modules/rest/rest.services.yml
core/modules/rest/rest.services.yml
1 service uses RestConfigSubscriber
rest.config_subscriber in core/modules/rest/rest.services.yml
Drupal\rest\EventSubscriber\RestConfigSubscriber

File

core/modules/rest/src/EventSubscriber/RestConfigSubscriber.php, line 13

Namespace

Drupal\rest\EventSubscriber
View source
class RestConfigSubscriber implements EventSubscriberInterface {

  /**
   * The router builder.
   *
   * @var \Drupal\Core\Routing\RouteBuilderInterface
   */
  protected $routerBuilder;

  /**
   * Constructs the RestConfigSubscriber.
   *
   * @param \Drupal\Core\Routing\RouteBuilderInterface $router_builder
   *   The router builder service.
   */
  public function __construct(RouteBuilderInterface $router_builder) {
    $this->routerBuilder = $router_builder;
  }

  /**
   * Informs the router builder a rebuild is needed when necessary.
   *
   * @param \Drupal\Core\Config\ConfigCrudEvent $event
   *   The Event to process.
   */
  public function onSave(ConfigCrudEvent $event) {
    $saved_config = $event
      ->getConfig();

    // @see \Drupal\rest\Plugin\rest\resource\EntityResource::permissions()
    if ($saved_config
      ->getName() === 'rest.settings' && $event
      ->isChanged('bc_entity_resource_permissions')) {
      $this->routerBuilder
        ->setRebuildNeeded();
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[ConfigEvents::SAVE][] = [
      'onSave',
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RestConfigSubscriber::$routerBuilder protected property The router builder.
RestConfigSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
RestConfigSubscriber::onSave public function Informs the router builder a rebuild is needed when necessary.
RestConfigSubscriber::__construct public function Constructs the RestConfigSubscriber.