mirror of
https://github.com/processwire/processwire.git
synced 2025-08-11 09:14:58 +02:00
Fix issue processwire/processwire-issues#1172
This commit is contained in:
@@ -529,6 +529,25 @@ class FieldtypeOptions extends FieldtypeMulti implements Module {
|
||||
$this->wire('fields')->addHookAfter('cloned', $this, 'hookCloned');
|
||||
return parent::___cloneField($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the given field
|
||||
*
|
||||
* @param Field $field Field object
|
||||
* @return bool True on success, false on DB delete failure.
|
||||
*
|
||||
*/
|
||||
public function ___deleteField(Field $field) {
|
||||
$result = parent::___deleteField($field);
|
||||
try {
|
||||
$this->manager->deleteAllOptionsForField($field);
|
||||
} catch(\Exception $e) {
|
||||
$result = false;
|
||||
$this->error($e->getMessage());
|
||||
$this->trackException($e);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook called when field is cloned, to clone the selectable options from old field to new field
|
||||
|
@@ -669,6 +669,26 @@ class SelectableOptionManager extends Wire {
|
||||
return $cnt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all options for given field
|
||||
*
|
||||
* @param Field $field
|
||||
* @return int
|
||||
* @throws WireException
|
||||
*
|
||||
*/
|
||||
public function deleteAllOptionsForField(Field $field) {
|
||||
$database = $this->wire()->database;
|
||||
$table = self::optionsTable;
|
||||
$sql = "DELETE FROM `$table` WHERE fields_id=:fields_id";
|
||||
$query = $database->prepare($sql);
|
||||
$query->bindValue(':fields_id', $field->id, \PDO::PARAM_INT);
|
||||
$query->execute();
|
||||
$cnt = $query->rowCount();
|
||||
$this->message("Deleted $cnt row(s) from table $table", Notice::debug);
|
||||
return $cnt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given option titles for $field
|
||||
*
|
||||
|
Reference in New Issue
Block a user