I have used Webform many times before but this is the first time I am testing Webform Node :
Provides a Webform content type which allows webforms to be integrated into a website as nodes.
Usually, I integrate webforms with blocks.
Everything works fine but I notice that the webform $form_id
contains the node id (here nid = 174
):
webform_submission_shop_contact_node_174_add_form
This poses a problem for me because I want to make a hook to add a library. The hook will therefore not be able to work on all environments once deployed because here the node is content and the nid will be different.
In hook_form_alter
if ($form_id === 'webform_submission_shop_contact_node_174_add_form') {
$form['#attached']['library'][] = 'custom_theme/contact';
}
Do you know if I can modify the id of this webform integrated into a node?
I saw this option here /admin/structure/webform/manage/{webform}/settings/form
which allows you to create a custom id but this has no effect (probably because the webform is integrated into a node).
webform_submission_shop_contact_form
in your case, or the webform IDshop_contact
?dump($form)
, I can clearly see the#webform_id
key :shop_contact
. I can now add my library like this inhook_form_alter
:if (isset($form['#webform_id']) && $form['#webform_id'] === 'shop_contact') { ... }
So simple, it works. Do you want to answer the question so I can vote?