Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interfaces: fix value lookup in LinkAddressField #8161 #8162

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,16 @@ public function getPredefinedOptions()
public function getValidators()
{
$validators = parent::getValidators();
if ($this->internalValue != null) {
$validators[] = new CallbackValidator(["callback" => function ($data) {
$messages = [];
if (isset(self::$known_addresses[$data])) {
return $messages;
} elseif (!Util::isIpAddress($data)) {
$messages[] = gettext('A valid network address is required.');
}

$validators[] = new CallbackValidator(["callback" => function ($data) {
$messages = [];
if (isset(self::$known_addresses[$data])) {
return $messages;
}]);
}
} elseif (!Util::isIpAddress($data)) {
$messages[] = gettext('A valid network address is required.');
}
return $messages;
}]);

return $validators;
}
Expand All @@ -113,24 +112,29 @@ public function getValidators()
*/
public function getDescription()
{
if (isset(self::$known_addresses[$this->internalValue])) {
return self::$known_addresses[$this->internalValue];
$value = $this->getCurrentValue() ?? '';

if (isset(self::$known_addresses[$value])) {
return self::$known_addresses[$value];
}
return $this->internalValue;

return $value;
}

/**
* return either ipaddr or if field, only one should be used, addresses are preferred.
*/
public function __toString()
public function getCurrentValue(): ?string
{
$parent = $this->getParentNode();

foreach (['ipaddr', 'if'] as $fieldname) {
if (!empty((string)$parent->$fieldname)) {
return (string)$parent->$fieldname;
}
}
return (string)$this->internalValue;

return null;
}

/**
Expand Down