sites_group_overrides-1.x-dev/src/Routing/SitesGroupOverrides.php
src/Routing/SitesGroupOverrides.php
<?php
namespace Drupal\sites_group_overrides\Routing;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\sites_group\SitesGroupServiceInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Route;
/**
* Defines dynamic routes.
*/
class SitesGroupOverrides implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* Constructs a SitesGroupContentPushLocalTask object.
*
* @param \Drupal\sites_group\SitesGroupServiceInterface $sitesGroupService
* The sites_group service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
*/
public function __construct(
protected readonly SitesGroupServiceInterface $sitesGroupService,
protected readonly EntityTypeManagerInterface $entityTypeManager
) {}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('sites_group.service'),
$container->get('entity_type.manager')
);
}
/**
* Provides dynamic routes.
*/
public function routes() {
$routes = [];
// Declares a single route under the name 'example.content'.
// Returns an array of Route objects.
foreach ($this->sitesGroupService->getGroupSiteEntityTypeIds() as $entity_type) {
$canonical = $this->entityTypeManager->getStorage($entity_type)->getEntityType()->getLinkTemplate('canonical');
$routes["entity.{$entity_type}.overrides"] = new Route(
$canonical . '/overrides',
[
'_form' => \Drupal\sites_group_overrides\Form\SitesGroupOverridesForm::class,
'_title_callback' => \Drupal\sites_group_overrides\Form\SitesGroupOverridesForm::class . '::title',
],
[
'_custom_access' => \Drupal\sites_group_overrides\Form\SitesGroupOverridesForm::class . '::access',
],
[
'parameters' => [
$entity_type => ['type' => "entity:$entity_type"],
],
'_group_operation_route' => TRUE,
]
);
}
return $routes;
}
}
