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 1 commit
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
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;
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('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.
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,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}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this not change the logic?

($action eq 1 and $mode eq 4 ): ADD and MODE_CREATE
$action eq 2: UPDATE
$action eq 8192: PROFILE

I can't grok why we need to test for these; $isDuplicate should be enough, I'd think.

And array_key_exists('_qf_Edit_upload_duplicate', $form) should always be TRUE.

So can we just change this to {if $isDuplicate}?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@highfalutin the reason for the button check is that the button is ONLY there under a very narrow situation - if you use an entity reference field & choose (e.g) new Organization AND choose an organization that exists THEN the button appears

<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 Down