From 714eca2b18ebc6846ef4bacb86d561d6eada8b88 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Sun, 10 Apr 2022 14:35:05 +0200 Subject: [PATCH] Services / Unbound + core MVC - extend ModelRelationField to show combined descriptions using vsprintf() and implement hostname.domain in new unbound alias popup. closes https://github.com/opnsense/core/issues/5694 --- .../Base/FieldTypes/ModelRelationField.php | 18 ++++++++++++++---- .../app/models/OPNsense/Unbound/Unbound.xml | 3 ++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ModelRelationField.php b/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ModelRelationField.php index 185270cdb..ae011a56a 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ModelRelationField.php +++ b/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ModelRelationField.php @@ -95,13 +95,22 @@ class ModelRelationField extends BaseListField } $groupKey = isset($modelData['group']) ? $modelData['group'] : null; - $displayKey = $modelData['display']; + $displayKeys = explode(',', $modelData['display']); + $displayFormat = !empty($modelData['display_format']) ? $modelData['display_format'] : "%s"; $groups = array(); $searchItems = $modelObj->getNodeByReference($modelData['items']); if (!empty($searchItems)) { foreach ($modelObj->getNodeByReference($modelData['items'])->iterateItems() as $node) { - if (!isset($node->getAttributes()['uuid']) || $node->$displayKey == null) { + $descriptions = []; + foreach ($displayKeys as $displayKey) { + if ($node->$displayKey != null) { + $descriptions[] = (string)$node->$displayKey; + } else { + $descriptions[] = ""; + } + } + if (!isset($node->getAttributes()['uuid'])) { continue; } @@ -126,8 +135,9 @@ class ModelRelationField extends BaseListField } $uuid = $node->getAttributes()['uuid']; - self::$internalCacheOptionList[$this->internalCacheKey][$uuid] = - (string)$node->$displayKey; + self::$internalCacheOptionList[$this->internalCacheKey][$uuid] = vsprintf( + $displayFormat, $descriptions + ); } } unset($modelObj); diff --git a/src/opnsense/mvc/app/models/OPNsense/Unbound/Unbound.xml b/src/opnsense/mvc/app/models/OPNsense/Unbound/Unbound.xml index 26f9bd25f..2de8d2e86 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Unbound/Unbound.xml +++ b/src/opnsense/mvc/app/models/OPNsense/Unbound/Unbound.xml @@ -184,7 +184,8 @@ OPNsense.Unbound.Unbound hosts.host - domain + hostname,domain + %s.%s Y