From 1a4127a0d6a07f905a3d18e995bd7e7e028f97b8 Mon Sep 17 00:00:00 2001 From: kenwest Date: Mon, 23 May 2016 22:43:03 +1000 Subject: [PATCH] CRM-18656 Advanced search fails to show tagset criteria when editing saved search --- CRM/Contact/Form/Search/Advanced.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/CRM/Contact/Form/Search/Advanced.php b/CRM/Contact/Form/Search/Advanced.php index 8aa70546f3..5403415868 100644 --- a/CRM/Contact/Form/Search/Advanced.php +++ b/CRM/Contact/Form/Search/Advanced.php @@ -385,6 +385,34 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search { if ($this->_ssID && empty($_POST)) { $defaults = array_merge($defaults, CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID)); } + + /* + * CRM-18656 - reverse the normalisation of 'contact_taglist' done in + * self::normalizeFormValues(). Remove tagset tags from the default + * 'contact_tags' and put them in 'contact_taglist[N]' where N is the + * id of the tagset. + */ + if (isset($defaults['contact_tags'])) { + $tag = new CRM_Core_BAO_Tag(); + foreach ($defaults['contact_tags'] as $key => $tagId) { + $params = array('id' => $tagId); + $result = array(); + $tag->retrieve($params, $result); + $parentId = $result['parent_id']; + $element = "contact_taglist[$parentId]"; + if ($this->elementExists($element)) { // It's a tagset + unset($defaults['contact_tags'][$key]); + if (!isset($defaults[$element])) { + $defaults[$element] = array(); + } + $defaults[$element][] = $tagId; + } + } + if (empty($defaults['contact_tags'])) { + unset($defaults['contact_tags']); + } + } + return $defaults; } -- 2.25.1