From c813e8f4b128cb2e03a7f81ceaa7ebb4c01bbc3e Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 28 Jul 2020 14:44:08 +1200 Subject: [PATCH] [REF] Move handling of form elements back to the Form This toxic function getRowsElementsAndInfo does things for the form layer but it's also heavily used in the BAO dedupeProcess. Ideally we want the things that are onnly being done to support (one specific) form to sit on that form. This does that just for one of the 2 arrays it creates of form elements. The rel_table_elements array is just an array that looks like [ ['checkbox', 'move_rel_contributions'], ['checkbox, 'move_rel_activities'], ] The rel_tables array is an array of metadata keyed by eg. move_rel_contributions. Ergo this can be done easily on the form layer with the data it already has --- CRM/Contact/Form/Merge.php | 4 ++-- CRM/Dedupe/Merger.php | 7 +------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/CRM/Contact/Form/Merge.php b/CRM/Contact/Form/Merge.php index 0f68d5a057c2..fb6f6bddf12c 100644 --- a/CRM/Contact/Form/Merge.php +++ b/CRM/Contact/Form/Merge.php @@ -229,8 +229,8 @@ public function preProcess() { } // add related table elements - foreach ($rowsElementsAndInfo['rel_table_elements'] as $relTableElement) { - $element = $this->addElement($relTableElement[0], $relTableElement[1]); + foreach (array_keys($rowsElementsAndInfo['rel_tables']) as $relTableElement) { + $element = $this->addElement('checkbox', $relTableElement); $element->setChecked(TRUE); } diff --git a/CRM/Dedupe/Merger.php b/CRM/Dedupe/Merger.php index 1a918695103c..0bab319abba7 100644 --- a/CRM/Dedupe/Merger.php +++ b/CRM/Dedupe/Merger.php @@ -1097,9 +1097,6 @@ public static function getLocationBlockInfo() { * * elements => An array of form elements for the merge UI * - * rel_table_elements => An array of form elements for the merge UI for - * entities related to the contact (eg: checkbox to move 'mailings') - * * rel_tables => Stores the tables that have related entities for the contact * for example mailings, groups * @@ -1129,7 +1126,7 @@ public static function getRowsElementsAndInfo($mainId, $otherId, $checkPermissio $compareFields = self::retrieveFields($main, $other); - $rows = $elements = $relTableElements = $migrationInfo = []; + $rows = $elements = $migrationInfo = []; foreach ($compareFields['contact'] as $field) { if ($field === 'contact_sub_type') { @@ -1186,7 +1183,6 @@ public static function getRowsElementsAndInfo($mainId, $otherId, $checkPermissio $mergeHandler = new CRM_Dedupe_MergeHandler((int) $mainId, (int) $otherId); $relTables = $mergeHandler->getTablesRelatedToTheMergePair(); foreach ($relTables as $name => $null) { - $relTableElements[] = ['checkbox', "move_$name"]; $migrationInfo["move_$name"] = 1; $relTables[$name]['main_url'] = str_replace('$cid', $mainId, $relTables[$name]['url']); @@ -1274,7 +1270,6 @@ public static function getRowsElementsAndInfo($mainId, $otherId, $checkPermissio $result = [ 'rows' => $rows, 'elements' => $elements, - 'rel_table_elements' => $relTableElements, 'rel_tables' => $relTables, 'main_details' => $main, 'other_details' => $other,