You are here

public function LocalTaskLinkBinding::build in Drupal 7 to 8/9 Module Upgrader 8

Builds the link definition.

Return value

array

Overrides LinkBinding::build

File

src/Routing/LinkBinding/LocalTaskLinkBinding.php, line 30

Class

LocalTaskLinkBinding
Represents a local task or default local task.

Namespace

Drupal\drupalmoduleupgrader\Routing\LinkBinding

Code

public function build() {
  $link = parent::build();
  $source = $this
    ->getSource();
  if ($source
    ->isDefaultLocalTask()) {
    $link['base_route'] = $link['route_name'];
  }
  elseif ($source
    ->isLocalTask()) {
    $default_task = $source
      ->getDefaultTask();
    if ($default_task) {
      $path = $default_task
        ->getPath()
        ->__toString();
      if ($this->index
        ->containsKey($path)) {
        $link['base_route'] = $this->index[$path]
          ->getDestination()
          ->getIdentifier();
      }
    }
  }
  if ($source
    ->hasParent()) {
    $parent = $source
      ->getParent();
    if ($parent
      ->isLocalTask() || $parent
      ->isDefaultLocalTask()) {
      $parent_id = $this
        ->getParentID();
      if ($parent_id) {
        unset($link['base_route']);
        $link['parent_id'] = $parent_id;
      }
    }
  }
  return $link;
}