sites_group_overrides-1.x-dev/src/Plugin/Derivative/LocalTask.php

src/Plugin/Derivative/LocalTask.php
<?php

namespace Drupal\sites_group_overrides\Plugin\Derivative;

use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\sites_group_overrides\SitesGroupOverridesServiceInterface;
use Drupal\sites_group_overrides\GroupRelationshipFieldConfigSyncInterface;

/**
 * Provides local task definitions for all entity bundles.
 *
 * @see \Drupal\devel\Controller\EntityDebugController
 * @see \Drupal\devel\Routing\RouteSubscriber
 */
class LocalTask extends DeriverBase implements ContainerDeriverInterface {

  use StringTranslationTrait;

  /**
   * Constructs a LocalTask object.
   *
   * @param GroupRelationshipFieldConfigSyncInterface $groupRelationshipFieldConfigSync
   *   The groupRelationshipFieldConfigSync service.
   */
  public function __construct(
    private readonly SitesGroupOverridesServiceInterface $sitesGroupOverridesService,
    ) {  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static(
      $container->get('sites_group_overrides.service')
    );
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $this->derivatives = [];

    foreach ($this->sitesGroupOverridesService->getSourceBundleEntityTypes() as $entity_type_id => $entity_type) {
      if ($entity_type->hasLinkTemplate('edit-form')) {
        $this->derivatives["$entity_type_id.sync_tab"] = [
          'route_name' => "entity.$entity_type_id.sites_group_overrides",
          'title' => $this->t('Sites group overrides'),
          'base_route' => "entity.$entity_type_id.edit_form",
          'weight' => 100,
        ];
      }
    }

    foreach ($this->derivatives as &$entry) {
      $entry += $base_plugin_definition;
    }

    return $this->derivatives;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc