我正在处理Drupal 8中的自定义模块,它应该在Honeypot模块的帮助下保护Simpleform表单。
到目前为止,我可以启用我的模块在Drupal工作完美,但蜜罐保护没有添加到表单。我现在的一个问题是,我不知道表单ID是什么。这就是为什么我试图记录整个表单--这也是不起作用的。
在加载包含Simpleform的页面时,我的.module文件中的整个代码似乎都被Drupal绕过了。我在这里做错什么了?
我的档案:
overwrite_simplenews.info.yml
name: Overwrite Simplenews
type: module
description: 'Enable Honeypot for Simplenews plugin'
package: Custom
core: 8.xoverwrite_simplenews.module
<?php
function hook_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id){
if ($form_id == 'simplenews_subscriptions_block_dc6f06ce_ad69-46de_8d8d'){
honeypot_add_form_protection($form, $form_state, array('honeypot'));
}
$message = 'Form content: <pre>' . print_r($form, TRUE) . '</pre>';
\Drupal::logger('overwrite_simplenews')->notice($message);
}发布于 2021-01-21 10:13:18
所有挂钩必须根据您的模块名称“重命名”。例如,要使用hook_form_alter,必须调用函数: overwrite_simplenews_form_alter();
https://stackoverflow.com/questions/65824820
复制相似问题