[英]How can I alter the webform based on it's parent paragraph type?
The target for me is a custom paragraph type that I made which allows you to embed a webform in it.我的目标是我制作的自定义段落类型,它允许您在其中嵌入网络表单。 I need to update the submit callback for only those forms which are added in this paragraph type.
我只需要更新在此段落类型中添加的那些 forms 的提交回调。
I have used the hook to alter the form, but I can't seem to find the reference to the parent paragraph type in that hook to put the condition.我已经使用钩子来更改表单,但我似乎无法在该钩子中找到对父段落类型的引用来放置条件。
Alternatively, when I am preprocessing the paragraph, I have access to the content and in turn the webform entity, but I can't update the form settings from that function?或者,当我预处理段落时,我可以访问内容,进而访问网络表单实体,但我无法从该 function 更新表单设置?
Edit: The ultimate goal is for me to handle the ajax submit by default method but in my custom callback function so that I want to override the response with an additional command.编辑:最终目标是让我处理 ajax 默认方法提交,但在我的自定义回调 function 中,以便我想用附加命令覆盖响应。
I am able to do it currently, but this approach alters all the forms.我目前能够做到,但这种方法会改变所有 forms。
Any help would be appreciated.任何帮助,将不胜感激。 I have not added the code blocks here since the implementation is pretty generic, but if somebody wants to take a look at the code, let me know.
由于实现非常通用,因此我没有在此处添加代码块,但是如果有人想查看代码,请告诉我。
The $form_id
is always in the form webform_submission_<webform_id>_<field_machine_name>_<delta>_add_form
(see my example below) $form_id
始终采用webform_submission_<webform_id>_<field_machine_name>_<delta>_add_form
(参见下面的示例) So you can check if
$form_id
start with webform_submission_<webform_id>_<field_machine_name>
like this:因此,您可以检查
$form_id
是否以webform_submission_<webform_id>_<field_machine_name>
开头,如下所示:
function <your_module>_form_alter(&$form, $form_state, $form_id) {
if (strpos($form_id, 'webform_submission_<webform_id>_<field_machine_name>') === 0) {
// Your logic
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.