What happened?
Sidenote... craft\services\Fields::EVENT_BEFORE_APPLY_FIELD_SAVE is not included in the Event Generator.
I believe there is a bug in the new EVENT_BEFORE_APPLY_FIELD_SAVE event. Specifically, the $event->field value is inconsistent based on whether you are:
- (A) Changing the field type in the Control Panel (locally), or
- (B) Applying your Project Config changes.
Here is my current code (shown below via Xdebug).
Locally, (scenario A) the $event->field registers as a Google Maps field...
But if you roll back the database and apply the modified Project Config (scenario B), the $event->field registers as an Ether field...
This is tangentially related to a very important question...
⭐️ What is the best way to determine both the before and after types of the changing field? ⭐
I noticed that ProjectConfig::EVENT_UPDATE_ITEM emits a ConfigEvent, which contains both an $oldValue and a $newValue. Is it possible to introduce something similar to the ApplyFieldSaveEvent?
Steps to reproduce
You can get the mostly-functional dev version of this feature here...
"doublesecretagency/craft-googlemaps": "dev-v5-features/address-conversion"
- Install Google Maps & Ether Maps.
- Create an Ether Map field and populate it with some data.
- Go to Settings > Fields and find your Map field.
- Change the field type to Address (Google Maps) and save.
- The field should convert as expected, and existing Address data should be properly ported over.
...however...
- Roll back the database.
- Apply the same change via Project Config.
- Notice that these scenarios are handled differently.
Expected behavior
The $event->field value should be consistent whether I am changing the field type initially, or applying that change via Project Config.
Additionally, there should be an easy way to determine what the field type is changing to and from.
Actual behavior
- Changing the field type via CP sets the
$event->field to a Google Maps field, but
- Changing the field type via Project Config sets the
$event->field to an Ether field.
Craft CMS version
5.5.2
PHP version
8.2.22
Operating system and version
Linux 6.11.6-orbstack-00279-g28c6c77332e6
Database type and version
MySQL 8.0.36
Image driver and version
Imagick 3.7.0 (ImageMagick 6.9.11-60)
Installed plugins and versions
- Google Maps v5.0.3 (dev-v5-features/address-conversion)
- Ether Maps v5.0.4
What happened?
Sidenote...
craft\services\Fields::EVENT_BEFORE_APPLY_FIELD_SAVEis not included in the Event Generator.I believe there is a bug in the new
EVENT_BEFORE_APPLY_FIELD_SAVEevent. Specifically, the$event->fieldvalue is inconsistent based on whether you are:Here is my current code (shown below via Xdebug).
Locally, (scenario A) the
$event->fieldregisters as a Google Maps field...But if you roll back the database and apply the modified Project Config (scenario B), the
$event->fieldregisters as an Ether field...This is tangentially related to a very important question...
⭐️ What is the best way to determine both the before and after types of the changing field? ⭐
I noticed that
ProjectConfig::EVENT_UPDATE_ITEMemits a ConfigEvent, which contains both an$oldValueand a$newValue. Is it possible to introduce something similar to the ApplyFieldSaveEvent?Steps to reproduce
You can get the mostly-functional dev version of this feature here...
...however...
Expected behavior
The
$event->fieldvalue should be consistent whether I am changing the field type initially, or applying that change via Project Config.Additionally, there should be an easy way to determine what the field type is changing to and from.
Actual behavior
$event->fieldto a Google Maps field, but$event->fieldto an Ether field.Craft CMS version
5.5.2
PHP version
8.2.22
Operating system and version
Linux 6.11.6-orbstack-00279-g28c6c77332e6
Database type and version
MySQL 8.0.36
Image driver and version
Imagick 3.7.0 (ImageMagick 6.9.11-60)
Installed plugins and versions