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: '\Drupal\forms_admin\Form\FormSettings'
_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;
}
And my third file is: forms_admin.links.menu.yml
forms_admin.config:
title: Forms
route_name: forms_admin.settings
parent: system.admin_config_system
description: 'Forms settings'
weight: 0
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:
Symfony\Component\Routing\Exception\MissingMandatoryParametersException: Some mandatory parameters are missing ("arg1") to generate a URL for route "forms_admin.settings". in Drupal\Core\Routing\UrlGenerator->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?
ban.routing.yml
there are two routes with parameters, but onlyban.admin_page
specifies a default for its parameter.