$mappingHeader = $processor->getFieldName($i);
$websiteTypeId = $processor->getWebsiteTypeID($i);
$locationId = $processor->getLocationTypeID($i);
- $phoneType = $processor->getPhoneTypeID($i);
- $imProvider = $processor->getIMProviderID($i);
$typeId = $processor->getPhoneOrIMTypeID($i);
if ($websiteTypeId) {
$defaults["mapper[$i]"] = [$mappingHeader, $websiteTypeId];
}
else {
- if (!$locationId) {
- $js .= "{$formName}['mapper[$i][1]'].style.display = 'none';\n";
- }
//default for IM/phone without related contact
$defaults["mapper[$i]"] = [$mappingHeader ?? '', $locationId, $typeId];
}
- if ((!$phoneType) && (!$imProvider)) {
- $js .= "{$formName}['mapper[$i][2]'].style.display = 'none';\n";
- }
-
- $js .= "{$formName}['mapper[$i][3]'].style.display = 'none';\n";
+ $js .= $processor->getQuickFormJSForField($i);
$jsSet = TRUE;
}
return !empty($this->getValidRelationships()[$key]) ? TRUE : FALSE;
}
+ /**
+ * Get the relevant js for quickform.
+ *
+ * @param int $column
+ *
+ * @return string
+ * @throws \CiviCRM_API3_Exception
+ */
+ public function getQuickFormJSForField($column) {
+ $columnNumbersToHide = [];
+
+ if (!$this->getLocationTypeID($column) && !$this->getWebsiteTypeID($column)) {
+ $columnNumbersToHide[] = 1;
+ }
+ if (!$this->getPhoneOrIMTypeID($column)) {
+ $columnNumbersToHide[] = 2;
+ }
+ $columnNumbersToHide[] = 3;
+
+ $jsClauses = [];
+ foreach ($columnNumbersToHide as $columnNumber) {
+ $jsClauses[] = $this->getFormName() . "['mapper[$column][" . $columnNumber . "]'].style.display = 'none';";
+ }
+ return implode("\n", $jsClauses) . "\n";
+ }
+
}