blob: 21b2f26f6d10fda8e3c331dc0c9737b2fecc480e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
<?php
namespace Drupal\Core\ParamConverter;
use Drupal\Core\Menu\MenuLinkManagerInterface;
use Drupal\Component\Plugin\Exception\PluginException;
use Symfony\Component\Routing\Route;
/**
* Parameter converter for upcasting entity ids to full objects.
*/
class MenuLinkPluginConverter implements ParamConverterInterface {
/**
* Plugin manager which creates the instance from the value.
*
* @var \Drupal\Core\Menu\MenuLinkManagerInterface
*/
protected $menuLinkManager;
/**
* Constructs a new MenuLinkPluginConverter.
*
* @param \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager
* The menu link plugin manager.
*/
public function __construct(MenuLinkManagerInterface $menu_link_manager) {
$this->menuLinkManager = $menu_link_manager;
}
/**
* {@inheritdoc}
*/
public function convert($value, $definition, $name, array $defaults) {
if ($value) {
try {
return $this->menuLinkManager->createInstance($value);
}
catch (PluginException) {
// Suppress the error.
}
}
}
/**
* {@inheritdoc}
*/
public function applies($definition, $name, Route $route) {
return (!empty($definition['type']) && $definition['type'] === 'menu_link_plugin');
}
}
|