Answers.Body: <p>Setting up the sources in the sidebar isn't difficult. Add the <code>modifyEntrySources()</code>(<a href="http://buildwithcraft.com/docs/plugins/hooks-reference#modifyEntrySources" rel="nofollow">link</a>) hook to <code>MyCustomPlugin.php</code>.</p>
  
  <pre><code>public function modifyEntrySources(&amp;$sources, $context)
  {
      if ($context == 'index')
      {
          $sources[] = array('heading' =&gt; 'My Custom Heading');
  
          $sources['mypluginhandle:mysectionname'] = array(
              'label' =&gt; 'My Section Name',
              'criteria' =&gt; array('myPluginHandle' =&gt; 'SQL CODE HERE')
          );
      }
  }
  </code></pre>
  
  <p>At this point you should have a new entry heading and source in the Entries Listing page. Clicking on it isn't going to filter your data as you may expect... yet.</p>
  
  <p>Notice the <code>'criteria' =&gt; array('myPluginHandle' =&gt; 'SQL CODE HERE')</code>? This is what you are going to use to filter the entries according to what you want to see. Everything that is in the value of the 'myPluginHandle' array will be passed over to the <code>modifyElementsQuery()</code> (<a href="http://buildwithcraft.com/classreference/fieldtypes/BaseFieldType#modifyElementsQuery-detail" rel="nofollow">link</a>) method in the <code>MyCustomFieldtype.php</code> file. This is where you can build out your SQL statement accordingly.</p>
  
  <pre><code>public function modifyElementsQuery(DbCommand $query, $params)
  {
      if ($params != null) {
  
          // whatever you need to do to dig in to your custom fields' data...
          // using the code above, $params would be equal to 'SQL CODE HERE'
  
          $query-&gt;where($params);
      }
  }
  </code></pre>
  
  <p>This should be all you need to filter your entries by your custom field!</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-20T20:20:24.697Z
Answers.LastActivityDate: 2015-05-20T20:20:24.697Z
Answers.UserDisplayName: Jesse Schutt
Body: <p><a href="https://craftcms.stackexchange.com/questions/9835/how-can-i-add-data-from-my-custom-plugin-to-the-entry-listing-table">Now that I have my custom field displaying in the Entries Table</a>, how can I set up sources to view entries containing specific data from my custom field? My custom field holds several different values, but I want to have a filter set up to view specific things. </p>
  
  <p><em>Note: this is being copied from the Craft Slack channel so we don't lose it</em></p>
  
Tags: <plugin-development>
Title: How can I set up sources based on my custom field data?
ThreadText: # How can I set up sources based on my custom field data?
  
  (Asked by: username_0 on 2015-05-20)
  
  [Now that I have my custom field displaying in the Entries Table](https://craftcms.stackexchange.com/questions/9835/how-can-i-add-data-from-my-custom-plugin-to-the-entry-listing-table), how can I set up sources to view entries containing specific data from my custom field? My custom field holds several different values, but I want to have a filter set up to view specific things.
  
  *Note: this is being copied from the Craft Slack channel so we don't lose it*
  
  **Tags:** plugin-development
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-05-20. Score: 3 | Accepted answer
  
  Setting up the sources in the sidebar isn't difficult. Add the `modifyEntrySources()`([link](http://buildwithcraft.com/docs/plugins/hooks-reference#modifyEntrySources)) hook to `MyCustomPlugin.php`.
  
  ```
  public function modifyEntrySources(&$sources, $context)
  {
      if ($context == 'index')
      {
          $sources[] = array('heading' => 'My Custom Heading');
  
          $sources['mypluginhandle:mysectionname'] = array(
              'label' => 'My Section Name',
              'criteria' => array('myPluginHandle' => 'SQL CODE HERE')
          );
      }
  }
  
  ```
  
  At this point you should have a new entry heading and source in the Entries Listing page. Clicking on it isn't going to filter your data as you may expect... yet.
  
  Notice the `'criteria' => array('myPluginHandle' => 'SQL CODE HERE')`? This is what you are going to use to filter the entries according to what you want to see. Everything that is in the value of the 'myPluginHandle' array will be passed over to the `modifyElementsQuery()` ([link](http://buildwithcraft.com/classreference/fieldtypes/BaseFieldType#modifyElementsQuery-detail)) method in the `MyCustomFieldtype.php` file. This is where you can build out your SQL statement accordingly.
  
  ```
  public function modifyElementsQuery(DbCommand $query, $params)
  {
      if ($params != null) {
  
          // whatever you need to do to dig in to your custom fields' data...
          // using the code above, $params would be equal to 'SQL CODE HERE'
  
          $query->where($params);
      }
  }
  
  ```
  
  This should be all you need to filter your entries by your custom field!
  
  
  ---
  
  