Skip to content

Commit

Permalink
dev/core#4144 Fix smarty notice on isDuplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Feb 23, 2023
1 parent 6d5d6c5 commit 9e9ce4a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
34 changes: 22 additions & 12 deletions CRM/Profile/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ class CRM_Profile_Form extends CRM_Core_Form {
*/
public $_grid;

/**
* Name of button for saving matching contacts.
* @var string
*/
protected $_duplicateButtonName;
/**
* The title of the category we are editing.
*
Expand Down Expand Up @@ -206,7 +201,7 @@ protected static function handleDuplicateChecking(&$errors, $fields, $form) {
$form->_id = $ids[0];
}
else {
if ($form->_context == 'dialog') {
if ($form->isEntityReferenceContactCreateMode()) {
$contactLinks = CRM_Contact_BAO_Contact_Utils::formatContactIDSToLinks($ids, TRUE, TRUE);

$duplicateContactsLinks = '<div class="matching-contacts-found">';
Expand Down Expand Up @@ -249,9 +244,10 @@ protected static function handleDuplicateChecking(&$errors, $fields, $form) {

$errors['_qf_default'] = $duplicateContactsLinks;

// let smarty know that there are duplicates
$template = CRM_Core_Smarty::singleton();
$template->assign('isDuplicate', 1);
// The button 'Save Matching Contact' is added in buildForm
// but we only decide here whether ot not to show it - ie
// if validation failed due to there being duplicates.
CRM_Core_Smarty::singleton()->assign('isDuplicate', 1);
}
else {
$errors['_qf_default'] = ts('A record already exists with the same information.');
Expand All @@ -261,6 +257,18 @@ protected static function handleDuplicateChecking(&$errors, $fields, $form) {
return $errors;
}

/**
* Is this being called from an entity reference field.
*
* E.g clicking on 'New Organization' from the employer field
* would create a link with the context = 'dialog' in the url.
*
* @return bool
*/
public function isEntityReferenceContactCreateMode(): bool {
return $this->_context === 'dialog';
}

/**
* Explicitly declare the entity api name.
*/
Expand Down Expand Up @@ -329,7 +337,6 @@ public function preProcess() {
CRM_Core_Error::statusBounce(ts('Proper action not specified for this custom value record profile'));
}
}
$this->_duplicateButtonName = $this->getButtonName('upload', 'duplicate');

$gids = explode(',', (CRM_Utils_Request::retrieve('gid', 'String', CRM_Core_DAO::$_nullObject, FALSE, 0) ?? ''));

Expand Down Expand Up @@ -897,10 +904,13 @@ public function buildQuickForm(): void {
$this->freeze();
}

if ($this->_context == 'dialog') {
if ($this->isEntityReferenceContactCreateMode()) {
// Assign FALSE, here - this is overwritten during form validation
// if duplicates are found during submit.
CRM_Core_Smarty::singleton()->assign('isDuplicate', FALSE);
$this->addElement(
'xbutton',
$this->_duplicateButtonName,
$this->getButtonName('upload', 'duplicate'),
ts('Save Matching Contact'),
[
'type' => 'submit',
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Profile/Form/Dynamic.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<div id="crm-container" class="crm-container crm-public" lang="{$config->lcMessages|truncate:2:"":true}" xml:lang="{$config->lcMessages|truncate:2:"":true}">
{/if}

{if $isDuplicate and ( ($action eq 1 and $mode eq 4 ) or ($action eq 2) or ($action eq 8192) ) }
{if array_key_exists('_qf_Edit_upload_duplicate', $form) && $isDuplicate}
<div class="crm-submit-buttons">
{$form._qf_Edit_upload_duplicate.html}
</div>
Expand Down

0 comments on commit 9e9ce4a

Please sign in to comment.