How to show menu in children page`s child page

This is my code. I show menu in page and it’s child pages. The question is, how to show this menu in children’s child pages?

/**
* Implements hook_preprocess_page().
*/
function agnian_material_admin_preprocess_page(&$variables) {
// @todo: add an if statement to add below data only for “page__admin__content” page.
$variables[‘node_types’] = node_type_get_names();

/**
* Render “admin/structure” page’s menu in it’s all subpages.
*/
// get current page path
$path = Drupal::request()->getPathInfo();
if(strpos($path, ‘/admin/structure’) !== false) {
$tree = Drupal::menuTree();
$params = $tree->getCurrentRouteMenuTreeParameters(‘admin’);
$admin_menu = $tree->load(‘admin’, $params);
$admin_structure_menu = array_key_exists(‘system.admin_structure’, $admin_menu[‘system.admin’]->subtree) ? $admin_menu[‘system.admin’]->subtree[‘system.admin_structure’] : null;
if($admin_structure_menu) {
$subtree = $tree->build($admin_structure_menu->subtree);

/* this part is only for syncing menu items positions between “admin/structure” page and it’s child pages */
$old_items = $subtree[‘#items’];
$tmp = $subtree[‘#items’] = array();
foreach($old_items as $key => $value) $tmp[$key] = $value[‘title’];
asort($tmp);
foreach($tmp as $key => $value) $subtree[‘#items’][$key] = $old_items[$key];
/* end of sync */

$variables[‘admin_menu’] = $subtree;
}
}
/** End Of Render “admin/structure” page’s menu in it’s all subpages. */
}

Drupal version: 


Source: https://www.drupal.org/taxonomy/term/22/feed