/**
  * Returns the maximum depth of the possible parents of the menu link.
  *
  * @param string $id
  *   The menu link plugin ID or an empty value for a new link.
  *
  * @return int
  *   The depth related to the depth of the given menu link.
  */
 protected function getParentDepthLimit($id)
 {
     if ($id) {
         $limit = $this->menuLinkTree->maxDepth() - $this->menuLinkTree->getSubtreeHeight($id);
     } else {
         $limit = $this->menuLinkTree->maxDepth() - 1;
     }
     return $limit;
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $menu_name = $this->getDerivativeId();
     $parameters = $this->menuTree->getCurrentRouteMenuTreeParameters($menu_name);
     // Adjust the menu tree parameters based on the block's configuration.
     $level = $this->configuration['level'];
     $depth = $this->configuration['depth'];
     $parameters->setMinDepth($level);
     // When the depth is configured to zero, there is no depth limit. When depth
     // is non-zero, it indicates the number of levels that must be displayed.
     // Hence this is a relative depth that we must convert to an actual
     // (absolute) depth, that may never exceed the maximum depth.
     if ($depth > 0) {
         $parameters->setMaxDepth(min($level + $depth - 1, $this->menuTree->maxDepth()));
     }
     $tree = $this->menuTree->load($menu_name, $parameters);
     $manipulators = array(array('callable' => 'menu.default_tree_manipulators:checkAccess'), array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'));
     $tree = $this->menuTree->transform($tree, $manipulators);
     return $this->menuTree->build($tree);
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state)
 {
     $menu_enabled = $this->moduleHandler->moduleExists('menu_ui');
     if ($menu_enabled) {
         $menus = array('__new-menu__' => $this->t('Create new menu(s)')) + menu_ui_get_menus();
     } else {
         $menus = menu_list_system_menus();
     }
     $form['existing_menus'] = array('#type' => 'checkboxes', '#title' => $this->t('Generate links for these menus'), '#options' => $menus, '#default_value' => array('__new-menu__'), '#required' => TRUE);
     if ($menu_enabled) {
         $form['num_menus'] = array('#type' => 'number', '#title' => $this->t('Number of new menus to create'), '#default_value' => $this->getSetting('num_menus'), '#min' => 0, '#states' => array('visible' => array(':input[name="existing_menus[__new-menu__]"]' => array('checked' => TRUE))));
     }
     $form['num_links'] = array('#type' => 'number', '#title' => $this->t('Number of links to generate'), '#default_value' => $this->getSetting('num_links'), '#required' => TRUE, '#min' => 0);
     $form['title_length'] = array('#type' => 'number', '#title' => $this->t('Maximum number of characters in menu and menu link names'), '#description' => $this->t('The minimum length is 2.'), '#default_value' => $this->getSetting('title_length'), '#required' => TRUE, '#min' => 2, '#max' => 128);
     $form['link_types'] = array('#type' => 'checkboxes', '#title' => $this->t('Types of links to generate'), '#options' => array('node' => $this->t('Nodes'), 'front' => $this->t('Front page'), 'external' => $this->t('External')), '#default_value' => array('node', 'front', 'external'), '#required' => TRUE);
     $form['max_depth'] = array('#type' => 'select', '#title' => $this->t('Maximum link depth'), '#options' => range(0, $this->menuLinkTree->maxDepth()), '#default_value' => floor($this->menuLinkTree->maxDepth() / 2), '#required' => TRUE);
     unset($form['max_depth']['#options'][0]);
     $form['max_width'] = array('#type' => 'number', '#title' => $this->t('Maximum menu width'), '#default_value' => $this->getSetting('max_width'), '#description' => $this->t('Limit the width of the generated menu\'s first level of links to a certain number of items.'), '#required' => TRUE, '#min' => 0);
     $form['kill'] = array('#type' => 'checkbox', '#title' => $this->t('Delete existing custom generated menus and menu links before generating new ones.'), '#default_value' => $this->getSetting('kill'));
     return $form;
 }