public function UserSettingsForm::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/ UserSettingsForm.php, line 49
Class
- UserSettingsForm
- Class UserSettingsForm.
Namespace
Drupal\restrict_by_ip\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('restrict_by_ip.settings');
$form['new_restriction'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Add new user allowed IP range'),
];
$form['new_restriction']['name'] = [
'#type' => 'entity_autocomplete',
'#target_type' => 'user',
'#title' => t('Username'),
];
$form['new_restriction']['restriction'] = [
'#type' => 'textfield',
'#title' => t('Allowed IP range'),
'#description' => 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>.'),
'#maxlength' => NULL,
];
// Current restrictions.
foreach ($config
->get('user') as $key => $value) {
$account = \Drupal\user\Entity\User::load($key);
$form['restrict_by_ip_user_' . $key] = [
'#type' => 'textfield',
'#title' => $this
->t('@name user IP range', [
'@name' => $account
->label(),
]),
'#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 @name.', [
'@name' => $account
->label(),
]),
'#default_value' => $config
->get('user.' . $key),
];
}
return parent::buildForm($form, $form_state);
}