You are here

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

Represents a binding between a Drupal 7 route and a Drupal 8 one.

Hierarchy

  • class \Drupal\drupalmoduleupgrader\Routing\LinkBinding\LinkBinding

Expanded class hierarchy of LinkBinding

2 files declare their use of LinkBinding
LinkBindingTest.php in tests/src/Unit/Routing/LinkBinding/LinkBindingTest.php
LinkIndex.php in src/Routing/LinkIndex.php

File

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

Namespace

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

  /**
   * @var \Drupal\drupalmoduleupgrader\Routing\Drupal7\RouteWrapper
   */
  protected $source;

  /**
   * @var \Drupal\drupalmoduleupgrader\Routing\Drupal8\RouteWrapper
   */
  protected $destination;

  /**
   * The link ID.
   *
   * @var string
   */
  protected $id;

  /**
   * Index of all other links of this type.
   *
   * @var \Drupal\drupalmoduleupgrader\Routing\LinkIndex
   */
  protected $index;

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

  /**
   * Returns the Drupal 7 route in this binding.
   *
   * @return \Drupal\drupalmoduleupgrader\Routing\Drupal7\RouteWrapper
   */
  public function getSource() {
    return $this->source;
  }

  /**
   * Returns the Drupal 8 route in this binding.
   *
   * @return \Drupal\drupalmoduleupgrader\Routing\Drupal7\RouteWrapper
   */
  public function getDestination() {
    return $this->destination;
  }

  /**
   * Returns the link's plugin ID.
   *
   * @return string
   */
  public function getIdentifier() {
    return $this->id ?: $this
      ->getDestination()
      ->getIdentifier();
  }

  /**
   * React when the binding is added to an index.
   *
   * @param string $id
   *   The link's plugin ID, sanitized to prevent collisions.
   * @param \Drupal\drupalmoduleupgrader\Routing\LinkIndex $index
   *   The link index.
   */
  public function onIndexed($id, LinkIndex $index) {
    $this->id = $id;
    $this->index = $index;
  }

  /**
   * Builds the link definition.
   *
   * @return array
   */
  public function build() {
    $link = [
      'route_name' => $this
        ->getDestination()
        ->getIdentifier(),
    ];
    $source = $this
      ->getSource();
    if ($source
      ->containsKey('title')) {
      $link['title'] = $source['title'];
    }
    if ($source
      ->containsKey('weight')) {
      $link['weight'] = $source['weight'];
    }
    return $link;
  }

}

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::build public function Builds the link definition. 3
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.
LinkBinding::__construct public function Constructs a LinkBinding object. 1