I have a product, A, B, C ... variations foo, bar, tar...

I am showing all three products in a url like drupal.dev/all-products.

I managed to display all three products via a webview. Now below these products I am making a webform to handle submissions, and in this webform I would like to be able to show all product variations, but there seems to be no way to fetch product variations in webforms.

How can I go about doing this?

1 Answer 1


You should be able to use the hook_form_alter() to achieve this in a custom module. As long as there is a relationship between the product and its variations you can use the hook_form_alter to add and remove variations from the form. You could also use the module controller to generate a custom twig template that renders content pull from the DB.

hook form alter - https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21form.api.php/function/hook_form_alter/8.4.x

custom twig template - https://www.drupal.org/docs/8/theming/twig/create-custom-twig-templates-from-custom-module

custom webform twig template - How to access webform elements in webform.html.twig

  • Is there any way to do this without writing a custom hook? I am still new to the drupal code and this would take me ages to figure out
    – hidar
    Aug 7, 2017 at 20:18
  • It depends on how much you want to accomplish. If you just want to display the variations as images on the page, perhaps with links to their forms, you can customize the twig template. Editing theme pages is much easier to do than creating a custom module. The answers on this page might be really helpful. drupal.stackexchange.com/questions/232980/… Aug 7, 2017 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.