<p>After getting some feedback from <em>Craft</em> support it turns out one has to use <code>uid</code> instead of <code>id</code> for this to work:</p>

<pre><code>"sources" =&gt; ["section:" . $questionsSection-&gt;uid],
</code></pre>

<p>Since I had a lot of places in my migration where I needed to specify sources, I included a couple small functions:</p>

<pre><code>/* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- */

protected function _section_id($sectionHandle)
{
    return Craft::$app-&gt;sections-&gt;getSectionByHandle($sectionHandle)-&gt;uid;

} // _section_id()

/* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- */

protected function _source($handle, $kind = 'section')
{
    $source = $kind . ':' . $this-&gt;_section_id($handle);
    return $source;

} // _source()

/* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- */
</code></pre>

<p>You can then limit the entries field sources like so:</p>

<pre><code>"source" =&gt; null,
"sources" =&gt; [
    $this-&gt;_source("sectionA"),
    $this-&gt;_source("sectionB"),
],
</code></pre>

<p>(Note that I'm additionally setting <code>"source" =&gt; null</code> as per a plugin-created migration I analyzed, but not sure if it's required.)</p>

CC BY-SA 4.0
2019-07-30T11:04:25.657Z
2019-07-30T11:04:25.657Z
JSICS
<p>I'm seeting up all of my project's fields using migrations.
This works really well, but I haven't been able to figure out how to limit the sources (sections) for an entry selection field.</p>

<p>I've based my work on this <a href="https://github.com/vend/craft3-migration-examples/blob/master/migrations/m180717_214112_faq_entry_matrix_block.php" rel="nofollow noreferrer">migrations example</a>, which contains the following code:</p>

<pre><code>new \craft\fields\Entries([
    "name" =&gt; "Questions",
    "handle" =&gt; "questions",
    "instructions" =&gt; "Choose one or more questions",
    "sources" =&gt; ["section:" . $questionsSection-&gt;id],
    "limit" =&gt; 10,
    "required" =&gt; false,
    "selectionLabel" =&gt; "Select Questions",
]),
</code></pre>

<p>However, I don't get how I can add <em>multiple</em> sections as allowed sources… can anybody clarify how to do this?</p>

CC BY-SA 4.0
2019-07-29T18:19:11.643Z
Could you add your update as an official answer instead of an update to the original question?
Brad Bell
CC BY-SA 4.0
2019-07-30T11:04:58.993Z
@BradBell, done. Thanks for pointing that out.
JSICS
<entries-field><migration><sources>
How to limit sources for Entries field set up via migration
# How to limit sources for Entries field set up via migration

(Asked by: username_0 on 2019-07-01)

I'm seeting up all of my project's fields using migrations.
This works really well, but I haven't been able to figure out how to limit the sources (sections) for an entry selection field.
I've based my work on this migrations example, which contains the following code:
new \craft\fields\Entries([
    "name" => "Questions",
    "handle" => "questions",
    "instructions" => "Choose one or more questions",
    "sources" => ["section:" . $questionsSection->id],
    "limit" => 10,
    "required" => false,
    "selectionLabel" => "Select Questions",
]),

However, I don't get how I can add multiple sections as allowed sources… can anybody clarify how to do this?

**Tags:** entries-field, migration, sources

> **Comments:**
> **username_1**: Could you add your update as an official answer instead of an update to the original question?  
> **username_0**: @BradBell, done. Thanks for pointing that out.  

---

## 1 answers

### Answer by username_0 on 2019-07-30. Score: 1

After getting some feedback from Craft support it turns out one has to use uid instead of id for this to work:
"sources" => ["section:" . $questionsSection->uid],

Since I had a lot of places in my migration where I needed to specify sources, I included a couple small functions:
/* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- */

protected function _section_id($sectionHandle)
{
    return Craft::$app->sections->getSectionByHandle($sectionHandle)->uid;

} // _section_id()

/* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- */

protected function _source($handle, $kind = 'section')
{
    $source = $kind . ':' . $this->_section_id($handle);
    return $source;

} // _source()

/* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- */

You can then limit the entries field sources like so:
"source" => null,
"sources" => [
    $this->_source("sectionA"),
    $this->_source("sectionB"),
],

(Note that I'm additionally setting "source" => null as per a plugin-created migration I analyzed, but not sure if it's required.)


---

