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

Make hook_civicrm_pre() and hook_civicrm_post() fire on CaseContacts #14030

Merged
merged 1 commit into from
Apr 14, 2019

Conversation

aydun
Copy link
Contributor

@aydun aydun commented Apr 11, 2019

Overview

Make hook_civicrm_pre() and hook_civicrm_post() fire on CaseContacts

Before

Modifications to CaseContacts do not trigger hook_civicrm_pre() or hook_civicrm_post()

After

Modifications to CaseContacts do trigger hook_civicrm_pre() or hook_civicrm_post()

Technical Details

Based on CRM_Core_BAO_Dashboard::create() as advised on https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_post/

Documentation PR will follow once code merged.

@civibot
Copy link

civibot bot commented Apr 11, 2019

(Standard links)

@civibot civibot bot added the master label Apr 11, 2019
@demeritcowboy
Copy link
Contributor

demeritcowboy commented Apr 12, 2019

  • General standards
    • [r-explain] PASS
    • [r-user] PASS
    • [r-doc] COMMENTS Since CaseContact isn't a first-class object and only exists because of the way the many-to-many relationship is modelled and exposed in civi, "create" and "edit" have a slightly different meaning here. They are more like "link" and "re-link". In other words, what you're hooking on is the event when a case object gets linked to a client contact object or vice-versa. No actual first-class object is being created/edited.
    • [r-run] PASS I tested this by making a little extension that logs the pre and post hook input and then created a case. It all looks right. I also tested via api explorer since I wasn't even sure how to test the "edit" otherwise. For example reassign case doesn't seem to use the object/hook, and even if it did that action actually creates a new case and a new linkage.
  • Developer standards
    • [r-tech] PASS
    • [r-code] PASS
    • [r-maint] COMMENTS I'm not sure how you'd write a test for hooks.
    • [r-test] PASS

@MegaphoneJon
Copy link
Contributor

@aydun @demeritcowboy I had to learn how to test hooks recently :) An example is in tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php, testing that hook_civicrm_tokenValues works correctly on PDF letters.

You write a function using the hook, but you can name it whatever you want. Then you call $this->hookClass->setHook, specifying the function name.

@demeritcowboy
Copy link
Contributor

@MegaphoneJon Ah cool. Do you want to post that as answer to this SE question? https://civicrm.stackexchange.com/questions/25795/how-to-write-php-unit-test-for-an-entity-using-hooks

@mattwire
Copy link
Contributor

Tested by @demeritcowboy This is a standard hook with standard parameters added in a "standard" way so we can skip a unit test.

@mattwire mattwire merged commit 6f744f5 into civicrm:master Apr 14, 2019
@mattwire
Copy link
Contributor

@aydun Please follow up with docs PR and I'll merge

aydun added a commit to aydun/civicrm-dev-docs that referenced this pull request Apr 15, 2019
…tation - see civicrm/civicrm-core#14030

Reposition 'Campaign' in list to be alphabetical
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.

4 participants