You are here

class ConfigRebuildRoutes in Acquia Content Hub 8

A subscriber to rebuild routes whenever there is a change in configuration.

Class ConfigRebuildRoutes.

@package Drupal\acquia_contenthub\EventSubscriber

Hierarchy

  • class \Drupal\acquia_contenthub\EventSubscriber\ConfigRebuildRoutes implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of ConfigRebuildRoutes

1 string reference to 'ConfigRebuildRoutes'
acquia_contenthub.services.yml in ./acquia_contenthub.services.yml
acquia_contenthub.services.yml
1 service uses ConfigRebuildRoutes
acquia_contenthub.config_rebuild_routes in ./acquia_contenthub.services.yml
Drupal\acquia_contenthub\EventSubscriber\ConfigRebuildRoutes

File

src/EventSubscriber/ConfigRebuildRoutes.php, line 17

Namespace

Drupal\acquia_contenthub\EventSubscriber
View source
class ConfigRebuildRoutes implements EventSubscriberInterface {

  /**
   * The Route Builder.
   *
   * @var \Drupal\Core\Routing\RouteBuilderInterface
   */
  protected $routeBuilder;

  /**
   * Public constructor.
   *
   * @param \Drupal\Core\Routing\RouteBuilderInterface $route_builder
   *   The Route Builder service.
   */
  public function __construct(RouteBuilderInterface $route_builder) {
    $this->routeBuilder = $route_builder;
  }

  /**
   * Rebuild routes whenever we save new configuration.
   *
   * @param \Drupal\Core\Config\ConfigCrudEvent $event
   *   The Event to process.
   */
  public function onSave(ConfigCrudEvent $event) {

    // Changing the content hub configuration entities that control the entity
    // types that are "exportable" to content hub requires that we rebuild
    // the routes to make those new routes available for the format
    // 'acquia_contenthub_cdf'.
    // We do not need to invalidate tags because any request coming to the
    // routes provided by acquia_contenthub are added the 'cache tag' of the
    // configuration entity that provided the response. Then if that config
    // entity is saved, its cache tag is automatically invalidated and thus
    // the response to the format 'acquia_contenthub_cdf' of the entity that
    // is served through it.
    if (strpos($event
      ->getConfig()
      ->getName(), 'acquia_contenthub.entity.') !== FALSE) {
      $this->routeBuilder
        ->setRebuildNeeded();
    }
  }

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

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigRebuildRoutes::$routeBuilder protected property The Route Builder.
ConfigRebuildRoutes::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
ConfigRebuildRoutes::onSave public function Rebuild routes whenever we save new configuration.
ConfigRebuildRoutes::__construct public function Public constructor.