core
core copied to clipboard
$content->setFieldValue('image', 'image.png'); doesn't work
Can't update/create image field in fixtures
protected function load(ContentFactory $factory): void
{
$content = $this->factory->create('image');
$content->setFieldValue('slug', 'icon');
$content->setFieldValue('image', 'image.png');
$this->factory->save($content);
}
Details
Question | Answer |
---|---|
Relevant Bolt Version | 5.1.20 |
Install type | composer |
PHP version | 8 |
Web server | Nginx |
For UX/UI issues | Browser name and version |
Reproduction
- have a contentype
image:
name: Images
slug: image
singular_name: Image
searchable: false
viewless: true
fields:
slug:
type: slug
image:
type: image
- update/create record
$content = $this->factory->create('image');
$content->setFieldValue('slug', 'icon');
$content->setFieldValue('image', 'image.png');
$this->factory->save($content);
Bug summary
Problem is text fields are updated as expected, but not image field
Specifics
* Mention the URL where this bug occurs, if applicable
* What version of Bolt are you using (down to the very last digit!) 5.1.20
* What method did you use to install Bolt - composer
* What browser and version you are using - using cli
Expected result
Image gets updated
Actual result
text fields are updated, image field not
Why are you saving the factory? Shouldn't you save/persist the Content itself?
The same result is got when using
$this->factory->save($content);
or
$manager->persist($content);
$manager->flush();
Initially I used factory because bolt5 docs recommended it https://docs.boltcms.io/5.0/extensions/creating_content