core icon indicating copy to clipboard operation
core copied to clipboard

$content->setFieldValue('image', 'image.png'); doesn't work

Open Saltibarsciai opened this issue 9 months ago • 2 comments

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

  1. have a contentype
image:
    name: Images
    slug: image
    singular_name: Image
    searchable: false
    viewless: true
    fields:
        slug:
            type: slug
        image:
            type: image
  1. 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

Saltibarsciai avatar Sep 16 '23 20:09 Saltibarsciai

Why are you saving the factory? Shouldn't you save/persist the Content itself?

bobdenotter avatar Sep 18 '23 09:09 bobdenotter

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

Saltibarsciai avatar Sep 18 '23 10:09 Saltibarsciai