diff --git a/wire/core/Fields.php b/wire/core/Fields.php index 89e2e9cb..3e4710a4 100644 --- a/wire/core/Fields.php +++ b/wire/core/Fields.php @@ -5,7 +5,7 @@ * * Manages collection of ALL Field instances, not specific to any particular Fieldgroup * - * ProcessWire 3.x, Copyright 2022 by Ryan Cramer + * ProcessWire 3.x, Copyright 2023 by Ryan Cramer * https://processwire.com * * #pw-summary Manages all custom fields in ProcessWire, independently of any Fieldgroup. @@ -357,6 +357,7 @@ class Fields extends WireSaveableItems { } if(!$item->type) throw new WireException("Can't save a Field that doesn't have it's 'type' property set to a Fieldtype"); + $item->type->saveFieldReady($item); if(!parent::___save($item)) return false; if($isNew) $item->type->createField($item); @@ -773,7 +774,7 @@ class Fields extends WireSaveableItems { // so use verbose/slow method to delete the field from pages $ids = $this->getNumPages($field, array('template' => $template, 'getPageIDs' => true)); - $items = $this->wire('pages')->getById($ids, $template); + $items = $this->wire()->pages->getById($ids, $template); foreach($items as $page) { try { @@ -791,7 +792,7 @@ class Fields extends WireSaveableItems { // large number of pages to operate on: use fast method - $database = $this->wire('database'); + $database = $this->wire()->database; $table = $database->escapeTable($field->getTable()); $sql = "DELETE $table FROM $table " . "INNER JOIN pages ON pages.id=$table.pages_id " . diff --git a/wire/core/Fieldtype.php b/wire/core/Fieldtype.php index c2a4ea9d..540ef5f0 100644 --- a/wire/core/Fieldtype.php +++ b/wire/core/Fieldtype.php @@ -47,6 +47,7 @@ * @method Field cloneField(Field $field) * @method void renamedField(Field $field, $prevName) * @method void savedField(Field $field) + * @method void saveFieldReady(Field $field) * @method void install() * @method void uninstall() * @@ -992,8 +993,9 @@ abstract class Fieldtype extends WireData implements Module { if($a == 'CHARSET') $info['charset'] = $b; } } - if(!$info['engine']) $info['engine'] = $this->wire('config')->dbEngine; - if(!$info['charset']) $info['charset'] = $this->wire('config')->dbCharset; + $config = $this->wire()->config; + if(!$info['engine']) $info['engine'] = $config->dbEngine; + if(!$info['charset']) $info['charset'] = $config->dbCharset; if($info['engine']) $info['engine'] = str_replace(array('MYISAM', 'INNODB'), array('MyISAM', 'InnoDB'), $info['engine']); $info['transactions'] = $info['engine'] == 'InnoDB'; } @@ -1505,6 +1507,7 @@ abstract class Fieldtype extends WireData implements Module { * Most Fieldtypes don't need to do anything here, but this exists just in case. * * #pw-internal + * #pw-hooker * * @param Field $field * @param string $prevName Previous name (current name can be found in $field->name) @@ -1513,12 +1516,30 @@ abstract class Fieldtype extends WireData implements Module { public function ___renamedField(Field $field, $prevName) { } + /** + * Hook called by Fields::save() when a field is about to be saved + * + * If field is a new field it will not yet have an id. + * + * #pw-internal + * #pw-hooker + * + * @param Field $field + * @since 3.0.212 + * + */ + public function ___saveFieldReady(Field $field) { + } + /** * 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. * + * #pw-internal + * #pw-hooker + * * @param Field $field * @since 3.0.171 *