Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Routing / LinkBinding / LinkBindingFactory.php
1 <?php
2
3 namespace Drupal\drupalmoduleupgrader\Routing\LinkBinding;
4
5 use Drupal\Component\Plugin\PluginManagerInterface;
6 use Drupal\drupalmoduleupgrader\Routing\Drupal7\RouteWrapper as Drupal7Route;
7 use Drupal\drupalmoduleupgrader\Routing\Drupal8\RouteWrapper as Drupal8Route;
8
9 /**
10  * Factory class to create link bindings, depending on the source route's type.
11  */
12 class LinkBindingFactory {
13
14   /**
15    * @var PluginManagerInterface
16    */
17   private $linkManager;
18
19   public function __construct(PluginManagerInterface $link_manager) {
20     $this->linkManager = $link_manager;
21   }
22
23   /**
24    * Factory method. Returns a link binding object appropriate for the source link type.
25    *
26    * @param Drupal7Route $source
27    *  The source (Drupal 7) route.
28    * @param Drupal8Route $destination
29    *  The destination (Drupal 8) route.
30    *
31    * @return mixed
32    *  A link binding object; either an instance of this class or a subclass thereof.
33    */
34   public function create(Drupal7Route $source, Drupal8Route $destination) {
35     if ($source->isLink()) {
36       return new MenuLinkBinding($source, $destination);
37     }
38     elseif ($source->isLocalTask() || $source->isDefaultLocalTask()) {
39       return new LocalTaskLinkBinding($source, $destination, $this->linkManager);
40     }
41     elseif ($source->isLocalAction()) {
42       if ($source->isContextualLink()) {
43         return new LinkBinding($source, $destination);
44       }
45       else {
46         return new LocalActionLinkBinding($source, $destination);
47       }
48     }
49   }
50
51 }