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

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

<p>So I have resolved the problem by adding my own New Entry button.</p>

CC BY-SA 3.0
2016-09-21T23:05:56.320Z
2016-09-21T23:05:56.320Z
fcb
<p>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.</p>

<p>All was going well until I tried to remove the default Craft sources by clearing the <code>$sources</code> array at the start. This has resulted in the New Entry button no longer being displayed.</p>

<p>This is my function at the moment:</p>

<pre><code>public function modifyEntrySources(&amp;$sources, $context)
{
    if ($context == 'index')
    {
        if ($this-&gt;regionalEd)
        {
            $sources = [];
            foreach ($this-&gt;regions as $region)
            {
                $sources[] = ['heading' =&gt; $region['title']];
                $sources['news:'.$region['id']] = [
                    'label'       =&gt; 'News',
                    'criteria'    =&gt; ['relatedTo' =&gt; $region['id'], 'section' =&gt; 'news', 'editable' =&gt; true],
                    'data'        =&gt; array('type' =&gt; SectionType::Channel, 'handle' =&gt; 'news'),
                    'defaultSort' =&gt; array('postDate', 'desc'),
                ];
                $sources['notifications:'.$region['id']] = [
                    'label'       =&gt; 'Notifications',
                    'criteria'    =&gt; ['relatedTo' =&gt; $region['id'], 'section' =&gt; 'notifications', 'editable' =&gt; true],
                    'data'        =&gt; array('type' =&gt; SectionType::Channel, 'handle' =&gt; 'notifications'),
                    'defaultSort' =&gt; array('postDate', 'desc'),
                ];
            }
        }
    }
}
</code></pre>

<p>Is there something I need to add/remove, (other than the <code>$sources = [];</code> line!), to allow the New Entry button to be displayed?</p>

<plugin-development><entries><control-panel>
Add Entry Button Not Shown When Overriding Entry Sources
# Add Entry Button Not Shown When Overriding Entry Sources

(Asked by: username_0 on 2016-09-20)

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?

**Tags:** plugin-development, entries, control-panel


---

## 1 answers

### Answer by username_0 on 2016-09-21. Score: 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.


---

