-
Notifications
You must be signed in to change notification settings - Fork 638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add outgoing field config to the ApplyFieldSaveEvent #16168
add outgoing field config to the ApplyFieldSaveEvent #16168
Conversation
Thanks @i-just! 🙏 Just to clarify... would the I'm slightly confused about the difference between Once this PR is accepted, I assume my event logic would change to something closer to this... // If no field is provided, bail
if (!$field = $event->field) {
return;
}
// If not a Google Maps Address field, bail
if (!($field instanceof \doublesecretagency\googlemaps\fields\AddressField)) {
return;
}
// If no original field, bail
if (!$event->oldConfig) {
return;
}
// If original field wasn't a Maps Map field, bail
if (!$event->oldConfig instanceof \ether\simplemap\fields\MapField) {
return;
}
// ... migrate the field's data... Am I on the right track? Will this logic be executed consistently between the original save versus applying the PC change? |
@lindseydiloreto, the As to your code, I’d tweak that to check the
I hope this helps! |
Just refactored the PR a bit. Removed the |
Just tested this, and it seems to be working perfectly! Thanks @i-just and @brandonkelly! 🎉 🙏 Here's the final code we're using to determine whether or not to perform the migration... // If no field is provided, bail
if (!$field = $event->field) {
return;
}
// If not currently an Ether "Map" field, bail
if (!($field instanceof \ether\simplemap\fields\MapField)) {
return;
}
// If no new field config, bail
if (!$newConfig = $event->config) {
return;
}
// If new config isn't an "Address (Google Maps)" field, bail
if ($newConfig['type'] !== AddressField::class) {
return;
}
// ... migrate the field's data... I believe it is now behaving consistently between CP fieldtype changes & Project Config fieldtype changes. Thanks again! |
Description
Added
oldConfig
to theApplyFieldSaveEvent
to make it easier to compare the changes applied to the field.In addition to what the OP said:
Regardless of how the field is changed, the
Fields->applyFieldSave()
method still has the field record, which hasn’t been updated yet, which means we still have access to the outgoing field’s config. Getting that config and passing it in the event should give an easier way to compare the changes being applied to the field.Related issues
#16156