Skip to content

[5.x]: Setting field values in Entry::EVENT_BEFORE_SAVE doesn't work when $firstSave is true #15369

@boboldehampsink

Description

@boboldehampsink

What happened?

Description

I have an Entry::EVENT_BEFORE_SAVE event in which I do:

$entry->setFieldValues([
    'latitude' => $coords['lat'],
    'longitude' => $coords['lng'],
]);

This works when updating entries, but not for the case where $entry->firstSave is true.

Steps to reproduce

  1. Create an event listener that sets entry field values.

Expected behavior

It should work on first save.

Actual behavior

The first time saving it doesn't work, on updating it does.

Craft CMS version

5.2.6

PHP version

8.3

Operating system and version

No response

Database type and version

PostgreSQL 16

Image driver and version

No response

Installed plugins and versions

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions