sites_group_overrides-1.x-dev/src/EventSubscriber/RouteSubscriber.php
src/EventSubscriber/RouteSubscriber.php
<?php declare(strict_types = 1);
namespace Drupal\sites_group_overrides\EventSubscriber;
use Symfony\Component\Routing\Route;
use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;
use Drupal\sites_group_overrides\Form\BaseFieldConfigForm;
use Drupal\sites_group_overrides\SitesGroupOverridesServiceInterface;
/**
* Route subscriber.
*/
final class RouteSubscriber extends RouteSubscriberBase {
/**
* Constructs a RouteSubscriber object.
*/
public function __construct(
private readonly SitesGroupOverridesServiceInterface $sitesGroupOverridesService,
) {}
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection): void {
foreach ($this->sitesGroupOverridesService->getSourceBundleEntityTypes() as $entity_type_id => $entity_type) {
// @todo use field_ui_base_route setting
if ($entity_type->hasLinkTemplate('edit-form')) {
$route = new Route($entity_type->getLinkTemplate('edit-form') . '/field-sync', [
'_form' => BaseFieldConfigForm::class
],
[
'_permission' => 'adminsister field sync',
]
);
$collection->add("entity.$entity_type_id.sites_group_overrides", $route);
}
}
}
}
