Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#4144 Fix smarty notice on isDuplicate #25657

Merged
merged 3 commits into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this just muddies the waters using a property

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, strange choice

/**
* 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('showSaveDuplicateButton', 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

helpful explanation

*
* 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,14 @@ public function buildQuickForm(): void {
$this->freeze();
}

if ($this->_context == 'dialog') {
// Assign FALSE, here - this is overwritten during form validation
// if duplicates are found during submit.
CRM_Core_Smarty::singleton()->assign('showSaveDuplicateButton', FALSE);

if ($this->isEntityReferenceContactCreateMode()) {
$this->addElement(
'xbutton',
$this->_duplicateButtonName,
$this->getButtonName('upload', 'duplicate'),
ts('Save Matching Contact'),
[
'type' => 'submit',
Expand Down
8 changes: 4 additions & 4 deletions 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 $showSaveDuplicateButton}
<div class="crm-submit-buttons">
{$form._qf_Edit_upload_duplicate.html}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems odd that we hard-code the button name here, and go to the trouble to generate it dynamically in Form.php... but if it works, fine

</div>
Expand All @@ -50,7 +50,7 @@
{if $action eq 2 and $multiRecordFieldListing}
<h1>{ts}Edit Details{/ts}</h1>
<div class="crm-submit-buttons" style='float:right'>
{include file="CRM/common/formButtons.tpl" location=''}{if $isDuplicate}{$form._qf_Edit_upload_duplicate.html}{/if}
{include file="CRM/common/formButtons.tpl" location=''}{if $showSaveDuplicateButton}{$form._qf_Edit_upload_duplicate.html}{/if}
</div>
{/if}

Expand Down Expand Up @@ -94,7 +94,7 @@
<div class="content description">{$field.help_pre}</div>
</div>
{/if}
{if $field.options_per_line}
{if array_key_exists('options_per_line', $field) && $field.options_per_line}
<div class="crm-section editrow_{$n}-section form-item" id="editrow-{$n}">
<div class="label">{$form.$n.label}</div>
<div class="content edit-value">
Expand Down Expand Up @@ -201,7 +201,7 @@
</div>
{/if}
<div class="crm-submit-buttons" style='{$floatStyle}'>
{include file="CRM/common/formButtons.tpl" location=''}{if $isDuplicate}{$form._qf_Edit_upload_duplicate.html}{/if}
{include file="CRM/common/formButtons.tpl" location=''}{if $showSaveDuplicateButton}{$form._qf_Edit_upload_duplicate.html}{/if}
{if $includeCancelButton}
<a class="button cancel" href="{$cancelURL}">
<span>
Expand Down