简体   繁体   中英

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.

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?

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.

I am able to do it currently, but this approach alters all the 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) 在此处输入图像描述 So you can check if $form_id start with webform_submission_<webform_id>_<field_machine_name> like this:

function <your_module>_form_alter(&$form, $form_state, $form_id) {
    if (strpos($form_id, 'webform_submission_<webform_id>_<field_machine_name>') === 0) {
        // Your logic
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM