protected MenuForm::buildOverviewTreeForm($tree, $delta)
Recursive helper function for buildOverviewForm().
Parameters
\Drupal\Core\Menu\MenuLinkTreeElement[] $tree: The tree retrieved by \Drupal\Core\Menu\MenuLinkTreeInterface::load().
int $delta: The default number of menu items used in the menu weight selector is 50.
Return value
array The overview tree form.
File
- core/modules/menu_ui/src/MenuForm.php, line 338
Class
- MenuForm
- Base form for menu edit forms.
Namespace
Drupal\menu_ui
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | protected function buildOverviewTreeForm( $tree , $delta ) { $form = & $this ->overviewTreeForm; $tree_access_cacheability = new CacheableMetadata(); foreach ( $tree as $element ) { $tree_access_cacheability = $tree_access_cacheability ->merge(CacheableMetadata::createFromObject( $element ->access)); // Only render accessible links. if (! $element ->access->isAllowed()) { continue ; } /** @var \Drupal\Core\Menu\MenuLinkInterface $link */ $link = $element ->link; if ( $link ) { $id = 'menu_plugin_id:' . $link ->getPluginId(); $form [ $id ][ '#item' ] = $element ; $form [ $id ][ '#attributes' ] = $link ->isEnabled() ? array ( 'class' => array ( 'menu-enabled' )) : array ( 'class' => array ( 'menu-disabled' )); $form [ $id ][ 'title' ] = Link::fromTextAndUrl( $link ->getTitle(), $link ->getUrlObject())->toRenderable(); if (! $link ->isEnabled()) { $form [ $id ][ 'title' ][ '#suffix' ] = ' (' . $this ->t( 'disabled' ) . ')' ; } // @todo Remove this in https://www.drupal.org/node/2568785. elseif ( $id === 'menu_plugin_id:user.logout' ) { $form [ $id ][ 'title' ][ '#suffix' ] = ' (' . $this ->t( '<q>Log in</q> for anonymous users' ) . ')' ; } // @todo Remove this in https://www.drupal.org/node/2568785. elseif (( $url = $link ->getUrlObject()) && $url ->isRouted() && $url ->getRouteName() == 'user.page' ) { $form [ $id ][ 'title' ][ '#suffix' ] = ' (' . $this ->t( 'logged in users only' ) . ')' ; } $form [ $id ][ 'enabled' ] = array ( '#type' => 'checkbox' , '#title' => $this ->t( 'Enable @title menu link' , array ( '@title' => $link ->getTitle())), '#title_display' => 'invisible' , '#default_value' => $link ->isEnabled(), ); $form [ $id ][ 'weight' ] = array ( '#type' => 'weight' , '#delta' => $delta , '#default_value' => $link ->getWeight(), '#title' => $this ->t( 'Weight for @title' , array ( '@title' => $link ->getTitle())), '#title_display' => 'invisible' , ); $form [ $id ][ 'id' ] = array ( '#type' => 'hidden' , '#value' => $link ->getPluginId(), ); $form [ $id ][ 'parent' ] = array ( '#type' => 'hidden' , '#default_value' => $link ->getParent(), ); // Build a list of operations. $operations = array (); $operations [ 'edit' ] = array ( 'title' => $this ->t( 'Edit' ), ); // Allow for a custom edit link per plugin. $edit_route = $link ->getEditRoute(); if ( $edit_route ) { $operations [ 'edit' ][ 'url' ] = $edit_route ; // Bring the user back to the menu overview. $operations [ 'edit' ][ 'query' ] = $this ->getDestinationArray(); } else { // Fall back to the standard edit link. $operations [ 'edit' ] += array ( 'url' => Url::fromRoute( 'menu_ui.link_edit' , [ 'menu_link_plugin' => $link ->getPluginId()]), ); } // Links can either be reset or deleted, not both. if ( $link ->isResettable()) { $operations [ 'reset' ] = array ( 'title' => $this ->t( 'Reset' ), 'url' => Url::fromRoute( 'menu_ui.link_reset' , [ 'menu_link_plugin' => $link ->getPluginId()]), ); } elseif ( $delete_link = $link ->getDeleteRoute()) { $operations [ 'delete' ][ 'url' ] = $delete_link ; $operations [ 'delete' ][ 'query' ] = $this ->getDestinationArray(); $operations [ 'delete' ][ 'title' ] = $this ->t( 'Delete' ); } if ( $link ->isTranslatable()) { $operations [ 'translate' ] = array ( 'title' => $this ->t( 'Translate' ), 'url' => $link ->getTranslateRoute(), ); } $form [ $id ][ 'operations' ] = array ( '#type' => 'operations' , '#links' => $operations , ); } if ( $element ->subtree) { $this ->buildOverviewTreeForm( $element ->subtree, $delta ); } } $tree_access_cacheability ->merge(CacheableMetadata::createFromRenderArray( $form )) ->applyTo( $form ); return $form ; } |
Please login to continue.