mirror of
https://github.com/processwire/processwire.git
synced 2025-08-10 08:44:46 +02:00
Add Fieldtype::isDeleteValue() method to isolate that particular logic outside of savePageField() method so it can more easily be overridden
This commit is contained in:
@@ -494,6 +494,23 @@ abstract class Fieldtype extends WireData implements Module {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is given value one that should cause the DB row(s) to be deleted rather than saved?
|
||||||
|
*
|
||||||
|
* Not applicable to Fieldtypes that override the savePageField() method with their own
|
||||||
|
* implementation, unless they also use this method.
|
||||||
|
*
|
||||||
|
* @param Page $page
|
||||||
|
* @param Field $field
|
||||||
|
* @param mixed $value
|
||||||
|
* @return bool
|
||||||
|
* @since 3.0.150
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function isDeleteValue(Page $page, Field $field, $value) {
|
||||||
|
return $value === $this->getBlankValue($page, $field);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether the given value is considered empty or not.
|
* Return whether the given value is considered empty or not.
|
||||||
*
|
*
|
||||||
@@ -1132,8 +1149,10 @@ abstract class Fieldtype extends WireData implements Module {
|
|||||||
$database = $this->wire('database');
|
$database = $this->wire('database');
|
||||||
$value = $page->get($field->name);
|
$value = $page->get($field->name);
|
||||||
|
|
||||||
// if the value is the same as the default, then remove the field from the database because it's redundant
|
// if the value is one that should be deleted, then remove the field from the database because it's redundant
|
||||||
if($value === $this->getBlankValue($page, $field)) return $this->deletePageField($page, $field);
|
if($this->isDeleteValue($page, $field, $value)) {
|
||||||
|
return $this->deletePageField($page, $field);
|
||||||
|
}
|
||||||
|
|
||||||
$value = $this->sleepValue($page, $field, $value);
|
$value = $this->sleepValue($page, $field, $value);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user