Skip to content
Snippets Groups Projects
Commit c24c5794 authored by Andrey Vitushkin's avatar Andrey Vitushkin
Browse files

Issue #3451882: Add the "CIDR" checkbox to the storage settings form of the...

Issue #3451882: Add the "CIDR" checkbox to the storage settings form of the "ipaddress_pgsql" field type
parent 78304967
No related branches found
No related tags found
No related merge requests found
field.field_settings.ipaddress_pgsql:
field.storage_settings.ipaddress_pgsql:
type: mapping
label: 'IP address settings'
mapping:
......@@ -9,7 +9,7 @@ field.field_settings.ipaddress_pgsql:
type: boolean
label: 'Restrict to cidr format'
field.field_settings.ipaddress_mysql:
field.storage_settings.ipaddress_mysql:
type: mapping
label: 'IP address settings'
mapping:
......
......@@ -7,6 +7,7 @@ namespace Drupal\field_ipaddress_pgsql\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\TypedData\DataDefinition;
/**
......@@ -28,7 +29,41 @@ final class IpAddressPostgreSqlField extends FieldItemBase {
* {@inheritdoc}
*/
public static function defaultStorageSettings(): array {
return [] + parent::defaultStorageSettings();
return [
'protocol' => 'ipv4',
'cidr_format' => FALSE,
] + parent::defaultStorageSettings();
}
/**
* {@inheritdoc}
*/
public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
$element = [];
$element['protocol'] = [
'#type' => 'radios',
'#title' => $this->t('IP version allowed'),
'#options' => [
'ipv4' => $this->t('IPv4'),
'ipv6' => $this->t('IPv6'),
],
'#description' => $this->t('Select the IP address family that are allowed.'),
'#default_value' => $this->getSetting('protocol'),
];
$description = $this->t('If checked, only allow addresses that comply with <a href=":url" target="_blank">CIDR</a> notation.', [
':url' => 'https://www.postgresql.org/docs/16/datatype-net-types.html#DATATYPE-CIDR',
]);
$element['cidr_format'] = [
'#type' => 'checkbox',
'#title' => $this->t('CIDR'),
'#description' => $description,
'#default_value' => $this->getSetting('cidr_format'),
];
return $element;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment