class MenuLinkPluginConverter

Same name in this branch
  1. 11.x core/lib/Drupal/Core/ProxyClass/ParamConverter/MenuLinkPluginConverter.php \Drupal\Core\ProxyClass\ParamConverter\MenuLinkPluginConverter
Same name in other branches
  1. 9 core/lib/Drupal/Core/ProxyClass/ParamConverter/MenuLinkPluginConverter.php \Drupal\Core\ProxyClass\ParamConverter\MenuLinkPluginConverter
  2. 9 core/lib/Drupal/Core/ParamConverter/MenuLinkPluginConverter.php \Drupal\Core\ParamConverter\MenuLinkPluginConverter
  3. 8.9.x core/lib/Drupal/Core/ProxyClass/ParamConverter/MenuLinkPluginConverter.php \Drupal\Core\ProxyClass\ParamConverter\MenuLinkPluginConverter
  4. 8.9.x core/lib/Drupal/Core/ParamConverter/MenuLinkPluginConverter.php \Drupal\Core\ParamConverter\MenuLinkPluginConverter
  5. 10 core/lib/Drupal/Core/ProxyClass/ParamConverter/MenuLinkPluginConverter.php \Drupal\Core\ProxyClass\ParamConverter\MenuLinkPluginConverter
  6. 10 core/lib/Drupal/Core/ParamConverter/MenuLinkPluginConverter.php \Drupal\Core\ParamConverter\MenuLinkPluginConverter

Parameter converter for upcasting entity ids to full objects.

Hierarchy

Expanded class hierarchy of MenuLinkPluginConverter

File

core/lib/Drupal/Core/ParamConverter/MenuLinkPluginConverter.php, line 12

Namespace

Drupal\Core\ParamConverter
View source
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';
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
MenuLinkPluginConverter::$menuLinkManager protected property Plugin manager which creates the instance from the value.
MenuLinkPluginConverter::applies public function Determines if the converter applies to a specific route and variable. Overrides ParamConverterInterface::applies
MenuLinkPluginConverter::convert public function Converts path variables to their corresponding objects. Overrides ParamConverterInterface::convert
MenuLinkPluginConverter::__construct public function Constructs a new MenuLinkPluginConverter.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.