Drupal Hook不应用于网站
我正在与请求相关的WebForm中编写一个自定义挂钩,该挂钩将收音机字段(批准,拒绝,转发)授予到电子邮件字段中输入的电子邮件地址(通过请求者)。
整个想法是:
recletor提交表单 - > 董事将通过链接收到一封电子邮件,并选择他是否想批准,拒绝或通过编辑表格
我选择 webform_alter hook来实现这一点
function ach_request_form_alter(array &$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
if($form_id == 'ach_request') { //form's id
if($form['submitted_to']['#value'] === \Drupal::currentUser()->getEmail) { //if the value of the email element is equal to the email address of the current user (director);
$form['approval_state_']['#access'] = TRUE; //the radios element would be visible to the director with the same email address
}
}
}
,然后在终端中使用的drush cr,但仍然看不到选定元素。我的代码有什么问题吗?还是我也需要更改UI上的任何内容?
先感谢您。
I am writing a custom hook in my request related webform which grants access of a radios field (approve, reject, forward to) to the email address that is entered in an email field (by requestor).
the whole idea is:
requetor submits a form -> director will receive an email with the link and choose whether he wants to approve, reject, or pass it to the executives by editing form
I chose webform_alter hook to achieve this
function ach_request_form_alter(array &$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
if($form_id == 'ach_request') { //form's id
if($form['submitted_to']['#value'] === \Drupal::currentUser()->getEmail) { //if the value of the email element is equal to the email address of the current user (director);
$form['approval_state_']['#access'] = TRUE; //the radios element would be visible to the director with the same email address
}
}
}
Then I used drush cr in terminal but the select element is still not visible. Is there anything wrong with my code? Or do I need to change anything on UI as well?
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您实现挂钩时,应将函数名称的“挂钩”一部分替换为居住的模块或主题名称。
例如,
如果您想实现 hook_form_alter 您已将函数放置在名为“ myCoolModule”的自定义模块中,您的函数名称将为...
理解挂钩页面drupal.org
when you implement hooks, the "hook" part of the function name should be replaced with the module or theme name where it resides.
For example,
if you are trying to implement hook_form_alter and you have placed your function in your custom module named "mycoolmodule", your function name would be...
Understanding hooks page on drupal.org