gamify-1.1.x-dev/modules/userpoints/src/Plugin/Derivative/DynamicLocalTasks.php

modules/userpoints/src/Plugin/Derivative/DynamicLocalTasks.php
<?php

namespace Drupal\userpoints\Plugin\Derivative;

use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Defines dynamic local tasks for Userpoints.
 */
class DynamicLocalTasks extends DeriverBase implements ContainerDeriverInterface {

  use StringTranslationTrait;

  /**
   * The module config.
   *
   * @var \Drupal\Core\Config\ImmutableConfig
   */
  protected $config;

  /**
   * Entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Constructs a new DynamicLocalTasks object.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
   *   The config factory object.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
   *   The entity type manager.
   *   The stream wrapper manager service.
   */
  public function __construct(
    ConfigFactoryInterface $configFactory,
    EntityTypeManagerInterface $entityTypeManager
  ) {
    $this->config = $configFactory->get('userpoints.settings');
    $this->entityTypeManager = $entityTypeManager;
  }

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

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $bundle_info = $this->config->get('userpoints_ui_bundles');
    if (empty($bundle_info)) {
      $bundle_info = [];
    }
    foreach ($bundle_info as $entity_type_id => $bundles) {
      $key = "entity.$entity_type_id.userpoints";
      $this->derivatives[$key] = [
        'entity_type' => $entity_type_id,
        'title' => $this->t('Points'),
        'route_name' => $key,
        'base_route' => "entity.$entity_type_id.canonical",
      ] + $base_plugin_definition;
    }

    return parent::getDerivativeDefinitions($base_plugin_definition);
  }

}

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

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