protected MenuTreeStorage::setParents(array &$fields, $parent, array $original)
Sets the materialized path field values based on the parent.
Parameters
array $fields: The menu link.
array|false $parent: The parent menu link.
array $original: The original menu link.
File
- core/lib/Drupal/Core/Menu/MenuTreeStorage.php, line 462
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 | protected function setParents( array & $fields , $parent , array $original ) { // Directly fill parents for top-level links. if ( empty ( $fields [ 'parent' ])) { $fields [ 'p1' ] = $fields [ 'mlid' ]; for ( $i = 2; $i <= $this ->maxDepth(); $i ++) { $fields [ "p$i" ] = 0; } $fields [ 'depth' ] = 1; } // Otherwise, ensure that this link's depth is not beyond the maximum depth // and fill parents based on the parent link. else { // @todo We want to also check $original['has_children'] here, but that // will be 0 even if there are children if those are not enabled. // has_children is really just the rendering hint. So, we either need // to define another column (has_any_children), or do the extra query. if ( $original ) { $limit = $this ->maxDepth() - $this ->doFindChildrenRelativeDepth( $original ) - 1; } else { $limit = $this ->maxDepth() - 1; } if ( $parent [ 'depth' ] > $limit ) { throw new PluginException( "The link with ID {$fields['id']} or its children exceeded the maximum depth of {$this->maxDepth()}" ); } $fields [ 'depth' ] = $parent [ 'depth' ] + 1; $i = 1; while ( $i < $fields [ 'depth' ]) { $p = 'p' . $i ++; $fields [ $p ] = $parent [ $p ]; } $p = 'p' . $i ++; // The parent (p1 - p9) corresponding to the depth always equals the mlid. $fields [ $p ] = $fields [ 'mlid' ]; while ( $i <= static ::MAX_DEPTH) { $p = 'p' . $i ++; $fields [ $p ] = 0; } } } |
Please login to continue.