DevelRouteSubscriber.php in Search API Solr 8
File
src/Routing/DevelRouteSubscriber.php
View source
<?php
namespace Drupal\search_api_solr\Routing;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Routing\RouteSubscriberBase;
use Drupal\Core\Routing\RoutingEvents;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class DevelRouteSubscriber extends RouteSubscriberBase {
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entity_manager) {
$this->entityTypeManager = $entity_manager;
}
protected function alterRoutes(RouteCollection $collection) {
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type_id => $entity_type) {
if ($route = $this
->getDevelSolrRoute($entity_type)) {
$collection
->add("entity.{$entity_type_id}.devel_solr", $route);
}
}
}
protected function getDevelSolrRoute(EntityTypeInterface $entity_type) {
if ($devel_solr = $entity_type
->getLinkTemplate('devel-solr')) {
$entity_type_id = $entity_type
->id();
$route = new Route($devel_solr);
$route
->addDefaults([
'_controller' => '\\Drupal\\search_api_solr\\Controller\\DevelController::entitySolr',
'_title' => 'Devel Solr',
])
->addRequirements([
'_permission' => 'access devel information',
])
->setOption('_admin_route', TRUE)
->setOption('_devel_entity_type_id', $entity_type_id)
->setOption('parameters', [
$entity_type_id => [
'type' => 'entity:' . $entity_type_id,
],
]);
return $route;
}
}
public static function getSubscribedEvents() {
$events = parent::getSubscribedEvents();
$events[RoutingEvents::ALTER] = array(
'onAlterRoutes',
100,
);
return $events;
}
}