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

Issue #3453146: Add the possibility to store the "Default gateway" to the "ipaddress_mysql" widget

parent 3b41d6f3
No related branches found
No related tags found
No related merge requests found
......@@ -41,6 +41,15 @@ final class IpAddressMySqlWidget extends WidgetBase {
'#default_value' => $defaultValue,
];
if ($this->getFieldSetting('default_gateway_enabled')) {
$defaultGateway = inet_ntop($items[$delta]->default_gateway);
$element['gateway_value'] = [
'#type' => 'textfield',
'#title' => $this->t('Default Gateway'),
'#default_value' => $defaultGateway ?? '',
];
}
return $element;
}
......@@ -60,6 +69,9 @@ final class IpAddressMySqlWidget extends WidgetBase {
$networkMask = (string) Network::parse($value)->getNetmask();
$item['ip_address'] = inet_pton($ipAddress);
$item['network_mask'] = inet_pton($networkMask);
if ($this->getFieldSetting('default_gateway_enabled')) {
$item['default_gateway'] = inet_pton(trim($item['gateway_value']));
}
}
catch (\Exception $e) {
// Set some values, because if the values are empty, then the validate()
......@@ -68,6 +80,9 @@ final class IpAddressMySqlWidget extends WidgetBase {
// validator handler in the formElement() methods.
$item['ip_address'] = 'invalid';
$item['network_mask'] = 'invalid';
if ($this->getFieldSetting('default_gateway_enabled')) {
$item['default_gateway'] = 'invalid';
}
}
}
return $values;
......
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