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

Support hooks for MembershipType entity #11908

Merged

Conversation

mattwire
Copy link
Contributor

@mattwire mattwire commented Mar 31, 2018

Overview

Basic changes required to support pre/post hooks on MembershipType entity (see #11794).

Before

  • pre/post hooks not triggered on edit/create.

After

  • pre/post hooks triggered on edit/create.

@@ -128,6 +139,20 @@ public static function add(&$params, $ids = array()) {
if ($id) {
self::updateAllPriceFieldValue($id, $params);
}

if (!empty($params['custom']) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

@mattwire this should already be supported in the api layer in 5.0 see
civicrm/civicrm-dev-docs@b0bf2ba

We don't need to add via bao layer

if (empty($params['id'])) {
$params['id'] = CRM_Utils_Array::value('membershipType', $ids);
}
$id = CRM_Utils_Array::value('id', $params);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the tidiest way of expressing this part is the Phone BAO

$hook = empty($params['id']) ? 'create' : 'edit';
CRM_Utils_Hook::pre($hook, 'Phone', CRM_Utils_Array::value('id', $params), $params);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, updated to match that format

*/
public static function add(&$params, $ids = array()) {
$id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('membershipType', $ids));
if (empty($params['id'])) {
$params['id'] = CRM_Utils_Array::value('membershipType', $ids);
Copy link
Contributor

Choose a reason for hiding this comment

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

should we add a deprecation notice here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, added.

@@ -223,6 +223,7 @@ public static function customGroupExtends() {
'ContributionRecur' => ts('Recurring Contributions'),
'Group' => ts('Groups'),
'Membership' => ts('Memberships'),
'MembershipType' => ts('Membership Types'),
Copy link
Contributor

Choose a reason for hiding this comment

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

not needed

Copy link
Contributor Author

@mattwire mattwire May 6, 2018

Choose a reason for hiding this comment

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

@eileenmcnaughton The problem here is that you need to set 3 parameters (label, value, name) in cg_extend_objects but you cannot do this via the UI as name is not exposed. So you are either limited to doing the DB change via an extension or editing the DB directly. It may also be possible to do it via the API but it seems a lot less straightforward than just adding it here which allows the user to directly select "Membership Types" as a custom data entity when creating custom fields.
And we now have support in core for displaying those custom fields via this PR

Copy link
Contributor

Choose a reason for hiding this comment

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

@mattwire right - I think the intent IS that additional entities would be supported by adding values to that option group in an extension.

@@ -1813,6 +1813,9 @@ public static function mapTableName($table) {
case 'Membership':
return 'civicrm_membership';

case 'MembershipType':
Copy link
Contributor

Choose a reason for hiding this comment

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

not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eileenmcnaughton See comment above

@eileenmcnaughton
Copy link
Contributor

@mattwire the api already supports the custom data & we should switch to calling the api rather than doubling up on the BAO. The hook part we should add in the BAO create, as you have done. I'm in 2 minds about the ->find() addition because it imposes a performance cost on every save - regardless of whether hooks are in play. OTOH the hook itself can fetch extra data if required. (our code is inconsistent on this & as a low-traffic entity the performance is less of an issue but I think the precedent of leaving extra DB calls to the hook fn is better)

@mattwire mattwire force-pushed the membershiptype_customdata_support branch 2 times, most recently from d3936f7 to acfc2f2 Compare May 6, 2018 13:30
@mattwire
Copy link
Contributor Author

mattwire commented May 6, 2018

@eileenmcnaughton I've removed the ->find() per your comments. It's not required so I'll not add it here.
I've also removed the reference to custom data in the BAO object as the API does indeed work now :-) Nice work with that!

@eileenmcnaughton eileenmcnaughton changed the title Support custom data and hooks for MembershipType entity Support hooks for MembershipType entity May 8, 2018
@eileenmcnaughton
Copy link
Contributor

@mattwire I would merge this PR if it were just the BAO changes - I'm not sold on those 2 custom data changes as part of this

@mattwire mattwire force-pushed the membershiptype_customdata_support branch from acfc2f2 to 56eaab9 Compare May 12, 2018 07:38
@mattwire mattwire force-pushed the membershiptype_customdata_support branch from 56eaab9 to 000e4e8 Compare May 12, 2018 07:40
@mattwire
Copy link
Contributor Author

@eileenmcnaughton The PR is now just the BAO changes to support hooks for MembershipType. Assuming it passes tests would you mind having another look?

@eileenmcnaughton
Copy link
Contributor

unrelated fails

@eileenmcnaughton
Copy link
Contributor

Agree this just adds hooks & a little cleanup - merging

@eileenmcnaughton eileenmcnaughton merged commit 6e74fca into civicrm:master May 13, 2018
@mattwire mattwire deleted the membershiptype_customdata_support branch September 25, 2018 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants