【发布时间】:2022-06-12 07:04:44
【问题描述】:
我正在与我的请求相关的网络表单中编写一个自定义钩子,它授予对在电子邮件字段中输入的电子邮件地址(由请求者)访问无线电字段(批准、拒绝、转发)的权限。
整个想法是:
请求者提交表单 -> 主管将收到一封包含链接的电子邮件,并选择是否要批准、拒绝或通过编辑表单将其传递给主管
我选择了 webform_alter 钩子来实现这个
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 上的任何内容?
提前谢谢你。
【问题讨论】:
标签: php drupal hook drupal-webform