1

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?

1

The New Entry button is not being displayed as Craft is not seeing my sources as containing publishable entries.

The Craft JS object contains a list of publishableSections which is checked by craft.js using this.getSourceByKey('section:'+section.id). Since my sources use a custom key value they are not included in this list.

So I have resolved the problem by adding my own New Entry button.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.