public function LoginRedirectionForm::buildForm in Redirect after login 8
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
File
- src/
Form/ LoginRedirectionForm.php, line 27 - Contains \Drupal\redirect_after_login\Form\LoginRedirectionForm.
Class
Namespace
Drupal\redirect_after_login\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$savedPathRoles = \Drupal::config('redirect_after_login.settings')
->get('login_redirection');
$this->allUser = user_role_names();
$form['roles'] = array(
'#type' => 'fieldset',
'#title' => t('All roles'),
);
foreach ($this->allUser as $user => $name) {
$form['roles'][$user] = [
'#type' => 'textfield',
'#title' => t($name),
'#size' => 60,
'#maxlength' => 128,
'#description' => t('Add a valid url or <front> for main page'),
'#required' => TRUE,
'#default_value' => $savedPathRoles[$user],
];
}
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Save'),
'#button_type' => 'primary',
];
// Disable caching
$form['#cache']['max-age'] = 0;
return $form;
}