You are here

class OgLocalTask in Organic groups 8

Provides local task definitions for all entity bundles.

Hierarchy

Expanded class hierarchy of OgLocalTask

1 file declares its use of OgLocalTask
OgLocalTaskTest.php in tests/src/Unit/OgLocalTaskTest.php
1 string reference to 'OgLocalTask'
og.links.task.yml in ./og.links.task.yml
og.links.task.yml

File

src/Plugin/Derivative/OgLocalTask.php, line 17

Namespace

Drupal\og\Plugin\Derivative
View source
class OgLocalTask extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;

  /**
   * The group type manager.
   *
   * @var \Drupal\og\GroupTypeManagerInterface
   */
  protected $groupTypeManager;

  /**
   * Route provider object.
   *
   * @var \Drupal\Core\Routing\RouteProvider
   */
  protected $routProvider;

  /**
   * Creates an OgLocalTask object.
   *
   * @param \Drupal\og\GroupTypeManagerInterface $group_type_manager
   *   The group type manager.
   * @param \Drupal\Core\Routing\RouteProvider $route_provider
   *   The route provider services.
   */
  public function __construct(GroupTypeManagerInterface $group_type_manager, RouteProvider $route_provider) {
    $this->groupTypeManager = $group_type_manager;
    $this->routProvider = $route_provider;
  }

  /**
   * {@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->routProvider
        ->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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
OgLocalTask::$groupTypeManager protected property The group type manager.
OgLocalTask::$routProvider protected property Route provider object.
OgLocalTask::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
OgLocalTask::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
OgLocalTask::__construct public function Creates an OgLocalTask object.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.