Answers.Body: <p>civix is a cli tool that will help you a lot to write that extension. you will have to:</p>
  
  <ul>
  <li>write a hook to get that extra token</li>
  <li>add a page to let the user add the custom message (civix generate:page once you have generated the extension)</li>
  </ul>
  
  <p>Instead of a token, it might be easier to generate the html and merge your html table, the custom message and a template and send it as a mail (or generate the pdf)</p>
  
  <p>As for the custom link, it depends on which screen and how you want to add it, we might have already a hook to add an extra action, or you can use a hook when the form/page is generated to add the needed buttons/links.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-08T17:15:48.097Z
Answers.Text: I have used civix a couple of times for extensions. I want the link on each participant row of a contact's Events tab and in participant search results. I think hook_civicrm_links() may be what I need. If I add this link to launch activity/email/add, I would like to provide a context of the participant ID that was clicked (and send that ID another step forward into my custom token hook when the user clicks Send, to generate my token value). Is there a technique to achieve this?
Answers.UserDisplayName: Nicholai
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-09T09:43:53.500Z
Answers.Text: you can simply add the participant id as a get param and read it in the next page. Is this what you mean?
Answers.UserDisplayName: Xavier
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-09T13:34:31.417Z
Answers.Text: I can add participant ID to the query string when going to activity/email/add, but I'm missing the step of how get the ID one step further (i.e. it needs to post when the user clicks send in order for the TokenValue hook to make use of it and create the correct query). Do I need a second hook somewhere to create a custom hidden input on the email creation page, or to put my participant ID into a PHP session variable?
Answers.UserDisplayName: Nicholai
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-08T10:19:58.570Z
Answers.LastActivityDate: 2015-05-08T10:19:58.570Z
Answers.UserDisplayName: Xavier
Body: <p>My goal is to display a link or button for a given participant record on the Events tab of a contact record (or possibly within the More link in participant search results). On click, it will open a screen with an editable message template pre-loaded that can be emailed or printed to PDF. The template would contain a token to be filled based on a parameter that is the value of a custom participant field. The token's data is based on a SQL query, from whose results I'll create an HTML table to display a participant invoice.</p>
  
  <p>I'm guessing I'll need to write a custom token, but there are several other components at play required to make this happen. SQL is my thing, so that part is done. But I'm middling in PHP, and fairly novice in Civi extensions. What is the "right" way for me to attack this problem? Are there any complete examples of the parts involved in this, i.e. creating a contextual link, loading a screen with a message template, having a participant context for my custom token in order to get proper query results, anything else I'm forgetting?</p>
  
Tags: <api>
Title: How to create a custom action within context of the current record
ThreadText: # How to create a custom action within context of the current record
  
  (Asked by: username_0 on 2015-05-08)
  
  My goal is to display a link or button for a given participant record on the Events tab of a contact record (or possibly within the More link in participant search results). On click, it will open a screen with an editable message template pre-loaded that can be emailed or printed to PDF. The template would contain a token to be filled based on a parameter that is the value of a custom participant field. The token's data is based on a SQL query, from whose results I'll create an HTML table to display a participant invoice.
  
  I'm guessing I'll need to write a custom token, but there are several other components at play required to make this happen. SQL is my thing, so that part is done. But I'm middling in PHP, and fairly novice in Civi extensions. What is the "right" way for me to attack this problem? Are there any complete examples of the parts involved in this, i.e. creating a contextual link, loading a screen with a message template, having a participant context for my custom token in order to get proper query results, anything else I'm forgetting?
  
  **Tags:** api
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-05-08. Score: 1
  
  civix is a cli tool that will help you a lot to write that extension. you will have to:
  
  * write a hook to get that extra token
  * add a page to let the user add the custom message (civix generate:page once you have generated the extension)
  
  Instead of a token, it might be easier to generate the html and merge your html table, the custom message and a template and send it as a mail (or generate the pdf)
  
  As for the custom link, it depends on which screen and how you want to add it, we might have already a hook to add an extra action, or you can use a hook when the form/page is generated to add the needed buttons/links.
  
  > **Comments:**
  > **username_0**: I have used civix a couple of times for extensions. I want the link on each participant row of a contact's Events tab and in participant search results. I think hook_civicrm_links() may be what I need. If I add this link to launch activity/email/add, I would like to provide a context of the participant ID that was clicked (and send that ID another step forward into my custom token hook when the user clicks Send, to generate my token value). Is there a technique to achieve this?  
  > **username_1**: you can simply add the participant id as a get param and read it in the next page. Is this what you mean?  
  > **username_0**: I can add participant ID to the query string when going to activity/email/add, but I'm missing the step of how get the ID one step further (i.e. it needs to post when the user clicks send in order for the TokenValue hook to make use of it and create the correct query). Do I need a second hook somewhere to create a custom hidden input on the email creation page, or to put my participant ID into a PHP session variable?  
  
  ---
  
  