Skip to main content
removed "Drupal" from the title; removed tags from the title
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

How do you load Why doesn't loading a form using drupal_get_form() but in Drupal 8the view header work?

Source Link
Patoshi パトシ
  • 8.7k
  • 14
  • 80
  • 166

How do you load a form using drupal_get_form() but in Drupal 8?

I've been checking for the past 2 days on how to do a drupal_get_form() for Drupal 8 and everyone seems to give me the following answers which don't seem to work. Let's just say I want to take the following Basic Page creation form and embed it into a Views header:

enter image description here

The ID of the form is: node-page-form or node_page_form if we were using drupal_get_form() from Drupal 7. But this time its the following:

$form = \Drupal::formBuilder()->getForm(Drupal\user\Form\NodePageForm::class);

I'm assuming "NodePageForm" is the parameter I'm suppose to use. If not how can one find this out from viewing the source of that page?

I then put the following PHP code in the Views header of my page like this:

enter image description here

I click save and update... my header is blank. What did I do wrong?

I'm trying to be as descriptive as I can explaining this problem. End result I just want to be able to take ANY form from any D8 page and be able to render it anywhere that takes PHP. That's my end goal. So no 3rd party modules as a solution.