Guest User


a guest
Jul 28th, 2016
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Firstly, you might be confused about what `FormBuilder::getForm` is expecting as a parameter. It's looking for a string representation of the class name, fully qualified with namespaces.
  3. As a contrived example, that could be `'\Drupal\foo\Form\BarForm'`. Note the quotes, meaning it's a string.
  5. So to load a form, you would use this (again pay attention to the quotes):
  7. $form = \Drupal::formBuilder()->getForm('\Drupal\foo\Form\BarForm');
  9. Now, since PHP 5.5, classes have an implicit static `::class` method, which returns the fully-qualified class name as a string. So the above can become:
  11. $form = \Drupal::formBuilder()->getForm(\Drupal\foo\Form\BarForm::class);
  13. Notice the absence of quotes this time, as `::class` returns the string we're looking for.
  15. The second method is better, as it's less prone to error. You'll get a fatal error from the interpreter if you reference an invalid class, rather than a runtime error if you use a string.
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add to your ad blocker whitelist or disable your adblocking software.