You are here

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

Represents a set of link bindings of a single type (i.e., menu links, local tasks, etc.)

Hierarchy

  • class \Drupal\drupalmoduleupgrader\Routing\LinkIndex extends \Doctrine\Common\Collections\ArrayCollection

Expanded class hierarchy of LinkIndex

3 files declare their use of LinkIndex
LinkBinding.php in src/Routing/LinkBinding/LinkBinding.php
LinkBindingTest.php in tests/src/Unit/Routing/LinkBinding/LinkBindingTest.php
Links.php in src/Plugin/DMU/Converter/Links.php

File

src/Routing/LinkIndex.php, line 11

Namespace

Drupal\drupalmoduleupgrader\Routing
View source
class LinkIndex extends ArrayCollection {

  /**
   * Tracks link IDs to prevent collisions.
   *
   * @var string[]
   */
  protected $idiotBox = [];

  /**
   * Adds a binding to this index.
   *
   * @param \Drupal\drupalmoduleupgrader\Routing\LinkBinding\LinkBinding $binding
   */
  public function addBinding(LinkBinding $binding) {
    $id = $binding
      ->getIdentifier();
    if (isset($this->idiotBox[$id])) {
      $id .= '_' . $this->idiotBox[$id]++;
    }
    else {
      $this->idiotBox[$id] = 0;
    }
    $this
      ->set($binding
      ->getSource()
      ->getPath()
      ->__toString(), $binding);
    $binding
      ->onIndexed($id, $this);
  }

  /**
   * Builds all the links in this index and returns them as an array of arrays,
   * keyed by link ID.
   *
   * @return array
   */
  public function build() {
    $build = [];
    foreach ($this as $binding) {
      $build[$binding
        ->getIdentifier()] = $binding
        ->build();
    }
    return $build;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LinkIndex::$idiotBox protected property Tracks link IDs to prevent collisions.
LinkIndex::addBinding public function Adds a binding to this index.
LinkIndex::build public function Builds all the links in this index and returns them as an array of arrays, keyed by link ID.