Answers.Body: <p>Events don’t get pre-registered anywhere in Craft, so there’s no way to easily fetch a definitive list of all events that will ever get called, but with a little PHP we can get a pretty good idea of what they all are.</p>
  
  <p>You’d start by getting a list of all the components on <a href="http://buildwithcraft.com/classreference/etc/web/WebApp" rel="nofollow">WebApp</a> (what <code>craft()</code> returns) by calling its <a href="http://www.yiiframework.com/doc/api/1.1/CModule#getComponents-detail" rel="nofollow">getComponents()</a> method, loop through each of them, use reflection to get each of their methods, and find the ones that start with <code>on</code>. (By convention, all event methods should start with that, and non-event methods generally shouldn’t start with that, although it’s possible this will yield some false positives, so make sure you double-check the results.)</p>
  
  <pre class="lang-php prettyprint-override"><code>$events = [];
  $components = craft()-&gt;getComponents(false);
  
  foreach ($components as $id =&gt; $component)
  {
      // Skip some non-existent components
      if ($id == 'fieldTypes' || $id == 'file')
      {
          continue;
      }
  
      // If the component hasn't been loaded yet, $component will just be its config array
      if (is_array($component))
      {
          $component = craft()-&gt;getComponent($id);
      }
  
      // Find the event methods
      $class = new \ReflectionClass($component);
      $methods = $class-&gt;getMethods(\ReflectionMethod::IS_PUBLIC);
  
      foreach ($methods as $method)
      {
          if (strncasecmp($method-&gt;name, 'on', 2) === 0)
          {
              $events[] = $id.'.'.$method-&gt;name;
          }
      }
  }
  
  // Dump 'em out
  Craft::dd($events);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-04T18:55:56.623Z
Answers.Text: Exactly what I needed, thanks a bunch Brandon!
Answers.UserDisplayName: Selvin Ortiz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-04T18:58:22.283Z
Answers.Text: @SelvinOrtiz Just made a quick edit after testing locally - apparently we have a couple component definitions that shouldn't actually be there. I'll remove those for the next release, but for now you can just skip them with a quick conditional.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-04T18:52:11.860Z
Answers.LastActivityDate: 2014-12-04T18:57:34.197Z
Answers.LastEditDate: 2014-12-04T18:57:34.197Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>The documentation provides a very <a href="http://buildwithcraft.com/docs/plugins/events-reference" rel="nofollow">comprehensive list of events</a> provided by Craft  but I would like to know if there is a way to get a list of those events at runtime.</p>
  
  <p>Having such list would enable me to display a <code>&lt;select&gt;</code> field whereby a user could choose the event that should trigger an action.</p>
  
  <p>Think of it as <strong>dynamic event registration!</strong></p>
  
Tags: <events>
Title: How do I get a list of craft provided events at runtime?
ThreadText: # How do I get a list of craft provided events at runtime?
  
  (Asked by: username_0 on 2014-12-04)
  
  The documentation provides a very [comprehensive list of events](http://buildwithcraft.com/docs/plugins/events-reference) provided by Craft but I would like to know if there is a way to get a list of those events at runtime.
  
  Having such list would enable me to display a `<select>` field whereby a user could choose the event that should trigger an action.
  
  Think of it as **dynamic event registration!**
  
  **Tags:** events
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-12-04. Score: 3 | Accepted answer
  
  Events don’t get pre-registered anywhere in Craft, so there’s no way to easily fetch a definitive list of all events that will ever get called, but with a little PHP we can get a pretty good idea of what they all are.
  
  You’d start by getting a list of all the components on [WebApp](http://buildwithcraft.com/classreference/etc/web/WebApp) (what `craft()` returns) by calling its [getComponents()](http://www.yiiframework.com/doc/api/1.1/CModule#getComponents-detail) method, loop through each of them, use reflection to get each of their methods, and find the ones that start with `on`. (By convention, all event methods should start with that, and non-event methods generally shouldn’t start with that, although it’s possible this will yield some false positives, so make sure you double-check the results.)
  
  ```php
  $events = [];
  $components = craft()->getComponents(false);
  
  foreach ($components as $id => $component)
  {
      // Skip some non-existent components
      if ($id == 'fieldTypes' || $id == 'file')
      {
          continue;
      }
  
      // If the component hasn't been loaded yet, $component will just be its config array
      if (is_array($component))
      {
          $component = craft()->getComponent($id);
      }
  
      // Find the event methods
      $class = new \ReflectionClass($component);
      $methods = $class->getMethods(\ReflectionMethod::IS_PUBLIC);
  
      foreach ($methods as $method)
      {
          if (strncasecmp($method->name, 'on', 2) === 0)
          {
              $events[] = $id.'.'.$method->name;
          }
      }
  }
  
  // Dump 'em out
  Craft::dd($events);
  
  ```
  
  > **Comments:**
  > **username_0**: Exactly what I needed, thanks a bunch username_1!  
  > **username_1**: @username_0 Just made a quick edit after testing locally - apparently we have a couple component definitions that shouldn't actually be there. I'll remove those for the next release, but for now you can just skip them with a quick conditional.  
  
  ---
  
  