class LingotekRouteSubscriber in Lingotek Translation 8
Same name and namespace in other branches
- 8.2 src/Routing/LingotekRouteSubscriber.php \Drupal\lingotek\Routing\LingotekRouteSubscriber
- 4.0.x src/Routing/LingotekRouteSubscriber.php \Drupal\lingotek\Routing\LingotekRouteSubscriber
- 3.0.x src/Routing/LingotekRouteSubscriber.php \Drupal\lingotek\Routing\LingotekRouteSubscriber
- 3.1.x src/Routing/LingotekRouteSubscriber.php \Drupal\lingotek\Routing\LingotekRouteSubscriber
- 3.2.x src/Routing/LingotekRouteSubscriber.php \Drupal\lingotek\Routing\LingotekRouteSubscriber
- 3.3.x src/Routing/LingotekRouteSubscriber.php \Drupal\lingotek\Routing\LingotekRouteSubscriber
- 3.4.x src/Routing/LingotekRouteSubscriber.php \Drupal\lingotek\Routing\LingotekRouteSubscriber
- 3.5.x src/Routing/LingotekRouteSubscriber.php \Drupal\lingotek\Routing\LingotekRouteSubscriber
- 3.6.x src/Routing/LingotekRouteSubscriber.php \Drupal\lingotek\Routing\LingotekRouteSubscriber
- 3.7.x src/Routing/LingotekRouteSubscriber.php \Drupal\lingotek\Routing\LingotekRouteSubscriber
- 3.8.x src/Routing/LingotekRouteSubscriber.php \Drupal\lingotek\Routing\LingotekRouteSubscriber
Subscriber to add lingotek controller and generate bulk administration routes for content entity translation.
Hierarchy
- class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\lingotek\Routing\LingotekRouteSubscriber
Expanded class hierarchy of LingotekRouteSubscriber
1 string reference to 'LingotekRouteSubscriber'
1 service uses LingotekRouteSubscriber
File
- src/
Routing/ LingotekRouteSubscriber.php, line 20 - Contains \Drupal\lingotek\Routing\LingotekRouteSubscriber.
Namespace
Drupal\lingotek\RoutingView source
class LingotekRouteSubscriber extends RouteSubscriberBase {
/**
* The entity type manager
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* Constructs a RouteSubscriber object.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity type manager.
*/
public function __construct(EntityManagerInterface $entity_manager) {
$this->entityManager = $entity_manager;
}
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
// Use instead of ContentTranslationController.
foreach ($collection as $route) {
if ($route
->getDefault('_controller') == '\\Drupal\\content_translation\\Controller\\ContentTranslationController::overview') {
$route
->setDefault('_controller', '\\Drupal\\lingotek\\Controller\\LingotekContentTranslationController::overview');
}
if ($route
->getDefault('_controller') == '\\Drupal\\config_translation\\Controller\\ConfigTranslationController::itemPage') {
$route
->setDefault('_controller', '\\Drupal\\lingotek\\Controller\\LingotekConfigTranslationController::itemPage');
}
}
$debug_enabled = \Drupal::state()
->get('lingotek.enable_debug_utilities', FALSE);
foreach ($this->entityManager
->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type
->isTranslatable() && \Drupal::config('lingotek.settings')
->get('translate.entity.' . $entity_type_id)) {
// Add a route for bulk translation management.
$path = "admin/lingotek/manage/{$entity_type_id}";
$options = array(
'_admin_route' => TRUE,
);
$defaults = array(
'entity_type_id' => $entity_type_id,
);
$route = new Route($path, array(
'_form' => 'Drupal\\lingotek\\Form\\LingotekManagementForm',
'_title' => 'Manage Translations',
) + $defaults, array(
'_permission' => 'administer lingotek',
), $options);
$collection
->add("lingotek.manage.{$entity_type_id}", $route);
// Add a route for view metadata.
if ($debug_enabled) {
$path = ($entity_type
->hasLinkTemplate('canonical') ? $entity_type
->getLinkTemplate('canonical') : $entity_type
->getLinkTemplate('edit_form')) . '/metadata';
$defaults = [
'entity_type_id' => $entity_type_id,
];
$options = [
'parameters' => [
$entity_type_id => [
'type' => 'entity:' . $entity_type_id,
],
],
];
$route = new Route($path, [
'_form' => 'Drupal\\lingotek\\Form\\LingotekMetadataEditForm',
'_title' => 'Edit translation metadata',
] + $defaults, [
'_permission' => 'administer lingotek',
], $options);
$collection
->add("lingotek.metadata.{$entity_type_id}", $route);
}
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events = parent::getSubscribedEvents();
// ContentTranslationRouteSubscriber is -100.
$events[RoutingEvents::ALTER] = array(
'onAlterRoutes',
-211,
);
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LingotekRouteSubscriber:: |
protected | property | The entity type manager | |
LingotekRouteSubscriber:: |
protected | function |
Alters existing routes for a specific collection. Overrides RouteSubscriberBase:: |
|
LingotekRouteSubscriber:: |
public static | function |
Returns an array of event names this subscriber wants to listen to. Overrides RouteSubscriberBase:: |
|
LingotekRouteSubscriber:: |
public | function | Constructs a RouteSubscriber object. | |
RouteSubscriberBase:: |
public | function | Delegates the route altering to self::alterRoutes(). | 1 |