mirror of
https://github.com/moodle/moodle.git
synced 2025-04-09 02:12:22 +02:00
Merge branch 'MDL-79365-401' of https://github.com/paulholden/moodle into MOODLE_401_STABLE
This commit is contained in:
commit
c4c514ee46
@ -238,7 +238,13 @@ abstract class data_controller {
|
||||
*/
|
||||
protected function is_unique($value) : bool {
|
||||
global $DB;
|
||||
|
||||
// Ensure the "value" datafield can be safely compared across all databases.
|
||||
$datafield = $this->datafield();
|
||||
if ($datafield === 'value') {
|
||||
$datafield = $DB->sql_cast_to_char($datafield);
|
||||
}
|
||||
|
||||
$where = "fieldid = ? AND {$datafield} = ?";
|
||||
$params = [$this->get_field()->get('id'), $value];
|
||||
if ($this->get('id')) {
|
||||
|
@ -136,6 +136,29 @@ class data_controller extends \core_customfield\data_controller {
|
||||
$instance->{$this->get_form_element_name()} = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the value is empty, overriding the base method to ensure it's the "text" element of our value being compared
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_empty($value): bool {
|
||||
if (is_array($value)) {
|
||||
$value = $value['text'];
|
||||
}
|
||||
return html_is_blank($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the value is unique, overriding the base method to ensure it's the "text" element of our value being compared
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_unique($value): bool {
|
||||
return parent::is_unique($value['text']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete data
|
||||
*
|
||||
@ -166,9 +189,6 @@ class data_controller extends \core_customfield\data_controller {
|
||||
require_once($CFG->libdir . '/filelib.php');
|
||||
|
||||
$value = $this->get_value();
|
||||
if ($this->is_empty($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($dataid = $this->get('id')) {
|
||||
$context = $this->get_context();
|
||||
|
Loading…
x
Reference in New Issue
Block a user