public function RoleSettingsForm::buildForm in Restrict Login or Role Access by IP Address 8.4
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/ RoleSettingsForm.php, line 50
Class
- RoleSettingsForm
- Class RoleSettingsForm.
Namespace
Drupal\restrict_by_ip\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('restrict_by_ip.settings');
$user_roles = user_roles(TRUE);
// Get all roles except anonymous
unset($user_roles['authenticated']);
// Remove default authenticated user role
if (count($user_roles) === 0) {
$form['no_roles'] = [
'#markup' => $this
->t('No roles configured. <a href="@add-role">Add a role</a>.', [
'@add-role' => Url::fromRoute('entity.user_role.collection'),
]),
'#prefix' => '<p>',
'#suffix' => '</p>',
];
}
foreach ($user_roles as $role) {
$form['restrict_by_ip_role_' . $role
->id()] = [
'#type' => 'textfield',
'#title' => $this
->t('@role-label role IP range', [
'@role-label' => $role
->label(),
]),
'#maxlength' => NULL,
'#description' => $this
->t('Enter IP Address Ranges in CIDR Notation separated with semi-colons, with no trailing semi-colon. E.G. 10.20.30.0/24;192.168.199.1/32;1.0.0.0/8<br />For more information on CIDR notation click <a href="http://www.brassy.net/2007/mar/cidr_basic_subnetting">here</a>.<br />Leave field blank to disable IP restrictions for ' . $role
->label() . '.'),
'#default_value' => $config
->get('role.' . $role
->id()),
];
}
return parent::buildForm($form, $form_state);
}