MenuController.php

Same filename in this branch
  1. 11.x core/modules/menu_ui/src/Controller/MenuController.php
Same filename in other branches
  1. 9 core/modules/menu_link_content/src/Controller/MenuController.php
  2. 9 core/modules/menu_ui/src/Controller/MenuController.php
  3. 8.9.x core/modules/menu_link_content/src/Controller/MenuController.php
  4. 8.9.x core/modules/menu_ui/src/Controller/MenuController.php
  5. 10 core/modules/menu_link_content/src/Controller/MenuController.php
  6. 10 core/modules/menu_ui/src/Controller/MenuController.php

Namespace

Drupal\menu_link_content\Controller

File

core/modules/menu_link_content/src/Controller/MenuController.php

View source
<?php

namespace Drupal\menu_link_content\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\system\MenuInterface;

/**
 * Defines a route controller for a form for menu link content entity creation.
 */
class MenuController extends ControllerBase {
    
    /**
     * Provides the menu link creation form.
     *
     * @param \Drupal\system\MenuInterface $menu
     *   An entity representing a custom menu.
     *
     * @return array
     *   Returns the menu link creation form.
     */
    public function addLink(MenuInterface $menu) {
        $menu_link = $this->entityTypeManager()
            ->getStorage('menu_link_content')
            ->create([
            'menu_name' => $menu->id(),
        ]);
        return $this->entityFormBuilder()
            ->getForm($menu_link);
    }

}

Classes

Title Deprecated Summary
MenuController Defines a route controller for a form for menu link content entity creation.

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