Answers.Body: <p><strong>Create an extension</strong></p>
  
  <p>The first step to create a hook is to create an extension.
  I'd recommend installing <a href="https://github.com/totten/civix" rel="nofollow noreferrer">civix</a> which can generate an empty extension by simply typing the command :</p>
  
  <pre><code>civix generate:module myextension
  </code></pre>
  
  <p>Go check <a href="https://docs.civicrm.org/dev/en/latest/extensions/" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/extensions/</a> for more details about extensions.</p>
  
  <p>All you need to know for now is that civix will create a file called myextension.php where you can put your hooks. There are a few hooks commented as examples in the generated files.</p>
  
  <p><strong>Create the hook</strong></p>
  
  <p>A hook is simply a function that start with the name of your extension and finish with the name of the hook. For example <code>hook_civicrm_post</code> will be named <code>myextension_civicrm_post</code> in the extension we've just created.</p>
  
  <p>In your case, I believe <code>hook_civicrm_post</code> is the one you want to use but you can see the documentation about the hooks in :</p>
  
  <ul>
  <li><a href="https://docs.civicrm.org/dev/en/latest/hooks/" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/hooks/</a></li>
  <li><a href="https://docs.civicrm.org/dev/en/latest/hooks/list/" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/hooks/list/</a></li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-04T15:50:30.970Z
Answers.Text: If they want to validate the external id then hook_civicrm_validateForm might be a better fit than _post.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-05T21:06:46.233Z
Answers.Text: Yes, depends on what the OP wants. If it's a kind of sync that is needed and that needs to work with API calls, then _post is probably the way to go. If it's for UI validation, then validateForm might be better.
Answers.UserDisplayName: samuelsov
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-06T16:03:06.833Z
Answers.Text: I'm reading about it, is interesting but how or where should I add my function callback with the singleton  `Civi::dispatcher()>addListener`? for me is not clear this part yet, it could be directly in my extesion? it would be loaded when somebody request something related to my custom extension?
Answers.UserDisplayName: Aneury Perez
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-11T22:04:38.093Z
Answers.Text: You probably don't need a dispatcher as the standard hooks will be automatically called if properly named in your (activated) extension. 
  In some specific case, you might need to use the addListener like so :
  
  Civi::service('dispatcher')->addListener('hook_civicrm_pageRun', 'reorderdashboard_symfony_civicrm_pageRun', -255);
  
  See also : https://github.com/civicrm/org.civicrm.shoreditch/pull/316/files
Answers.UserDisplayName: samuelsov
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-17T17:13:04.650Z
Answers.Text: Can hooks only be used by extensions? Is there a way to use hooks from within my theme's functions.php file for example?
Answers.UserDisplayName: dsmith63
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-04T15:20:06.350Z
Answers.LastActivityDate: 2019-12-04T15:20:06.350Z
Answers.UserDisplayName: samuelsov
Body: <p>I would to ask you , on how can create an event (programatically) when I change the external ID in contact form, how can I t make some kind of process like validation in another module or service I know I can create something like a hook but I dont know how to start working with hooks in civiccrm, is there any document, book ,link, video, note where I 
  can learn about it? I would really appreciate this, thank you in advance.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-12-05T14:37:25.287Z
Comments.Text: Hi Aneury, are you comfortable with hooks (actions & filters) in WordPress? If so, I can help you do this in a WordPress plugin.
Comments.UserDisplayName: Christian Wach
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-12-06T15:58:58.450Z
Comments.Text: I'm not comfortable with hooks yet, but it could be! let me know how to proceed with this, please.
Comments.UserDisplayName: Aneury Perez
Tags: <wordpress><hooks><external-id>
Title: how can I create an hook when external id change
ThreadText: # how can I create an hook when external id change
  
  (Asked by: username_0 on 2019-12-04)
  
  I would to ask you , on how can create an event (programatically) when I change the external ID in contact form, how can I t make some kind of process like validation in another module or service I know I can create something like a hook but I dont know how to start working with hooks in civiccrm, is there any document, book ,link, video, note where I
  can learn about it? I would really appreciate this, thank you in advance.
  
  **Tags:** wordpress, hooks, external-id
  
  > **Comments:**
  > **username_1**: Hi username_0, are you comfortable with hooks (actions & filters) in WordPress? If so, I can help you do this in a WordPress plugin.  
  > **username_0**: I'm not comfortable with hooks yet, but it could be! let me know how to proceed with this, please.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-12-04. Score: 1
  
  **Create an extension**
  
  The first step to create a hook is to create an extension.
  I'd recommend installing [civix](https://github.com/totten/civix) which can generate an empty extension by simply typing the command :
  
  ```
  civix generate:module myextension
  
  ```
  
  Go check <https://docs.civicrm.org/dev/en/latest/extensions/> for more details about extensions.
  
  All you need to know for now is that civix will create a file called myextension.php where you can put your hooks. There are a few hooks commented as examples in the generated files.
  
  **Create the hook**
  
  A hook is simply a function that start with the name of your extension and finish with the name of the hook. For example `hook_civicrm_post` will be named `myextension_civicrm_post` in the extension we've just created.
  
  In your case, I believe `hook_civicrm_post` is the one you want to use but you can see the documentation about the hooks in :
  
  * <https://docs.civicrm.org/dev/en/latest/hooks/>
  * <https://docs.civicrm.org/dev/en/latest/hooks/list/>
  
  > **Comments:**
  > **username_3**: If they want to validate the external id then hook_civicrm_validateForm might be a better fit than _post.  
  > **username_2**: Yes, depends on what the OP wants. If it's a kind of sync that is needed and that needs to work with API calls, then _post is probably the way to go. If it's for UI validation, then validateForm might be better.  
  > **username_0**: I'm reading about it, is interesting but how or where should I add my function callback with the singleton  `Civi::dispatcher()>addListener`? for me is not clear this part yet, it could be directly in my extesion? it would be loaded when somebody request something related to my custom extension?  
  > **username_2**: You probably don't need a dispatcher as the standard hooks will be automatically called if properly named in your (activated) extension.  In some specific case, you might need to use the addListener like so :  Civi::service('dispatcher')->addListener('hook_civicrm_pageRun', 'reorderdashboard_symfony_civicrm_pageRun', -255);  See also : https://github.com/civicrm/org.civicrm.shoreditch/pull/316/files  
  > **username_4**: Can hooks only be used by extensions? Is there a way to use hooks from within my theme's functions.php file for example?  
  
  ---
  
  