class DynamicLocalTasks

Same name in this branch
  1. main core/modules/media/src/Plugin/Derivative/DynamicLocalTasks.php \Drupal\media\Plugin\Derivative\DynamicLocalTasks
Same name and namespace in other branches
  1. 10 core/modules/media/src/Plugin/Derivative/DynamicLocalTasks.php \Drupal\media\Plugin\Derivative\DynamicLocalTasks
  2. 11.x core/modules/media/src/Plugin/Derivative/DynamicLocalTasks.php \Drupal\media\Plugin\Derivative\DynamicLocalTasks
  3. 11.x core/modules/content_moderation/src/Plugin/Derivative/DynamicLocalTasks.php \Drupal\content_moderation\Plugin\Derivative\DynamicLocalTasks
  4. 10 core/modules/content_moderation/src/Plugin/Derivative/DynamicLocalTasks.php \Drupal\content_moderation\Plugin\Derivative\DynamicLocalTasks
  5. 9 core/modules/media/src/Plugin/Derivative/DynamicLocalTasks.php \Drupal\media\Plugin\Derivative\DynamicLocalTasks
  6. 9 core/modules/content_moderation/src/Plugin/Derivative/DynamicLocalTasks.php \Drupal\content_moderation\Plugin\Derivative\DynamicLocalTasks
  7. 8.9.x core/modules/media/src/Plugin/Derivative/DynamicLocalTasks.php \Drupal\media\Plugin\Derivative\DynamicLocalTasks
  8. 8.9.x core/modules/content_moderation/src/Plugin/Derivative/DynamicLocalTasks.php \Drupal\content_moderation\Plugin\Derivative\DynamicLocalTasks

Generates moderation-related local tasks.

Hierarchy

Expanded class hierarchy of DynamicLocalTasks

1 string reference to 'DynamicLocalTasks'
content_moderation.links.task.yml in core/modules/content_moderation/content_moderation.links.task.yml
core/modules/content_moderation/content_moderation.links.task.yml

File

core/modules/content_moderation/src/Plugin/Derivative/DynamicLocalTasks.php, line 18

Namespace

Drupal\content_moderation\Plugin\Derivative
View source
class DynamicLocalTasks extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;
  
  /**
   * Creates a FieldUiLocalTask object.
   *
   * @param string $basePluginId
   *   The base plugin ID.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
   *   The entity type manager.
   * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
   *   The translation manager.
   * @param \Drupal\content_moderation\ModerationInformationInterface $moderationInfo
   *   The moderation information service.
   * @param \Symfony\Component\Routing\RouterInterface $router
   *   The router.
   */
  public function __construct(protected $basePluginId, protected EntityTypeManagerInterface $entityTypeManager, TranslationInterface $string_translation, protected ModerationInformationInterface $moderationInfo, protected RouterInterface $router) {
    $this->stringTranslation = $string_translation;
  }
  
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($base_plugin_id, $container->get('entity_type.manager'), $container->get('string_translation'), $container->get('content_moderation.moderation_information'), $container->get('router'));
  }
  
  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $this->derivatives = [];
    // Add the moderated content task if the route exists.
    if ($this->router
      ->getRouteCollection()
      ->get('content_moderation.admin_moderated_content') !== NULL) {
      $this->derivatives['content_moderation.moderated_content'] = [
        'route_name' => 'content_moderation.admin_moderated_content',
        'title' => $this->t('Moderated content'),
        'parent_id' => 'system.admin_content',
        'weight' => 1,
      ];
    }
    // Add the latest version tab to entities.
    $latest_version_entities = array_filter($this->entityTypeManager
      ->getDefinitions(), function (EntityTypeInterface $type) {
      return $this->moderationInfo
        ->canModerateEntitiesOfEntityType($type) && $type->hasLinkTemplate('latest-version');
    });
    foreach ($latest_version_entities as $entity_type_id => $entity_type) {
      $this->derivatives["{$entity_type_id}.latest_version_tab"] = [
        'route_name' => "entity.{$entity_type_id}.latest_version",
        'title' => $this->t('Latest version'),
        'base_route' => "entity.{$entity_type_id}.canonical",
        'weight' => 1,
      ] + $base_plugin_definition;
    }
    return $this->derivatives;
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Overrides DeriverInterface::getDerivativeDefinition
DynamicLocalTasks::create public static function Overrides ContainerDeriverInterface::create
DynamicLocalTasks::getDerivativeDefinitions public function Overrides DeriverBase::getDerivativeDefinitions
DynamicLocalTasks::__construct public function Creates a FieldUiLocalTask object.
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. 1

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