You are here

class EntityUsageLocalTask in Entity Usage 8

Same name and namespace in other branches
  1. 8.4 src/Plugin/Derivative/EntityUsageLocalTask.php \Drupal\entity_usage\Plugin\Derivative\EntityUsageLocalTask
  2. 8.2 src/Plugin/Derivative/EntityUsageLocalTask.php \Drupal\entity_usage\Plugin\Derivative\EntityUsageLocalTask
  3. 8.3 src/Plugin/Derivative/EntityUsageLocalTask.php \Drupal\entity_usage\Plugin\Derivative\EntityUsageLocalTask

Provides local task definitions for all entity types.

Hierarchy

Expanded class hierarchy of EntityUsageLocalTask

1 string reference to 'EntityUsageLocalTask'
entity_usage.links.task.yml in ./entity_usage.links.task.yml
entity_usage.links.task.yml

File

src/Plugin/Derivative/EntityUsageLocalTask.php, line 15

Namespace

Drupal\entity_usage\Plugin\Derivative
View source
class EntityUsageLocalTask extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;

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

  /**
   * The config factory service.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $config;

  /**
   * Creates an EntityUsageLocalTask object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity manager.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config
   *   The config factory service.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config) {
    $this->entityTypeManager = $entity_type_manager;
    $this->config = $config;
  }

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

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $this->derivatives = [];
    $configured_types = $this->config
      ->get('entity_usage.settings')
      ->get('local_task_enabled_entity_types') ?: [];
    foreach ($this->entityTypeManager
      ->getDefinitions() as $entity_type_id => $entity_type) {
      if ($entity_type
        ->hasLinkTemplate('canonical')) {
        if (!in_array($entity_type_id, $configured_types)) {
          continue;
        }
        $this->derivatives["{$entity_type_id}.entity_usage"] = [
          'route_name' => "entity.{$entity_type_id}.entity_usage",
          'title' => $this
            ->t('Usage'),
          'base_route' => "entity.{$entity_type_id}.canonical",
          'weight' => 99,
        ];
      }
    }
    foreach ($this->derivatives as &$entry) {
      $entry += $base_plugin_definition;
    }
    return $this->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
EntityUsageLocalTask::$config protected property The config factory service.
EntityUsageLocalTask::$entityTypeManager protected property The entity type manager.
EntityUsageLocalTask::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
EntityUsageLocalTask::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
EntityUsageLocalTask::__construct public function Creates an EntityUsageLocalTask 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.