-1

Working in D8, I am trying to insert a form into an already created page/template file.

I am using webforms, and on the webform submission page (that lists the submission details), I am trying to insert a custom form to do some additional stuff. I already have the form generated, but I cannot find the correct way to insert the form into the template/page.

I tried using \Drupal::formBuilder()->getForm(form_name) in the twig template where I wanted it, but Drupal didn't like that.

I then tried to use hook_page_bottom and hook_page_top, but that quite literally attaches it to the very top of the page, or very bottom of the page (outside of the bounds of the theme/template), not where I want it to be.

I am already overriding the template using the naming convention webform-submission--webform-machine-name.html.twig.

I am assuming since you can override the default templates for webform submissions, that the webform module implements hook_theme or some other similar hook. Is there a way I can hook into this hook and pass the form off as a variable, then just render it in the actual template using {{ form }}, or do I need to create my own override and pass both the submission data and the form data into it?

I miss the days when I could just use $form = drupal_get_form(); and print render($form); inside of the template exactly where I wanted it.

5
  • Thank you for the cleanup.
    – Ex0r
    Jul 4, 2020 at 0:38
  • There is a webform reference field for content types, and you can also add this field to a custom block type. Is there a reason this may not be a good approach for you? Is your custom form not a webform? Jul 4, 2020 at 2:59
  • Correct. It's a module created form that is generated programmatically. I could make the form a block on the page, but then I'm not able to stick it specifically where I want it on the page and it'll place it either above or below the content on the page. There's a specific place in the content it needs to live.
    – Ex0r
    Jul 4, 2020 at 9:30
  • Related: drupal.stackexchange.com/questions/231200/…
    – sonfd
    Jul 4, 2020 at 10:46
  • This isn't a related question. I'm not trying to render a webform in a page, I'm trying to render a programmatically built form inside of a different programmatically built page. I can't render the form directly in the twig template so I'm looking for another way to do it.
    – Ex0r
    Jul 4, 2020 at 11:59

1 Answer 1

0

I was able to resolve this myself using template_preprocess() and generating the form from there

Your Answer

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

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