You are here

protected function SettingsForm::getSortedMenus in Menu Breadcrumb 8

Same name and namespace in other branches
  1. 2.0.x src/Form/SettingsForm.php \Drupal\menu_breadcrumb\Form\SettingsForm::getSortedMenus()

Get Sorted Menus.

Returns array of menus with properties (enabled, taxattach, langhandle, weight, label) sorted by weight, initializing those properties if needed.

1 call to SettingsForm::getSortedMenus()
SettingsForm::buildForm in src/Form/SettingsForm.php
Form constructor.

File

src/Form/SettingsForm.php, line 267

Class

SettingsForm

Namespace

Drupal\menu_breadcrumb\Form

Code

protected function getSortedMenus() {
  $menu_enabled = $this->moduleHandler
    ->moduleExists('menu_ui');
  $menus = $menu_enabled ? menu_ui_get_menus() : menu_list_system_menus();
  $menu_breadcrumb_menus = $this
    ->config('menu_breadcrumb.settings')
    ->get('menu_breadcrumb_menus');
  foreach ($menus as $menu_name => &$menu) {
    if (!empty($menu_breadcrumb_menus[$menu_name])) {
      $menu = $menu_breadcrumb_menus[$menu_name] + [
        'label' => $menu,
      ];

      // Earlier versions of the module might not have these array keys set.
      // TODO Maybe set these for existing menu definitions in upgrade script?
      if (!isset($menu['taxattach'])) {
        $menu['taxattach'] = 0;
      }
      if (!isset($menu['langhandle'])) {
        $menu['langhandle'] = 0;
      }
    }
    else {
      $menu = [
        'weight' => 0,
        'enabled' => 0,
        'taxattach' => 0,
        'langhandle' => 0,
        'label' => $menu,
      ];
    }
  }
  uasort($menus, function ($a, $b) {
    return SortArray::sortByWeightElement($a, $b);
  });
  return $menus;
}