public function IpAddressField::fieldSettingsForm in IP address fields 8
Same name and namespace in other branches
- 2.0.x src/Plugin/Field/FieldType/IpAddressField.php \Drupal\field_ipaddress\Plugin\Field\FieldType\IpAddressField::fieldSettingsForm()
Returns a form for the field-level settings.
Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow administrators to configure field-level settings.
Parameters
array $form: The form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface $form_state: The form state of the (entire) configuration form.
Return value
array The form definition for the field settings.
Overrides FieldItemBase::fieldSettingsForm
File
- src/
Plugin/ Field/ FieldType/ IpAddressField.php, line 129
Class
- IpAddressField
- Plugin implementation of the 'ipaddress' field type.
Namespace
Drupal\field_ipaddress\Plugin\Field\FieldTypeCode
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$element = [];
$settings = $this
->getSettings();
$element['allow_family'] = [
'#type' => 'radios',
'#title' => $this
->t('IP version(s) allowed'),
'#options' => [
IpAddress::IP_FAMILY_4 => $this
->t('IPv4'),
IpAddress::IP_FAMILY_6 => $this
->t('IPv6'),
IpAddress::IP_FAMILY_ALL => $this
->t('Both IPv4 and IPv6'),
],
'#description' => $this
->t('Select the IP address family (or families) that are allowed.'),
'#default_value' => $settings['allow_family'],
];
$element['allow_range'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Allow IP Range'),
'#default_value' => $settings['allow_range'],
];
$element['ip4_range'] = [
'#type' => 'textfield',
'#title' => $this
->t('Allowed IPv4 range.'),
'#description' => $this
->t('The range of IPv4 addresses to allow. Leave blank to allow any valid IPv4 address.'),
'#states' => [
'visible' => [
[
':input[name="settings[allow_range]"]' => [
'checked' => TRUE,
],
':input[name="settings[allow_family]"]' => [
'value' => IpAddress::IP_FAMILY_4,
],
],
[
':input[name="settings[allow_range]"]' => [
'checked' => TRUE,
],
':input[name="settings[allow_family]"]' => [
'value' => IpAddress::IP_FAMILY_ALL,
],
],
],
],
'#default_value' => $settings['ip4_range'],
'#element_validate' => [
[
$this,
'validateIpAddressElement',
],
],
];
$element['ip6_range'] = [
'#type' => 'textfield',
'#title' => $this
->t('Allowed IPv6 range.'),
'#description' => $this
->t('The range of IPv6 addresses to allow. Leave blank to allow any valid IPv6 address.'),
'#states' => [
'visible' => [
[
':input[name="settings[allow_range]"]' => [
'checked' => TRUE,
],
':input[name="settings[allow_family]"]' => [
'value' => IpAddress::IP_FAMILY_6,
],
],
[
':input[name="settings[allow_range]"]' => [
'checked' => TRUE,
],
':input[name="settings[allow_family]"]' => [
'value' => IpAddress::IP_FAMILY_ALL,
],
],
],
],
'#default_value' => $settings['ip6_range'],
'#element_validate' => [
[
$this,
'validateIpAddressElement',
],
],
];
return $element;
}