1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-12 17:54:44 +02:00

Add new Fieldtype::saveFieldReady(Field $field) hook that is called right before a Field object is about to be saved. For newly created fields, the given $field will have $field->id==0

This commit is contained in:
Ryan Cramer
2023-02-09 09:54:28 -05:00
parent e86eb7fcf8
commit 1171241f5d
2 changed files with 27 additions and 5 deletions

View File

@@ -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 " .