MenuLinkPluginConverter.php in Drupal 10
File
core/lib/Drupal/Core/ParamConverter/MenuLinkPluginConverter.php
View source
<?php
namespace Drupal\Core\ParamConverter;
use Drupal\Core\Menu\MenuLinkManagerInterface;
use Drupal\Component\Plugin\Exception\PluginException;
use Symfony\Component\Routing\Route;
class MenuLinkPluginConverter implements ParamConverterInterface {
protected $menuLinkManager;
public function __construct(MenuLinkManagerInterface $menu_link_manager) {
$this->menuLinkManager = $menu_link_manager;
}
public function convert($value, $definition, $name, array $defaults) {
if ($value) {
try {
return $this->menuLinkManager
->createInstance($value);
} catch (PluginException $e) {
}
}
}
public function applies($definition, $name, Route $route) {
return !empty($definition['type']) && $definition['type'] === 'menu_link_plugin';
}
}