X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FRouting%2FLinkBinding%2FLinkBinding.php;fp=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FRouting%2FLinkBinding%2FLinkBinding.php;h=217d8d7a51077936a6bdc31a4d5d0bbbfb218ff1;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/drupalmoduleupgrader/src/Routing/LinkBinding/LinkBinding.php b/web/modules/contrib/drupalmoduleupgrader/src/Routing/LinkBinding/LinkBinding.php new file mode 100644 index 000000000..217d8d7a5 --- /dev/null +++ b/web/modules/contrib/drupalmoduleupgrader/src/Routing/LinkBinding/LinkBinding.php @@ -0,0 +1,107 @@ +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 Drupal7Route + */ + 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 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; + } + +}