<p>Prepending the field name with <code>field:</code> should do the trick.</p>
<pre class="lang-php prettyprint-override"><code>&lt;?php

return [
    [
        'sectionId' =&gt; $this-&gt;sectionIds['locations'],
        'typeId' =&gt; $this-&gt;typeIds['locations']['locations'],
        'title' =&gt; 'Location 1',
        'field:gmbId' =&gt; '123',
    ],
];
</code></pre>
<p>See <a href="https://github.com/craftcms/cms/blob/develop/tests/fixtures/data/entry-with-fields.php" rel="nofollow noreferrer">https://github.com/craftcms/cms/blob/develop/tests/fixtures/data/entry-with-fields.php</a> for reference.</p>

CC BY-SA 4.0
2021-02-17T16:27:42.980Z
I'm an idot....this whole time that field wasn't even attached to this particular entrytype. Thank you so much for helping!
Myles Hyson
CC BY-SA 4.0
2021-02-17T15:54:33.943Z
2021-02-17T15:54:33.943Z
Ben Croker
<p>I can't for the life of me figure out how to setup EntryFixtures in craft to populate with custom fields. I'm using the project config which already has the sections and fields defined in my tests. I'm trying to set a field, <code>gmbId</code>, that's set on a <code>locations</code> entry type. Here's my code. I feel like I'm missing something basic here.</p>
<p>codeception.yml</p>
<pre class="lang-yaml prettyprint-override"><code>actor: Tester
paths:
  tests: tests
  log: tests/_output
  data: tests/_data
  support: tests/_support
  envs: tests/_envs
bootstrap: _bootstrap.php
params:
  - tests/.env
modules:
  config:
    \craft\test\Craft:
      configFile: &quot;tests/_craft/config/test.php&quot;
      entryUrl: &quot;http://host.docker.internal/index.php&quot;
      projectConfig: {
        folder: &quot;config/project&quot;,
        reset: true
      }
      migrations: []
      plugins: []
      cleanup: true
      transaction: true
      dbSetup: { clean: true, setupCraft: true }

</code></pre>
<p>LocationFixture.php</p>
<pre class="lang-php prettyprint-override"><code>&lt;?php

namespace tests\fixtures;

use craft\test\fixtures\elements\EntryFixture;

class LocationFixture extends EntryFixture
{
    public $dataFile = __DIR__ . '/data/locations.php';
}

</code></pre>
<p>locations.php</p>
<pre class="lang-php prettyprint-override"><code>&lt;?php

return [
    [
        'sectionId' =&gt; $this-&gt;sectionIds['locations'],
        'typeId' =&gt; $this-&gt;typeIds['locations']['locations'],
        'title' =&gt; 'Location 1',
        'gmbId' =&gt; '123' # this is the custom field I'm trying to set.
    ],
    [
        'sectionId' =&gt; $this-&gt;sectionIds['locations'],
        'typeId' =&gt; $this-&gt;typeIds['locations']['locations'],
        'title' =&gt; 'Location 2',
        'gmbId' =&gt; '123'
    ],
    [
        'sectionId' =&gt; $this-&gt;sectionIds['locations'],
        'typeId' =&gt; $this-&gt;typeIds['locations']['locations'],
        'title' =&gt; 'Location 3',
        'gmbId' =&gt; '123'
    ]
];

</code></pre>

<entries><sections><entries-field><elementquery><tests>
How do you save custom fields on an EntryFixture?
# How do you save custom fields on an EntryFixture?

(Asked by: username_0 on 2021-02-16)

I can't for the life of me figure out how to setup EntryFixtures in craft to populate with custom fields. I'm using the project config which already has the sections and fields defined in my tests. I'm trying to set a field, gmbId, that's set on a locations entry type. Here's my code. I feel like I'm missing something basic here.
codeception.yml
actor: Tester
paths:
  tests: tests
  log: tests/_output
  data: tests/_data
  support: tests/_support
  envs: tests/_envs
bootstrap: _bootstrap.php
params:
  - tests/.env
modules:
  config:
    \craft\test\Craft:
      configFile: "tests/_craft/config/test.php"
      entryUrl: "http://host.docker.internal/index.php"
      projectConfig: {
        folder: "config/project",
        reset: true
      }
      migrations: []
      plugins: []
      cleanup: true
      transaction: true
      dbSetup: { clean: true, setupCraft: true }


LocationFixture.php

locations.php
 $this->sectionIds['locations'],
        'typeId' => $this->typeIds['locations']['locations'],
        'title' => 'Location 1',
        'gmbId' => '123' # this is the custom field I'm trying to set.
    ],
    [
        'sectionId' => $this->sectionIds['locations'],
        'typeId' => $this->typeIds['locations']['locations'],
        'title' => 'Location 2',
        'gmbId' => '123'
    ],
    [
        'sectionId' => $this->sectionIds['locations'],
        'typeId' => $this->typeIds['locations']['locations'],
        'title' => 'Location 3',
        'gmbId' => '123'
    ]
];

**Tags:** entries, sections, entries-field, elementquery, tests


---

## 1 answers

### Answer by username_1 on 2021-02-17. Score: 1 | Accepted answer

Prepending the field name with field: should do the trick.
 $this->sectionIds['locations'],
        'typeId' => $this->typeIds['locations']['locations'],
        'title' => 'Location 1',
        'field:gmbId' => '123',
    ],
];

See https://github.com/craftcms/cms/blob/develop/tests/fixtures/data/entry-with-fields.php for reference.

> **Comments:**
> **username_0**: I'm an idot....this whole time that field wasn't even attached to this particular entrytype. Thank you so much for helping!  

---

