Skip to content

[5.x]: Generated fields only regenerate on a second save with entry fields in contentBlock fields #17938

@lavandongen

Description

@lavandongen

What happened?

Description

I have encountered a bug with the generated fields, where the value of a generated field, that is based on an entry field in a contentBlock field will only be changed after you have already saved when changing the entry field. It only seems to generate on the value before the change in draft is applied.

Steps to reproduce

  1. Make an entry type, for this example I will call it pages
  2. Make a field of the Content block type, here contentBlock and add an Entry field entry
  3. Now add contentBlock to your pages entry type. Then go down to generated fields and enter contentBlockEntryId with the template {contentBlock.entry.one.id ?? null}.
  4. Read out {{ entry.contentBlockEntryId }} on the page template.

Expected behaviour

This should, when properly implemented mean that when changing the entry field to a different entry, and we save the generated field will display the id of the page we selected.

Actual behavior

However, in reality when we read out {{ entry.contentBlockEntryId }} after changing the Entry field the first time it will still display null. Then when resaving the page but changing nothing, the id suddenly is shown.

This continuous when changing, or emptying the entry value. The value contentBlockEntryId is consistent to the value it was before the drafted change is applied when saving.

Craft CMS version

Craft Pro 5.8.18

PHP version

8.4.10

Operating system and version

Linux 5.15.0-144-generic

Database type and version

MySQL 8.0.42

Image driver and version

Imagick 3.8.0 (ImageMagick 6.9.11-60)

Installed plugins and versions

CKEditor - 4.10.1
Craft Meilisearch - 5.10.0
Formie - 3.1.4
Image Resizer - 4.0.4
Maps - 5.0.4
Navigation - 3.0.13
Retour - 5.0.12
Sentry Logger - 5.0.2
SEOmatic - 5.1.17
Smith - 3.1.1
Template Comments - 5.0.4
Vite - 5.0.1

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions