-
-
Notifications
You must be signed in to change notification settings - Fork 826
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
ContactSummary - Replace Membership tab with Searchkit display #28810
Conversation
🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷 Introduction for new contributors...
Quick links for reviewers...
|
This is very good @jitendrapurohit thanks for working on it. Some notes:
|
9e76629
to
738f27f
Compare
738f27f
to
eb72987
Compare
$action = $params['where'][0][2]; | ||
$actionLinkIndex = self::getActionIndex($links, $action); | ||
$links = [$links[$actionLinkIndex]]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@colemanw Since the requirement here is to add new links to the action menu & not the toolbar, the searchkit expects this to return only 1 value and replaces the path link to 0th key here. To accommodate this, I had to perform this check and return the value accordingly. Is there a more optimal approach to address this requirement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jitendrapurohit I think a more optimal approach than this would be to break this into 2 callbacks instead of 1.
Like this:
civicrm-core/Civi/Api4/Service/Links/ContactLinksProvider.php
Lines 26 to 31 in 9316120
public static function getSubscribedEvents(): array { | |
return [ | |
'civi.api4.getLinks' => 'alterContactLinks', | |
'civi.api.respond' => 'alterContactLinksResult', | |
]; | |
} |
The idea is to split the logic between the two callbacks based on the way they each work:
civi.api4.getLinks
event gets called first. It's not context-aware, and the results are cached. So in this callback you should unconditionally add all links. This happens before the WHERE clause is applied.civi.api.respond
event, happens after the WHERE clause is applied, and it is context-aware, so this is where you do the fine-tuning and remove links that are not applicable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, pretty sure i started with this approach but was seeing weird number of links in the action menu. Will try this out again & let you know how it goes. Thanks.
@colemanw Seems .mgd condition works site-wide and not per contact basis? The membership type searchkit needs to be displayed based on $cid it is loading for. Does it make sense to add a new setting on the table config eg |
@jitendrapurohit I think the simplest solution for now would be to implement For that matter, we can also use that hook to conditionally unset the Membership component tabs if CiviMember is disabled (once we move the tab to core it will live in the |
b235cde
to
9a9688d
Compare
@colemanw Have now added 2 afforms
Due to these names, the existing tab of Membership is replaced with the afform tab for both contact types. I feel this is now ready to review. |
"allow_verification_by_email": false, | ||
"email_confirmation_template_id": null, | ||
"navigation": null, | ||
"modified_date": "2024-01-09 13:48:38" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jitendrapurohit our new convention is to use .aff.php
files instead of .aff.json
(the php format allows the use of E::ts()
for the title). And "modified date" shouldn't be included.
If you don't want to convert these files by hand, you can use the command civix export Afform afformTabMember
(that command will generate the aff.html
and .aff.php
files plus all the .mgd.php
for embedded search displays in the form).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, thanks for the above. Have updated 👍
7c72c60
to
8387a9a
Compare
Ok @jitendrapurohit this looks really good. My one question is that your |
private static function unsetLinks(array &$links, array $actions) { | ||
foreach ($actions as $action) { | ||
$actionLinkIndex = self::getActionIndex($links, $action); | ||
unset($links[$actionLinkIndex]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably need to wrap this unset
in a conditional like if (isset($actionLinkIndex))
since getActionIndex()
could return null
(this could happen because of filtering by the WHERE clause excluding the links so they don't need to be unset.).
'search_displays' => [ | ||
'Contact_Summary_Memberships.Contact_Summary_Memberships_Active', | ||
'Contact_Summary_Memberships.Contact_Summary_Memberships_Inactive', | ||
'Contact_Summary_Membership_Type.Contact_Summary_Membership_Type', | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a calculated field, not stored. Should be removed from this file.
'icon' => 'fa-external-link', | ||
'text' => E::ts('Edit'), | ||
'style' => 'default', | ||
'path' => 'civicrm/admin/member/membershipType/add?action=update&id=[id]&reset=1', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this use entity+action instead of path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have now added links for MembershipType entity in xml & updated the same here. Thanks.
'condition' => [], | ||
], | ||
[ | ||
'path' => 'civicrm/contact/view/membership?action=renew&reset=1&cid=[contact_id]&id=[id]&context=membership&selectedChild=member', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'path' => 'civicrm/contact/view/membership?action=renew&reset=1&cid=[contact_id]&id=[id]&context=membership&selectedChild=member', | |
'path' => '', |
Path should be omitted when using entity+action as it will be fetched from getLinks
api.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, looks like when MembershipLinksProvider was added with entity+action, the path remained in the mgd file even after the file was refreshed from api4 export? Thanks for spotting. Updated.
'dataType' => 'Integer', | ||
'label' => E::ts('Related'), | ||
'sortable' => TRUE, | ||
'rewrite' => "{crmAPI var='owner_count' entity='Membership' action='getcount' owner_membership_id=[id]}\n{if \$owner_count}\n {\$owner_count} {ts}created{/ts}\n{else}\n {ts}N/A{/ts}\n{/if}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be done with a join + group_by id?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems we dont yet have a self join on SK?
ea28740
to
773c31e
Compare
773c31e
to
dd2c594
Compare
This looks great @jitendrapurohit. |
Overview
ContactSummary - Replace Membership tab with Searchkit display
Before
Outdated code to render membership tab.
After
Uses searchkit display -
Comments
Tagging wip, since there are still few differences (issues?) from previous display.
Change Billing Details
action link should only be visible if related payment processor supports updateSubscriptionBillingInfoCancel Auto-renewal
link should only be displayed if processor supports cancelRecurringPerhaps, we can add a setting eg
Hide SK display if no results
?