og-8.x-1.x-dev/src/Plugin/Derivative/OgLocalTask.php

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

declare(strict_types=1);

namespace Drupal\og\Plugin\Derivative;

use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\og\GroupTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Provides local task definitions for all entity bundles.
 */
class OgLocalTask extends DeriverBase implements ContainerDeriverInterface {

  use StringTranslationTrait;

  public function __construct(
    protected readonly GroupTypeManagerInterface $groupTypeManager,
    protected readonly RouteProviderInterface $routeProvider,
  ) {}

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

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

    foreach (array_keys($this->groupTypeManager->getGroupMap()) as $entity_type_id) {
      $route_name = "entity.$entity_type_id.og_admin_routes";

      if (!$this->routeProvider->getRoutesByNames([$route_name])) {
        // Route not found.
        continue;
      }

      $derivatives[$entity_type_id . '.og_admin_routes'] = [
        'route_name' => $route_name,
        'title' => $this->t('Group'),
        'base_route' => 'entity.' . $entity_type_id . '.canonical',
        'weight' => 50,
      ];
    }

    // @todo Coder throws a false positive for this line. Remove this once the
    //   issue is fixed in the Coder project.
    // @see https://www.drupal.org/project/coder/issues/3065679
    // @codingStandardsIgnoreLine
    foreach ($derivatives as &$entry) {
      // @codingStandardsIgnoreLine
      $entry += $base_plugin_definition;
    }

    return $derivatives;
  }

}

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

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