Normalise removal of fields from project config field layouts #11054
-
Currently when using project config plugins and modules have to take care of cleaning up deleted fields when implementing a field layout. Throughout Craft this is done via a Could this be cleaned up a little and moved to either a project config helper method or an Event? The purpose of this is to try and reduce some of the boilerplate required when dealing with project config. Helper Event::on(Fields::class, Fields::EVENT_AFTER_DELETE_FIELD, function(FieldEvent $event) {
\craft\helpers\ProjectConfig::pruneDeletedField(ProjectConfig::PATH_GLOBAL_SETS, $event);
\craft\helpers\ProjectConfig::pruneDeletedField(ProjectConfig::PATH_CATEGORY_GROUPS, $event);
// ...
} Events I've used the existing field event with a new Event::on(Fields::class, Fields::EVENT_AFTER_DELETE_FIELD, function(FieldEvent $event) {
$event->projectConfigPaths[] = ProjectConfig::PATH_GLOBAL_SETS;
$event->projectConfigPaths[] = ProjectConfig::PATH_CATEGORY_GROUPS;
// ...
} As an aside is the path being provided to |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Doh… looks like we forgot to update these methods when we refactored field layouts in Craft 3.5, so they’ve been pointless ever since then. I explored the idea of centralizing the pruning of deleted fields from field layouts when looking into #11333, but unfortunately there’s just not a clean & reliable way to do it, without risking unexpected data deletion. In the end, I decided it’s best to just let the field layouts continue to reference the deleted fields, and to stop logging a warning when instantiating a field layout with one. I’ve also deprecated all of the existing |
Beta Was this translation helpful? Give feedback.
Doh… looks like we forgot to update these methods when we refactored field layouts in Craft 3.5, so they’ve been pointless ever since then.
I explored the idea of centralizing the pruning of deleted fields from field layouts when looking into #11333, but unfortunately there’s just not a clean & reliable way to do it, without risking unexpected data deletion.
In the end, I decided it’s best to just let the field layouts continue to reference the deleted fields, and to stop logging a warning when instantiating a field layout with one.
I’ve also dep…