3 namespace Drupal\drupalmoduleupgrader\Routing\LinkBinding;
5 use Drupal\drupalmoduleupgrader\Routing\Drupal7\RouteWrapper as Drupal7Route;
6 use Drupal\drupalmoduleupgrader\Routing\Drupal8\RouteWrapper as Drupal8Route;
7 use Drupal\drupalmoduleupgrader\Routing\LinkIndex;
10 * Represents a binding between a Drupal 7 route and a Drupal 8 one.
15 * @var \Drupal\drupalmoduleupgrader\Routing\Drupal7\RouteWrapper
20 * @var \Drupal\drupalmoduleupgrader\Routing\Drupal8\RouteWrapper
22 protected $destination;
32 * Index of all other links of this type.
39 * Constructs a LinkBinding object.
41 public function __construct(Drupal7Route $source, Drupal8Route $destination) {
42 $this->source = $source;
43 $this->destination = $destination;
47 * Returns the Drupal 7 route in this binding.
49 * @return \Drupal\drupalmoduleupgrader\Routing\Drupal7\RouteWrapper
51 public function getSource() {
56 * Returns the Drupal 8 route in this binding.
58 * @return Drupal7Route
60 public function getDestination() {
61 return $this->destination;
65 * Returns the link's plugin ID.
69 public function getIdentifier() {
70 return $this->id ?: $this->getDestination()->getIdentifier();
74 * React when the binding is added to an index.
77 * The link's plugin ID, sanitized to prevent collisions.
78 * @param LinkIndex $index
81 public function onIndexed($id, LinkIndex $index) {
83 $this->index = $index;
87 * Builds the link definition.
91 public function build() {
93 'route_name' => $this->getDestination()->getIdentifier(),
96 $source = $this->getSource();
97 if ($source->containsKey('title')) {
98 $link['title'] = $source['title'];
100 if ($source->containsKey('weight')) {
101 $link['weight'] = $source['weight'];