Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Routing / LinkBinding / LinkBinding.php
1 <?php
2
3 namespace Drupal\drupalmoduleupgrader\Routing\LinkBinding;
4
5 use Drupal\drupalmoduleupgrader\Routing\Drupal7\RouteWrapper as Drupal7Route;
6 use Drupal\drupalmoduleupgrader\Routing\Drupal8\RouteWrapper as Drupal8Route;
7 use Drupal\drupalmoduleupgrader\Routing\LinkIndex;
8
9 /**
10  * Represents a binding between a Drupal 7 route and a Drupal 8 one.
11  */
12 class LinkBinding {
13
14   /**
15    * @var \Drupal\drupalmoduleupgrader\Routing\Drupal7\RouteWrapper
16    */
17   protected $source;
18
19   /**
20    * @var \Drupal\drupalmoduleupgrader\Routing\Drupal8\RouteWrapper
21    */
22   protected $destination;
23
24   /**
25    * The link ID.
26    *
27    * @var string
28    */
29   protected $id;
30
31   /**
32    * Index of all other links of this type.
33    *
34    * @var LinkIndex
35    */
36   protected $index;
37
38   /**
39    * Constructs a LinkBinding object.
40    */
41   public function __construct(Drupal7Route $source, Drupal8Route $destination) {
42     $this->source = $source;
43     $this->destination = $destination;
44   }
45
46   /**
47    * Returns the Drupal 7 route in this binding.
48    *
49    * @return \Drupal\drupalmoduleupgrader\Routing\Drupal7\RouteWrapper
50    */
51   public function getSource() {
52     return $this->source;
53   }
54
55   /**
56    * Returns the Drupal 8 route in this binding.
57    *
58    * @return Drupal7Route
59    */
60   public function getDestination() {
61     return $this->destination;
62   }
63
64   /**
65    * Returns the link's plugin ID.
66    *
67    * @return string
68    */
69   public function getIdentifier() {
70     return $this->id ?: $this->getDestination()->getIdentifier();
71   }
72
73   /**
74    * React when the binding is added to an index.
75    *
76    * @param string $id
77    *  The link's plugin ID, sanitized to prevent collisions.
78    * @param LinkIndex $index
79    *  The link index.
80    */
81   public function onIndexed($id, LinkIndex $index) {
82     $this->id = $id;
83     $this->index = $index;
84   }
85
86   /**
87    * Builds the link definition.
88    *
89    * @return array
90    */
91   public function build() {
92     $link = [
93       'route_name' => $this->getDestination()->getIdentifier(),
94     ];
95
96     $source = $this->getSource();
97     if ($source->containsKey('title')) {
98       $link['title'] = $source['title'];
99     }
100     if ($source->containsKey('weight')) {
101       $link['weight'] = $source['weight'];
102     }
103
104     return $link;
105   }
106
107 }