示例#1
0
 /**
  * {@inheritdoc}
  */
 public function getCacheKeys()
 {
     // Add a key for the active menu trail.
     $menu = $this->getDerivativeId();
     $active_trail = $this->menuTree->getActiveTrailIds($menu);
     $active_trail_key = 'trail.' . implode('|', $active_trail);
     return array_merge(parent::getCacheKeys(), array($active_trail_key));
 }
示例#2
0
 /**
  * Form constructor to edit an entire menu tree at once.
  *
  * Shows for one menu the menu links accessible to the current user and
  * relevant operations.
  *
  * This form constructor can be integrated as a section into another form. It
  * relies on the following keys in $form_state:
  * - menu: A menu entity.
  * - menu_overview_form_parents: An array containing the parent keys to this
  *   form.
  * Forms integrating this section should call menu_overview_form_submit() from
  * their form submit handler.
  */
 protected function buildOverviewForm(array &$form, array &$form_state)
 {
     // Ensure that menu_overview_form_submit() knows the parents of this form
     // section.
     $form['#tree'] = TRUE;
     $form['#theme'] = 'menu_overview_form';
     $form_state += array('menu_overview_form_parents' => array());
     $form['#attached']['css'] = array(drupal_get_path('module', 'menu') . '/css/menu.admin.css');
     $links = array();
     $query = $this->entityQueryFactory->get('menu_link')->condition('menu_name', $this->entity->id());
     for ($i = 1; $i <= MENU_MAX_DEPTH; $i++) {
         $query->sort('p' . $i, 'ASC');
     }
     $result = $query->execute();
     if (!empty($result)) {
         $links = $this->menuLinkStorage->loadMultiple($result);
     }
     $delta = max(count($links), 50);
     // We indicate that a menu administrator is running the menu access check.
     $this->getRequest()->attributes->set('_menu_admin', TRUE);
     $tree = $this->menuTree->buildTreeData($links);
     $this->getRequest()->attributes->set('_menu_admin', FALSE);
     $form = array_merge($form, $this->buildOverviewTreeForm($tree, $delta));
     $form['#empty_text'] = t('There are no menu links yet. <a href="@link">Add link</a>.', array('@link' => url('admin/structure/menu/manage/' . $this->entity->id() . '/add')));
     return $form;
 }