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'
1 service uses ConfigRebuildRoutes
File
- src/
EventSubscriber/ ConfigRebuildRoutes.php, line 17
Namespace
Drupal\acquia_contenthub\EventSubscriberView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigRebuildRoutes:: |
protected | property | The Route Builder. | |
ConfigRebuildRoutes:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
ConfigRebuildRoutes:: |
public | function | Rebuild routes whenever we save new configuration. | |
ConfigRebuildRoutes:: |
public | function | Public constructor. |