function ResourceRoutes::onDynamicRouteEvent

Same name in other branches
  1. 9 core/modules/rest/src/Routing/ResourceRoutes.php \Drupal\rest\Routing\ResourceRoutes::onDynamicRouteEvent()
  2. 10 core/modules/rest/src/Routing/ResourceRoutes.php \Drupal\rest\Routing\ResourceRoutes::onDynamicRouteEvent()
  3. 11.x core/modules/rest/src/Routing/ResourceRoutes.php \Drupal\rest\Routing\ResourceRoutes::onDynamicRouteEvent()

Alters existing routes for a specific collection.

Parameters

\Drupal\Core\Routing\RouteBuildEvent $event: The route build event.

Return value

array

File

core/modules/rest/src/Routing/ResourceRoutes.php, line 64

Class

ResourceRoutes
Subscriber for REST-style routes.

Namespace

Drupal\rest\Routing

Code

public function onDynamicRouteEvent(RouteBuildEvent $event) {
    // Iterate over all enabled REST resource config entities.
    
    /** @var \Drupal\rest\RestResourceConfigInterface[] $resource_configs */
    $resource_configs = $this->resourceConfigStorage
        ->loadMultiple();
    foreach ($resource_configs as $resource_config) {
        if ($resource_config->status()) {
            $resource_routes = $this->getRoutesForResourceConfig($resource_config);
            $event->getRouteCollection()
                ->addCollection($resource_routes);
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.