protected MenuTreeStorage::moveChildren($fields, $original)
Re-parents a link's children when the link itself is moved.
Parameters
array $fields: The changed menu link.
array $original: The original menu link.
File
- core/lib/Drupal/Core/Menu/MenuTreeStorage.php, line 512
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 | protected function moveChildren( $fields , $original ) { $query = $this ->connection->update( $this ->table, $this ->options); $query ->fields( array ( 'menu_name' => $fields [ 'menu_name' ])); $expressions = array (); for ( $i = 1; $i <= $fields [ 'depth' ]; $i ++) { $expressions [] = array ( "p$i" , ":p_$i" , array ( ":p_$i" => $fields [ "p$i" ])); } $j = $original [ 'depth' ] + 1; while ( $i <= $this ->maxDepth() && $j <= $this ->maxDepth()) { $expressions [] = array ( 'p' . $i ++, 'p' . $j ++, array ()); } while ( $i <= $this ->maxDepth()) { $expressions [] = array ( 'p' . $i ++, 0, array ()); } $shift = $fields [ 'depth' ] - $original [ 'depth' ]; if ( $shift > 0) { // The order of expressions must be reversed so the new values don't // overwrite the old ones before they can be used because "Single-table // UPDATE assignments are generally evaluated from left to right". $expressions = array_reverse ( $expressions ); } foreach ( $expressions as $expression ) { $query ->expression( $expression [0], $expression [1], $expression [2]); } $query ->expression( 'depth' , 'depth + :depth' , array ( ':depth' => $shift )); $query ->condition( 'menu_name' , $original [ 'menu_name' ]); for ( $i = 1; $i <= $this ->maxDepth() && $original [ "p$i" ]; $i ++) { $query ->condition( "p$i" , $original [ "p$i" ]); } $query ->execute(); } |
Please login to continue.