【问题标题】:Drupal 8 hook_form_alter not called in the search block formDrupal 8 hook_form_alter 未在搜索块表单中调用
【发布时间】:2016-12-30 08:25:09
【问题描述】:

我正在尝试在我的 Drupal 8 项目中修改搜索块的表单操作。搜索块放置在主菜单区域中。我在我的 .theme 文件中添加了以下代码

function mytheme_form_alter(&$form, FormStateInterface $form_state, $form_id) {
echo 'my search form'.$form_id; 
}

页面加载时不会调用这个表单alter。

我尝试在我的自定义模块中添加 form_alter。它也不起作用。有任何想法吗?

【问题讨论】:

    标签: drupal-8 drupal-forms drupal-hooks


    【解决方案1】:

    我找到了答案。我们可以在主题文件夹中的block--search.html.twig文件中更改表单动作。

    【讨论】:

      【解决方案2】:

      你不能在主题中使用 hook_form_alter,只能在模块中使用

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-11-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-12
        • 2016-08-07
        相关资源
        最近更新 更多