简体   繁体   中英

how to modify function of contributed module in drupal?

I have the reqirement to modify simplenews_build_newsletter_mail() function in simplenews module but, we don't modify directly contributed module function.

can someone gives me ways to modify simplenews_build_newsletter_mail() function ?

Most of the data moving around in drupal can be altered through 'hooks'

the function you want to alter simplenews_build_newsletter_mail(&$message, SimplenewsSourceInterface $source) is being called from simplenews_mail($key, &$message, $params) which is simplenews implementation for hook_mail

fortunately all the output for hook_mail can be altered though hook_mail_alter() .

What you need to do is to create your own module, then implement hook_mail_alter() in your new custom module. find your target emails, change them.

you will need to identify which mail you would like to alter using the mail $id, The id will be {$module}_{$key} where the module is the drupal module generated this email (simplenews) in your case.

find more information here https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_mail_alter/7

    /**
     * Implements hook_mail_alter().
     */
    function mymodule_mail_alter(&$message) {
      switch ($message['id']) {
        case 'simplenews_node':
        case 'simplenews_test':
          // Do your magic.
          break;
      }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM