sites_group_overrides-1.x-dev/src/Plugin/Derivative/OverridesLocalTask.php
src/Plugin/Derivative/OverridesLocalTask.php
<?php
namespace Drupal\sites_group_overrides\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\sites_group\SitesGroupServiceInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Deriver for overrides local tasks.
*/
class OverridesLocalTask extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
/**
* Constructs a SitesGroupContentPushLocalTask object.
*
* @param \Drupal\sites_group\SitesGroupServiceInterface $sitesGroupService
* The sites_group service.
*/
public function __construct(
protected readonly SitesGroupServiceInterface $sitesGroupService
) {}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static(
$container->get('sites_group.service'),
);
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$this->derivatives = [];
foreach ($this->sitesGroupService->getGroupSiteEntityTypeIds() as $entity_type_id) {
$this->derivatives["$entity_type_id.domain_content_push"] = [
'route_name' => "entity.$entity_type_id.overrides",
'title' => $this->t('Overrides'),
'base_route' => "entity.$entity_type_id.canonical",
'weight' => 100,
] + $base_plugin_definition;
}
return $this->derivatives;
}
}
