Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickopris/44bdf701d7f216996dbd6a4ab718cbce to your computer and use it in GitHub Desktop.
Save nickopris/44bdf701d7f216996dbd6a4ab718cbce to your computer and use it in GitHub Desktop.
Drupal 8 - Pass arguments to buildForm()
// in preprocessing.php
$variables['lead_form'] =
\Drupal::formBuilder()->getForm('Drupal\my_form_module\Form\LeadForm', 'hero_video');
//it passes that extra variable through getForm into an arguments array added on the end of buildForm
public function buildForm(array $form, FormStateInterface $form_state, string $gated_content_context = NULL) {
if($gated_content_context === 'hero_video') {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment