In D7, if a node is translated, let say in French and if you are in the entity.node.edit_form page then you could find 2 secondary tabs: [French] and [English] pointing to the edit_form of each language.
To achieve this in D8, I looked at the derivatives, but they are loaded once during cache clear and can't evaluate the current entity.
Following the 4k4 comment I have tried to subclass LocalTaskDefault
But I am stuck with the following problems:
1-How can I create a route for a defined language (eg: a route to edit a french node)
2-In .links.task.yml
: should I create as many tabs as there are languages (I don't think so)
Here is my .links.task.yml
file
translated_node_tabs:
class: Drupal\mymodule\Plugin\Menu\TranslatedNodeTab
title: 'Translated nodes'
base_route: entity.node.edit_form
route_name: entity.node.edit_form
And here is the very beginning of what I have understood from the 4k4 advice
class TranslatedNodeTab extends LocalTaskDefault {
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
return [
'route'
];
}
/**
* {@inheritdoc}
*/
public function getRouteParameters(RouteMatchInterface $route_match) {
$current_node = $route_match->getParameter('node');
if ($current_node instanceof NodeInterface) {
$nid = $current_node->id();
return [
'node' => $nid
];
}
return [];
}
}
node
context by the way, useroute
.getRouteName()
... but same question: how to provide the localized route. Thank for the context, I have updated my question with theroute
context$this->getDerivativeId()