Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm thinking about copying the crm_core_contact_send_email_action action in crm_core_contact.module so that I can elaborate it a bit by saving the sent e-mail as an activity, on the recipient contact.
I see the contact entity is loaded in crm_core_contact_send_email_action():
$contact_wrapper = entity_metadata_wrapper('crm_core_contact', $contact);
Could someone tell me how to create an activity here and have it reference to this contact as a participant, and save the e-mail body?
Comments
Comment #1
JurriaanRoelofs CreditAttribution: JurriaanRoelofs commentedComment #3
RoSk0To easily archive your goal this action missed context, e.g. contact, in params to drupal_mail() call. I've fixed this. Now using hook_mail_alter you can create an activity, set its participant to contact from params and store message subject/body in fields of activity.
Comment #4
JurriaanRoelofs CreditAttribution: JurriaanRoelofs commentedI'm not really sure what you mean, it seems that all i need to do is programmatically create an entity inside the crm_core_contact_send_email_action($contact, $context) function, no?
I'm just not sure where to find the controller function to create an activity of some bundle/type.
edit: I see you patched the function so I can hook into it and get $contact, thanks. I was actually going to copy the whole action anyways because I plan to do more elaboration, like make the body a wysiwyg field, categorize different emails and report them as different actions etc. Was just looking for some code where activities are created programmatically so that I can use that as example.
Comment #5
RoSk0All you need to do is take this code, put it in your custom module and modify as needed.
Comment #6
JurriaanRoelofs CreditAttribution: JurriaanRoelofs commentedThanks for your excellent support!
Code worked fine, just needed some extra lines to set date and title: