class ContentTranslationLocalTasks

Same name and namespace in other branches
  1. 11.x core/modules/content_translation/src/Plugin/Derivative/ContentTranslationLocalTasks.php \Drupal\content_translation\Plugin\Derivative\ContentTranslationLocalTasks
  2. 10 core/modules/content_translation/src/Plugin/Derivative/ContentTranslationLocalTasks.php \Drupal\content_translation\Plugin\Derivative\ContentTranslationLocalTasks
  3. 9 core/modules/content_translation/src/Plugin/Derivative/ContentTranslationLocalTasks.php \Drupal\content_translation\Plugin\Derivative\ContentTranslationLocalTasks
  4. 8.9.x core/modules/content_translation/src/Plugin/Derivative/ContentTranslationLocalTasks.php \Drupal\content_translation\Plugin\Derivative\ContentTranslationLocalTasks

Provides dynamic local tasks for content translation.

Hierarchy

Expanded class hierarchy of ContentTranslationLocalTasks

1 string reference to 'ContentTranslationLocalTasks'
content_translation.links.task.yml in core/modules/content_translation/content_translation.links.task.yml
core/modules/content_translation/content_translation.links.task.yml

File

core/modules/content_translation/src/Plugin/Derivative/ContentTranslationLocalTasks.php, line 15

Namespace

Drupal\content_translation\Plugin\Derivative
View source
class ContentTranslationLocalTasks extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;
  
  /**
   * Constructs a new ContentTranslationLocalTasks.
   *
   * @param string $basePluginId
   *   The base plugin ID.
   * @param \Drupal\content_translation\ContentTranslationManagerInterface $contentTranslationManager
   *   The content translation manager.
   * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
   *   The translation manager.
   */
  public function __construct(protected $basePluginId, protected ContentTranslationManagerInterface $contentTranslationManager, TranslationInterface $string_translation) {
    $this->stringTranslation = $string_translation;
  }
  
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($base_plugin_id, $container->get('content_translation.manager'), $container->get('string_translation'));
  }
  
  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    // Create tabs for all possible entity types.
    foreach ($this->contentTranslationManager
      ->getSupportedEntityTypes() as $entity_type_id => $entity_type) {
      // Find the route name for the translation overview.
      $translation_route_name = "entity.{$entity_type_id}.content_translation_overview";
      $base_route_name = "entity.{$entity_type_id}.canonical";
      $this->derivatives[$translation_route_name] = [
        'entity_type' => $entity_type_id,
        'title' => $this->t('Translate'),
        'route_name' => $translation_route_name,
        'base_route' => $base_route_name,
      ] + $base_plugin_definition;
    }
    return parent::getDerivativeDefinitions($base_plugin_definition);
  }

}

Members

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

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