Setting up the sources in the sidebar isn't difficult. Add the modifyEntrySources()
(link) 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) 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!