You are here

public function WeMegaMenuAdminController::listWeMegaMenus in Drupal Mega Menu 8

Same name and namespace in other branches
  1. 8.x src/Controller/WeMegaMenuAdminController.php \Drupal\we_megamenu\Controller\WeMegaMenuAdminController::listWeMegaMenus()

Render page list menu backend.

1 string reference to 'WeMegaMenuAdminController::listWeMegaMenus'
we_megamenu.routing.yml in ./we_megamenu.routing.yml
we_megamenu.routing.yml

File

src/Controller/WeMegaMenuAdminController.php, line 157

Class

WeMegaMenuAdminController
Controller routines for block example routes.

Namespace

Drupal\we_megamenu\Controller

Code

public function listWeMegaMenus() {
  $menus = menu_ui_get_menus();
  $rows = [];
  foreach ($menus as $name => $title) {
    $row = [
      'menu-name' => $name,
      'menu-title' => $title,
    ];
    $dropbuttons = [
      '#type' => 'operations',
      '#links' => [
        'config' => [
          'url' => new Url('we_megamenu.admin.configure', [
            'menu_name' => $name,
          ]),
          'title' => 'Config',
        ],
        'edit' => [
          'url' => new Url('entity.menu.edit_form', [
            'menu' => $name,
          ]),
          'title' => 'Edit links',
        ],
      ],
    ];
    $row['menu-operations'] = [
      'data' => $dropbuttons,
    ];
    $rows[] = $row;
  }
  $header = [
    'menu-machine-name' => t('Machine Name'),
    'menu-name' => t('Menu Name'),
    'menu-options' => t('Options'),
  ];
  return [
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => t('No Drupal 8 Mega Menu block available. <a href="@link">Add Menu</a>.', [
      '@link' => Url::fromRoute('entity.menu.add_form')
        ->toString(),
    ]),
    '#attributes' => [
      'id' => 'we_megamenu',
    ],
  ];
}