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

Specify which relationships to generate tokens for #5

Merged
merged 8 commits into from
Mar 27, 2019

Conversation

MegaphoneJon
Copy link
Contributor

This PR allows a user to configure which relationship types should get tokens generated via the UI. I updated the README to document this and to remove this option from the "Room for Improvement" section.

Note that:

So this looks like a big PR, but the only code changes are:

  • CRM_Reltoken_Upgrader::addCustomData() (creates the custom field)
  • CRM_Reltoken_Upgrader::install() and CRM_Reltoken_Upgrader::enable() (which call addCustomData();
  • 6 lines in _reltoken_get_hashed_relationship_types() to filter by the new custom field.

@MegaphoneJon
Copy link
Contributor Author

My last PR passes a $context value to getTokenDetails(). That's a very expensive call, especially if you have other extensions providing custom tokens. By passing the context, I can skip processing tokens in other extensions that I know aren't necessary here. It gives me a 10x speedup when using the Salutations extension!

@@ -101,7 +101,7 @@ function reltoken_civicrm_tokenValues(&$values, $contactIDs, $job = null, $token
$baseToken = preg_replace('/^(.+)___.+$/', '$1', $token);
// dsm($baseToken, '$baseToken');
// dsm($relatedContactIDs, "\$relatedContactIDs for $token");
$tokenDetails = CRM_Utils_Token::getTokenDetails($relatedContactIDs, array($baseToken => 1), FALSE, FALSE, NULL, array('contact' => array($baseToken)));
$tokenDetails = CRM_Utils_Token::getTokenDetails($relatedContactIDs, array($baseToken => 1), FALSE, FALSE, NULL, array('contact' => array($baseToken)), 'CRM_Reltoken');
Copy link
Owner

Choose a reason for hiding this comment

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

@MegaphoneJon Thanks for this. I gather that 'CRM_Reltoken' is an arbitrary string here, since we don't really have a classname. Is that right?

@MegaphoneJon
Copy link
Contributor Author

That's correct, it's an arbitrary string.

'name' => 'display_reltokens',
'label' => E::ts('Generate tokens for this relationship'),
'data_type' => 'Boolean',
'default_value' => 0,
Copy link
Owner

Choose a reason for hiding this comment

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

@MegaphoneJon I'm thinking '1' here would be better for backwards compatibility. So we'd start with supporting all of them, and admins would need to disable specific ones. Thoughts?

@MegaphoneJon
Copy link
Contributor Author

Oh, good thinking. If this is the only change you have, I'll push that on this branch. Otherwise I'll wait until you've reviewed everything.

Copy link
Contributor Author

@MegaphoneJon MegaphoneJon left a comment

Choose a reason for hiding this comment

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

One other improvement I can see is that I create the custom group/fields but don't remove them on uninstall. The "allow custom fields on RelationshipType" should NOT uninstall itself because this extension doesn't "own" that setting; in fact, there's at least two other extensions (one public) that use that setting.

@twomice
Copy link
Owner

twomice commented Mar 21, 2019

@MegaphoneJon sure, this is great otherwise. Default to 1 on that custom field, and we can merge.

@MegaphoneJon
Copy link
Contributor Author

@twomice updated!

@twomice twomice merged commit cf94d98 into twomice:master Mar 27, 2019
@twomice
Copy link
Owner

twomice commented Mar 27, 2019

Thanks - merged!

@MegaphoneJon MegaphoneJon deleted the select-relationships branch April 3, 2019 20:10
@destrieux destrieux mentioned this pull request Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants