简体   繁体   English

如何根据其父段落类型更改网络表单?

[英]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.

相关问题 如何通过在 Drupal 8 中使用 hook_form_alter 在节点表单中添加一个段落(默认)? - How can I add a paragraph (as default) in the node form by using hook_form_alter in Drupal 8? Drupal 8 如何改变段落形式? - Drupal 8 how to alter paragraph form? 如何从 webform 处理程序中的 drupal webform url 字段获取 url - How do i get the url from a drupal webform url field in a webform handler 如何对一个调度事件的方法进行单元测试,该事件会更改被测方法的行为? - How can I unit test a method that dispatches events that alter behavior of the method under test? 当已经有了它的机器名称时,如何获得节点内容类型的 label? - how can I get the label of a node´s content type, when already having the machine name of it? 我们如何访问在Drupal 8中由内容类型的字段引用的视图中的段落字段 - How can we access the fields of a paragraph in views which is referred by a field of a content type in Drupal 8 我可以在导出Drupal 8 Webform提交的CSV文件时对列进行重新排序吗? - Can I re-order columns in exporting CSV on Drupal 8 Webform Submissions? 如何从Drupal 8中的模块更改节点模板? - How do I alter a node template from a module in Drupal 8? 在Drupal 8中查询段落类型 - Query Paragraph Type in Drupal 8 如何在内容类型drupal下显示所有内容 - How can i display all content under content type drupal
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM