【问题标题】:Hook not working in drupal 8钩子在drupal 8中不起作用
【发布时间】:2017-12-21 11:09:06
【问题描述】:
<?php
/**
 * @file
 */
/**
 * Implements hook_page_alter().
 */
function glue_page_alter(&$page) {
    $page['content']['bartik.content']['content']['#markup'] = 'Hello Content!';
}

这个钩子有什么问题?它不会运行(8.4.3)。我也清除了缓存

【问题讨论】:

    标签: drupal-8 drupal-hooks


    【解决方案1】:

    在 Drupal 7 中,当我们需要修改由其他模块添加的页面元素时,hook_page_alter 是一种方便的方法。 Drupal 8 取消了这个钩子——希望变得更好。为了填补 hook_page_alter 的解雇造成的空白,引入了以下钩子。

    hook_page_attachments()
    hook_page_attachments_alter()
    hook_page_top()
    hook_page_bottom()
    hook_theme_suggestions_HOOK()
    hook_theme_suggestions_HOOK_alter()
    

    来源:https://cryptic.zone/blog/where-hook_page_alter-drupal-8

    【讨论】:

    • 您知道在 drupal 8.4.3 中添加任何新内容时运行的任何挂钩吗?喜欢新文章,页面。
    • hook_node_presave 或 hook_entity_presave
    • 非常感谢,可以从 _node_presave 设置响应头吗?
    • 我知道我可以通过drupal 8中的事件来做到这一点,但由于某种原因需要在这个函数中添加标题。
    猜你喜欢
    • 1970-01-01
    • 2018-10-08
    • 2014-01-19
    • 2015-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-24
    • 1970-01-01
    相关资源
    最近更新 更多