class UserLocalTask

Same name in other branches
  1. 9 core/modules/user/src/Plugin/Derivative/UserLocalTask.php \Drupal\user\Plugin\Derivative\UserLocalTask
  2. 11.x core/modules/user/src/Plugin/Derivative/UserLocalTask.php \Drupal\user\Plugin\Derivative\UserLocalTask

Provides local task definitions for all entity bundles.

Hierarchy

Expanded class hierarchy of UserLocalTask

1 file declares its use of UserLocalTask
UserLocalTaskTest.php in core/modules/user/tests/src/Unit/Plugin/Derivative/UserLocalTaskTest.php
1 string reference to 'UserLocalTask'
user.links.task.yml in core/modules/user/user.links.task.yml
core/modules/user/user.links.task.yml

File

core/modules/user/src/Plugin/Derivative/UserLocalTask.php, line 15

Namespace

Drupal\user\Plugin\Derivative
View source
class UserLocalTask extends DeriverBase implements ContainerDeriverInterface {
    use StringTranslationTrait;
    
    /**
     * The entity type manager.
     *
     * @var \Drupal\Core\Entity\EntityTypeManagerInterface
     */
    protected $entityTypeManager;
    
    /**
     * Creates a UserLocalTask object.
     *
     * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
     *   The entity type manager.
     * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
     *   The translation manager.
     */
    public function __construct(EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation) {
        $this->entityTypeManager = $entity_type_manager;
        $this->stringTranslation = $string_translation;
    }
    
    /**
     * {@inheritdoc}
     */
    public static function create(ContainerInterface $container, $base_plugin_id) {
        return new static($container->get('entity_type.manager'), $container->get('string_translation'));
    }
    
    /**
     * {@inheritdoc}
     */
    public function getDerivativeDefinitions($base_plugin_definition) {
        $this->derivatives = [];
        $entity_definitions = $this->entityTypeManager
            ->getDefinitions();
        foreach ($entity_definitions as $bundle_type_id => $bundle_entity_type) {
            if (!$bundle_entity_type->hasLinkTemplate('entity-permissions-form')) {
                continue;
            }
            if (!($entity_type_id = $bundle_entity_type->getBundleOf())) {
                continue;
            }
            $entity_type = $entity_definitions[$entity_type_id];
            if (!($base_route = $entity_type->get('field_ui_base_route'))) {
                continue;
            }
            $this->derivatives["permissions_{$bundle_type_id}"] = [
                'route_name' => "entity.{$bundle_type_id}.entity_permissions_form",
                'weight' => 10,
                'title' => $this->t('Manage permissions'),
                'base_route' => $base_route,
            ] + $base_plugin_definition;
        }
        return parent::getDerivativeDefinitions($base_plugin_definition);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
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.
UserLocalTask::$entityTypeManager protected property The entity type manager.
UserLocalTask::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
UserLocalTask::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
UserLocalTask::__construct public function Creates a UserLocalTask object.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.