CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Mailing Job Id in alterMailParams Hook
Pages: [1]

Author Topic: Mailing Job Id in alterMailParams Hook  (Read 466 times)

Erawat

  • I’m new here
  • *
  • Posts: 19
  • Karma: 1
  • CiviCRM version: 4.1
  • CMS version: Drupal 7
  • MySQL version: 5.x
  • PHP version: 5.3
Mailing Job Id in alterMailParams Hook
January 06, 2014, 02:51:19 am
Hi All,

I am working on the extension that needs to alter mail parameter so I use hook_civicrm_alterMailParams. However, the extension requires the mailing job_id. I drilled down into the MailingBAO and Hook classes the solution would be.

1. Modified alterMailParams hook for passing job_id as below:

Code: [Select]
**
 * Implementation of hook_civicrm_alterMailParams( )
 */
function mailjet_civicrm_alterMailParams(&$params, $context, $jobId) {
  if(isset($jobId)){
   //do something
  }
}

2. The second one is to add  job_id as parameter before passing to the hook in Mailing BAO and unset after the hook was called

Code: [Select]
    //@erawat added $job_id
    $mailParams['job_id'] = $job_id;
    CRM_Utils_Hook::alterMailParams($mailParams, 'civimail');
    unset($mailParams['job_id']);

Which one is more practical to implement as I'd like to contribute it back to the core.

Thanks,

Erawat

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: Mailing Job Id in alterMailParams Hook
January 06, 2014, 11:52:36 am
I think the second one ($mailParams['job_id']) is more consistent with the style of that hook.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Mailing Job Id in alterMailParams Hook
January 06, 2014, 12:37:10 pm
The requirement on this hook I hit yesterday was to have the hook set a param like $mailParams['skip'] & have the mail not go out. In this case it's because our customers have taken fright at the fact that CiviCRM ignores 'do_not_email' for reminders which means they have to use them with extreme caution.

This doesn't seem like the only use case - I guess the issue would be what does happen - does an activity still get created?
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Mailing Job Id in alterMailParams Hook

This forum was archived on 2017-11-26.