3 namespace Drupal\drupalmoduleupgrader\Routing\LinkBinding;
5 use Drupal\Component\Plugin\PluginManagerInterface;
6 use Drupal\drupalmoduleupgrader\Routing\Drupal7\RouteWrapper as Drupal7Route;
7 use Drupal\drupalmoduleupgrader\Routing\Drupal8\RouteWrapper as Drupal8Route;
10 * Represents a local task or default local task.
12 class LocalTaskLinkBinding extends LinkBinding {
15 * @var PluginManagerInterface
20 * Constructs a LinkBinding object.
22 public function __construct(Drupal7Route $source, Drupal8Route $destination, PluginManagerInterface $link_manager) {
23 parent::__construct($source, $destination);
24 $this->linkManager = $link_manager;
30 public function build() {
31 $link = parent::build();
33 $source = $this->getSource();
35 if ($source->isDefaultLocalTask()) {
36 $link['base_route'] = $link['route_name'];
38 elseif ($source->isLocalTask()) {
39 $default_task = $source->getDefaultTask();
41 $path = $default_task->getPath()->__toString();
43 if ($this->index->containsKey($path)) {
44 $link['base_route'] = $this->index[$path]->getDestination()->getIdentifier();
49 if ($source->hasParent()) {
50 $parent = $source->getParent();
52 if ($parent->isLocalTask() || $parent->isDefaultLocalTask()) {
53 $parent_id = $this->getParentID();
56 unset($link['base_route']);
57 $link['parent_id'] = $parent_id;
66 * Gets the parent task's link ID, if any.
70 public function getParentID() {
71 $path = $this->getSource()->getParent()->getPath()->__toString();
73 if ($this->index->containsKey($path)) {
74 return $this->index[$path]->getIdentifier();
77 $parent = $this->getDestination()->getParent()->getIdentifier();
79 foreach ($this->linkManager->getDefinitions() as $id => $link) {
80 if ($link['route_name'] == $parent) {