Error Passing Extra Parameter to Custom Form
I have a simple custom form that works until I try to add a custom parameter for my module called “forms_admin”.
These are the contents of my forms_admin.routing.yml
forms_admin.settings: path: 'admin/config/system/forms/{arg1}' defaults: _form: 'Drupalforms_adminFormFormSettings' _title: 'Forms Settings' requirements: _permission: 'access content'
This is a relevant part of my FormSettings.php file (Currently do not have any custom Validation or Submit actions)
public function buildForm(array $form, FormStateInterface $form_state, $arg1 = NULL) { $form['title'] = array( '#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), ); return $form; }
The moment that I add {arg1} to my forms_admin.routing.yml and , $arg1 = NULL to my FormSettings.php file, I am unable to acces the website.
I receive a white page with the error that states:
The website encountered an unexpected error. Please try again later.
After removing arg1 from my two files and going to the Recent Log messages, this is the error I receive:
SymfonyComponentRoutingExceptionMissingMandatoryParametersException: Some mandatory parameters are missing (“arg1”) to generate a URL for route “forms_admin.settings”. in DrupalCoreRoutingUrlGenerator->doGenerate() (line 182 of /var/www/test_site/docroot/core/lib/Drupal/Core/Routing/UrlGenerator.php).
I have tried changing arg1 to other names, not making $arg1 = NULL, etc. and I receive an error every time.
What am I missing?