ContentTranslationMenuLinks.php in Lingotek Translation 3.4.x
File
src/Plugin/Derivative/ContentTranslationMenuLinks.php
View source
<?php
namespace Drupal\lingotek\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\lingotek\LingotekConfigurationServiceInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ContentTranslationMenuLinks extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
protected $basePluginId;
protected $lingotekConfiguration;
public function __construct($base_plugin_id, LingotekConfigurationServiceInterface $lingotek_configuration) {
$this->basePluginId = $base_plugin_id;
$this->lingotekConfiguration = $lingotek_configuration;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($base_plugin_id, $container
->get('lingotek.configuration'));
}
public function getDerivativeDefinitions($base_plugin_definition) {
foreach ($this->lingotekConfiguration
->getEnabledEntityTypes() as $entity_type_id => $entity_type) {
$translation_route_name = "lingotek.manage.{$entity_type_id}";
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 (isset($this->derivatives[$translation_route_name])) {
unset($this->derivatives[$translation_route_name]);
}
continue;
}
}
if ($entity_type_id === 'cohesion_layout') {
if (isset($this->derivatives[$translation_route_name])) {
unset($this->derivatives[$translation_route_name]);
}
continue;
}
$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);
}
}