protected MenuTreeStorage::loadLinks($menu_name, MenuTreeParameters $parameters)
Loads links in the given menu, according to the given tree parameters.
Parameters
string $menu_name: A menu name.
\Drupal\Core\Menu\MenuTreeParameters $parameters: The parameters to determine which menu links to be loaded into a tree. This method will set the absolute minimum depth, which is used in MenuTreeStorage::doBuildTreeData().
Return value
array A flat array of menu links that are part of the menu. Each array element is an associative array of information about the menu link, containing the fields from the {menu_tree} table. This array must be ordered depth-first.
File
- core/lib/Drupal/Core/Menu/MenuTreeStorage.php, line 872
Class
- MenuTreeStorage
- Provides a menu tree storage using the database.
Namespace
Drupal\Core\Menu
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 | protected function loadLinks( $menu_name , MenuTreeParameters $parameters ) { $query = $this ->connection->select( $this ->table, $this ->options); $query ->fields( $this ->table); // Allow a custom root to be specified for loading a menu link tree. If // omitted, the default root (i.e. the actual root, '') is used. if ( $parameters ->root !== '' ) { $root = $this ->loadFull( $parameters ->root); // If the custom root does not exist, we cannot load the links below it. if (! $root ) { return array (); } // When specifying a custom root, we only want to find links whose // parent IDs match that of the root; that's how we ignore the rest of the // tree. In other words: we exclude everything unreachable from the // custom root. for ( $i = 1; $i <= $root [ 'depth' ]; $i ++) { $query ->condition( "p$i" , $root [ "p$i" ]); } // When specifying a custom root, the menu is determined by that root. $menu_name = $root [ 'menu_name' ]; // If the custom root exists, then we must rewrite some of our // parameters; parameters are relative to the root (default or custom), // but the queries require absolute numbers, so adjust correspondingly. if (isset( $parameters ->minDepth)) { $parameters ->minDepth += $root [ 'depth' ]; } else { $parameters ->minDepth = $root [ 'depth' ]; } if (isset( $parameters ->maxDepth)) { $parameters ->maxDepth += $root [ 'depth' ]; } } // If no minimum depth is specified, then set the actual minimum depth, // depending on the root. if (!isset( $parameters ->minDepth)) { if ( $parameters ->root !== '' && $root ) { $parameters ->minDepth = $root [ 'depth' ]; } else { $parameters ->minDepth = 1; } } for ( $i = 1; $i <= $this ->maxDepth(); $i ++) { $query ->orderBy( 'p' . $i , 'ASC' ); } $query ->condition( 'menu_name' , $menu_name ); if (! empty ( $parameters ->expandedParents)) { $query ->condition( 'parent' , $parameters ->expandedParents, 'IN' ); } if (isset( $parameters ->minDepth) && $parameters ->minDepth > 1) { $query ->condition( 'depth' , $parameters ->minDepth, '>=' ); } if (isset( $parameters ->maxDepth)) { $query ->condition( 'depth' , $parameters ->maxDepth, '<=' ); } // Add custom query conditions, if any were passed. if (! empty ( $parameters ->conditions)) { // Only allow conditions that are testing definition fields. $parameters ->conditions = array_intersect_key ( $parameters ->conditions, array_flip ( $this ->definitionFields())); $serialized_fields = $this ->serializedFields(); foreach ( $parameters ->conditions as $column => $value ) { if ( is_array ( $value )) { $operator = $value [1]; $value = $value [0]; } else { $operator = '=' ; } if (in_array( $column , $serialized_fields )) { $value = serialize( $value ); } $query ->condition( $column , $value , $operator ); } } $links = $this ->safeExecuteSelect( $query )->fetchAllAssoc( 'id' , \PDO::FETCH_ASSOC); return $links ; } |
Please login to continue.