mirror of
https://github.com/processwire/processwire.git
synced 2025-08-13 18:24:57 +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:
@@ -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 " .
|
||||
|
@@ -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
|
||||
*
|
||||
|
Reference in New Issue
Block a user