You are here

class LocalTaskLinkBinding in Drupal 7 to 8/9 Module Upgrader 8

Represents a local task or default local task.

Hierarchy

Expanded class hierarchy of LocalTaskLinkBinding

1 file declares its use of LocalTaskLinkBinding
Links.php in src/Plugin/DMU/Converter/Links.php

File

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

Namespace

Drupal\drupalmoduleupgrader\Routing\LinkBinding
View source
class LocalTaskLinkBinding extends LinkBinding {

  /**
   * @var \Drupal\Component\Plugin\PluginManagerInterface
   */
  private $linkManager;

  /**
   * Constructs a LinkBinding object.
   */
  public function __construct(Drupal7Route $source, Drupal8Route $destination, PluginManagerInterface $link_manager) {
    parent::__construct($source, $destination);
    $this->linkManager = $link_manager;
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * Gets the parent task's link ID, if any.
   *
   * @return string|null
   */
  public function getParentID() {
    $path = $this
      ->getSource()
      ->getParent()
      ->getPath()
      ->__toString();
    if ($this->index
      ->containsKey($path)) {
      return $this->index[$path]
        ->getIdentifier();
    }
    $parent = $this
      ->getDestination()
      ->getParent()
      ->getIdentifier();
    foreach ($this->linkManager
      ->getDefinitions() as $id => $link) {
      if ($link['route_name'] == $parent) {
        return $id;
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LinkBinding::$destination protected property
LinkBinding::$id protected property The link ID.
LinkBinding::$index protected property Index of all other links of this type.
LinkBinding::$source protected property
LinkBinding::getDestination public function Returns the Drupal 8 route in this binding.
LinkBinding::getIdentifier public function Returns the link's plugin ID.
LinkBinding::getSource public function Returns the Drupal 7 route in this binding.
LinkBinding::onIndexed public function React when the binding is added to an index.
LocalTaskLinkBinding::$linkManager private property
LocalTaskLinkBinding::build public function Builds the link definition. Overrides LinkBinding::build
LocalTaskLinkBinding::getParentID public function Gets the parent task's link ID, if any.
LocalTaskLinkBinding::__construct public function Constructs a LinkBinding object. Overrides LinkBinding::__construct