Contact Dashboard: relationships: wrong links appear if "Pledges" not displayed
Description:
Very surprising behavior on the Contact Dashboard (q=civicrm/user):
If Display Preferences > Contact Dashboard does not include "Pledges", then the links for each relationship under "Your Contacts / Organizations" will not be the expected links "Edit Contact Information", "Dashboard", and "Disable"; instead those links will be to back-office features "View", "Edit", etc.
Analysis:
- These links are defined in
CRM_Contact_BAO_Relationship::getContactRelationshipSelector()
around line 2035, based on the value of$params['context']
, which ultimately is taken from $_REQUEST - On the Contact Dashboard, the relationships content is built via an xhr call to
/civicrm/ajax/contactrelationships?context=...
which will provide thatcontext
value; this value is set in Smarty template templates/CRM/Contact/Page/View/RelationshipSelector.tpl using whatever value is assigned to smarty variable$context
. - This $context variable is assigned to the template as 'user' in CRM_Core_Form_Search::loadStandardSearchOptionsFromUrl() based on the value in the controller store, which is set to 'user' in CRM_Pledge_Page_UserDashboard::listPledges().
If the Pledges section is not included on the Contact Dashboard, then the value of Smarty variable $context
is never set; therefore it's empty when passed via xhr to CRM_Contact_BAO_Relationship::getContactRelationshipSelector()
; therefore that method will use the back-office links for each relationship row, instead of the user-context links that are expected on the Contact Dashboard.
Possible fix:
A patch equivalent to this one is solving this problem in local dev, simply by specifying conteext="user"
in the Contact Dashboard when building the relationships section:
diff --git a/CRM/Contact/Page/View/UserDashBoard.php b/CRM/Contact/Page/View/UserDashBoard.php
index 8cba50b..868f0d1 100644
--- a/CRM/Contact/Page/View/UserDashBoard.php
+++ b/CRM/Contact/Page/View/UserDashBoard.php
@@ -132,6 +132,7 @@ class CRM_Contact_Page_View_UserDashBoard extends CRM_Core_Page {
$contactRelationships = $selector = NULL;
CRM_Utils_Hook::searchColumns('relationship.columns', $columnHeaders, $contactRelationships, $selector);
$this->assign('columnHeaders', $columnHeaders);
+ $this->assign('context', 'user');
$dashboardElements[] = [
'class' => 'crm-dashboard-permissionedOrgs',
'templatePath' => 'CRM/Contact/Page/View/RelationshipSelector.tpl',
However:
- Before submitting a PR, I'd be curious to hear feedback on what that might break -- i.e., thoughts on where additional test coverage might be warranted.
- I'm also wondering if there's a better place to set
context
. Seems like it would be safe (and more broadly effective) to defineconteext="user"
throughout the scope of the Contact Dashboard, rather than only when Relationships section is included.