HOOK_page_alter 在 Drupal 8 中

HOOK_page_alter in Drupal 8

我正在尝试在每一页上附加一个树枝模板。
在 Drupal 7 中,我们基本上使用 hook_page_alter

附加它
function hook_page_alter(&$page) { 
  $page['page_bottom']['devel']= array(
    '#type' => 'markup',
    '#markup' => '<div style="clear:both;">' . theme('TEST') . '</div>',
  ); // add test template on every page at bottom position.
}

但我认为在 Drupal 8 中没有 hook_page_alter

如何在 drupal 8 中执行此操作?

您可以在 Drupal 8 中使用 hook_preprocess_page(&$variables) 来更改页面内容。

示例:

function bartik_preprocess_page(&$variables){

   $variables['page']['footer_fourt']['test']= array( 
        '#type' => 'markup', 
        '#markup' => '<div style="clear:both;">hello test</div>', );
   kint($variables['page']['footer_fourt']['test']);        
}

即使您可以在主题中使用 kint() ,只需将您的主题附加到变量中即可

What happened to hook_page_alter is explained here in the Drupal change record 所以在你的情况下你可能会使用 hook_page_bottom.