You are here

class ContentTranslationMenuLinks in Lingotek Translation 8.2

Same name and namespace in other branches
  1. 4.0.x src/Plugin/Derivative/ContentTranslationMenuLinks.php \Drupal\lingotek\Plugin\Derivative\ContentTranslationMenuLinks
  2. 3.0.x src/Plugin/Derivative/ContentTranslationMenuLinks.php \Drupal\lingotek\Plugin\Derivative\ContentTranslationMenuLinks
  3. 3.1.x src/Plugin/Derivative/ContentTranslationMenuLinks.php \Drupal\lingotek\Plugin\Derivative\ContentTranslationMenuLinks
  4. 3.2.x src/Plugin/Derivative/ContentTranslationMenuLinks.php \Drupal\lingotek\Plugin\Derivative\ContentTranslationMenuLinks
  5. 3.3.x src/Plugin/Derivative/ContentTranslationMenuLinks.php \Drupal\lingotek\Plugin\Derivative\ContentTranslationMenuLinks
  6. 3.4.x src/Plugin/Derivative/ContentTranslationMenuLinks.php \Drupal\lingotek\Plugin\Derivative\ContentTranslationMenuLinks
  7. 3.5.x src/Plugin/Derivative/ContentTranslationMenuLinks.php \Drupal\lingotek\Plugin\Derivative\ContentTranslationMenuLinks
  8. 3.6.x src/Plugin/Derivative/ContentTranslationMenuLinks.php \Drupal\lingotek\Plugin\Derivative\ContentTranslationMenuLinks
  9. 3.7.x src/Plugin/Derivative/ContentTranslationMenuLinks.php \Drupal\lingotek\Plugin\Derivative\ContentTranslationMenuLinks
  10. 3.8.x src/Plugin/Derivative/ContentTranslationMenuLinks.php \Drupal\lingotek\Plugin\Derivative\ContentTranslationMenuLinks

Provides dynamic menu links for Lingotek content translation management.

Hierarchy

Expanded class hierarchy of ContentTranslationMenuLinks

1 string reference to 'ContentTranslationMenuLinks'
lingotek.links.menu.yml in ./lingotek.links.menu.yml
lingotek.links.menu.yml

File

src/Plugin/Derivative/ContentTranslationMenuLinks.php, line 14

Namespace

Drupal\lingotek\Plugin\Derivative
View source
class ContentTranslationMenuLinks extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;

  /**
   * The base plugin ID
   *
   * @var string
   */
  protected $basePluginId;

  /**
   * The Lingotek configuration service.
   *
   * @var \Drupal\lingotek\LingotekConfigurationServiceInterface
   */
  protected $lingotekConfiguration;

  /**
   * Constructs a new ContentTranslationLocalTasks.
   *
   * @param string $base_plugin_id
   *   The base plugin ID.
   * @param \Drupal\lingotek\LingotekConfigurationServiceInterface $lingotek_configuration
   *   The Lingotek configuration service.
   */
  public function __construct($base_plugin_id, LingotekConfigurationServiceInterface $lingotek_configuration) {
    $this->basePluginId = $base_plugin_id;
    $this->lingotekConfiguration = $lingotek_configuration;
  }

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

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {

    // Create menu links for all possible entity types.
    foreach ($this->lingotekConfiguration
      ->getEnabledEntityTypes() as $entity_type_id => $entity_type) {
      $translation_route_name = "lingotek.manage.{$entity_type_id}";

      // If it's a paragraph, we depend on the preference.
      if ($entity_type_id === 'paragraph') {
        $config = \Drupal::config('lingotek.settings');
        $enable_bulk_management = $config
          ->get('preference.contrib.paragraphs.enable_bulk_management', FALSE);
        if (!$enable_bulk_management) {

          // If already existed remove it.
          if (isset($this->derivatives[$translation_route_name])) {
            unset($this->derivatives[$translation_route_name]);
          }
          continue;
        }
      }

      // Create the entries for the tabs in the bulk manage pages.
      $base_route_name = "lingotek.manage";
      $this->derivatives[$translation_route_name] = [
        'entity_type_id' => $entity_type_id,
        'title' => $entity_type
          ->getLabel(),
        'route_name' => $translation_route_name,
        'base_route' => $base_route_name,
        'parent' => 'lingotek.manage',
      ] + $base_plugin_definition;
    }
    return parent::getDerivativeDefinitions($base_plugin_definition);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContentTranslationMenuLinks::$basePluginId protected property The base plugin ID
ContentTranslationMenuLinks::$lingotekConfiguration protected property The Lingotek configuration service.
ContentTranslationMenuLinks::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
ContentTranslationMenuLinks::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
ContentTranslationMenuLinks::__construct public function Constructs a new ContentTranslationLocalTasks.
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. 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.