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

Issue #3444179: Fix the error in the SQL syntax if not all options in the...

Issue #3444179: Fix the error in the SQL syntax if not all options in the formatter settings are selected
parent 922742c3
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*
* @FieldFormatter(
* id = "ipaddress_cidr",
* label = @Translation("IP Address PostgreSQL cidr"),
* label = @Translation("Default"),
* field_types = {
* "ipaddress_cidr",
* }
......@@ -192,39 +192,30 @@ final class IpAddressCidrFormatter extends FormatterBase implements ContainerFac
// As a user has selected functions in the formatter settings, then we
// create a query to the database and get the values of these functions.
// We get all the values at once, and then delete those that were not
// selected in the settings of the formatter.
$select = 'SELECT ';
if ($this->getSetting('abbrev')) {
$select .= 'abbrev(cidr :ipAddressString) as "abbrev", ';
}
if ($this->getSetting('broadcast')) {
$select .= 'broadcast(cidr :ipAddressString) as "broadcast", ';
}
if ($this->getSetting('family')) {
$select .= 'family(cidr :ipAddressString) as "family", ';
}
if ($this->getSetting('host')) {
$select .= 'host(cidr :ipAddressString) as "host", ';
}
if ($this->getSetting('hostmask')) {
$select .= 'hostmask(cidr :ipAddressString) as "hostmask", ';
}
if ($this->getSetting('masklen')) {
$select .= 'masklen(cidr :ipAddressString) as "masklen", ';
}
if ($this->getSetting('netmask')) {
$select .= 'netmask(cidr :ipAddressString) as "netmask", ';
}
if ($this->getSetting('network')) {
$select .= 'network(cidr :ipAddressString) as "network"';
}
$select .= 'abbrev(cidr :ipAddressString) as "abbrev", ';
$select .= 'broadcast(cidr :ipAddressString) as "broadcast", ';
$select .= 'family(cidr :ipAddressString) as "family", ';
$select .= 'host(cidr :ipAddressString) as "host", ';
$select .= 'hostmask(cidr :ipAddressString) as "hostmask", ';
$select .= 'masklen(cidr :ipAddressString) as "masklen", ';
$select .= 'netmask(cidr :ipAddressString) as "netmask", ';
$select .= 'network(cidr :ipAddressString) as "network"';
$query = $this->connection->query($select, [
':ipAddressString' => $ipAddressString,
]);
$result = $query->fetchAssoc();
// Delete the values that was not selected in the formatter settings.
foreach ($this->getSettings() as $name => $checked) {
if (!$checked) {
unset($result[$name]);
}
}
return [
'#theme' => 'field__ipaddress_pgsql',
'#ip_address' => $ipAddressString,
......
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