Skip to content

Commit

Permalink
[REF] Move handling of form elements back to the Form
Browse files Browse the repository at this point in the history
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
  • Loading branch information
eileenmcnaughton committed Jul 28, 2020
1 parent 6010fe3 commit f84bb3c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
4 changes: 2 additions & 2 deletions CRM/Contact/Form/Merge.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
7 changes: 1 addition & 6 deletions CRM/Dedupe/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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']);
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f84bb3c

Please sign in to comment.