From 0bddf640db516af3bbfb62f24d95533bbf85e8fc Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 22 Jan 2021 14:12:58 -0500 Subject: [PATCH] Add a new Fieldtype::savedField interface method so that Fieldtypes can monitor when a field of their type has been saved, without having to attach a hook --- wire/core/Fields.php | 2 ++ wire/core/Fieldtype.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/wire/core/Fields.php b/wire/core/Fields.php index ee76f742..4f8b7179 100644 --- a/wire/core/Fields.php +++ b/wire/core/Fields.php @@ -300,6 +300,8 @@ class Fields extends WireSaveableItems { } } + if($item->type) $item->type->savedField($item); + $this->getTags('reset'); return true; diff --git a/wire/core/Fieldtype.php b/wire/core/Fieldtype.php index 45e21619..7e351889 100644 --- a/wire/core/Fieldtype.php +++ b/wire/core/Fieldtype.php @@ -46,6 +46,7 @@ * @method bool deleteTemplateField(Template $template, Field $field) * @method Field cloneField(Field $field) * @method void renamedField(Field $field, $prevName) + * @method void savedField(Field $field) * @method void install() * @method void uninstall() * @@ -1474,6 +1475,19 @@ abstract class Fieldtype extends WireData implements Module { if($field && $prevName) {} } + /** + * Called when Field using this Fieldtype has been saved + * + * This is primarily so that Fieldtype modules can identify when their fields are + * saved without having to add a hook to the $fields API var. + * + * @param Field $field + * @since 3.0.171 + * + */ + public function ___savedField(Field $field) { + } + /** * Get a property from this Fieldtype’s data *