public function RegistrationRoleSettings::buildForm in Registration role 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/ RegistrationRoleSettings.php, line 42
Class
- RegistrationRoleSettings
- Contribute form.
Namespace
Drupal\registration_role\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('registration_role.setting');
$case = $config
->get('role_to_select');
$roles = user_roles(TRUE);
unset($roles['authenticated']);
foreach ($roles as $key => $value) {
$options[$key] = $value
->label();
}
$form['role_to_select'] = array(
'#type' => 'checkboxes',
'#title' => $this
->t('Roles to Assign'),
'#required' => TRUE,
'#options' => $options,
'#default_value' => $case,
'#description' => $this
->t('The selected role will be assigned to users who register using the user-registration form. Be sure this role does not have any privileges you fear giving out without reviewing who receives it.'),
);
$mode_case = $config
->get('registration_mode');
$registration_mode_options = [
'user' => $this
->t('User self registration'),
'admin' => $this
->t('Both user self registration and user creation by admin'),
];
$form['registration_mode'] = array(
'#type' => 'radios',
'#title' => $this
->t('Registration mode'),
'#required' => TRUE,
'#options' => $registration_mode_options,
'#default_value' => $mode_case ? $mode_case : 'user',
'#description' => $this
->t('Select if the role will be assigned only when people self register or also when administrators create users.'),
);
return parent::buildForm($form, $form_state);
}