We're putting together a site where there is regional content managed by regional editors. I want to override the sources to only list entries from regions they are allocated to. I also want to group them by region rather than having entries for all their regions in one list.
All was going well until I tried to remove the default Craft sources by clearing the $sources
array at the start. This has resulted in the New Entry button no longer being displayed.
This is my function at the moment:
public function modifyEntrySources(&$sources, $context)
{
if ($context == 'index')
{
if ($this->regionalEd)
{
$sources = [];
foreach ($this->regions as $region)
{
$sources[] = ['heading' => $region['title']];
$sources['news:'.$region['id']] = [
'label' => 'News',
'criteria' => ['relatedTo' => $region['id'], 'section' => 'news', 'editable' => true],
'data' => array('type' => SectionType::Channel, 'handle' => 'news'),
'defaultSort' => array('postDate', 'desc'),
];
$sources['notifications:'.$region['id']] = [
'label' => 'Notifications',
'criteria' => ['relatedTo' => $region['id'], 'section' => 'notifications', 'editable' => true],
'data' => array('type' => SectionType::Channel, 'handle' => 'notifications'),
'defaultSort' => array('postDate', 'desc'),
];
}
}
}
}
Is there something I need to add/remove, (other than the $sources = [];
line!), to allow the New Entry button to be displayed?