mirror of
https://github.com/moodle/moodle.git
synced 2025-07-25 00:02:18 +02:00
MDL-68569 customfield_select: get field options via instance method.
Deprecate the previous static method, which was only called from instantiated field classes.
This commit is contained in:
@@ -24,8 +24,6 @@
|
||||
|
||||
namespace customfield_select;
|
||||
|
||||
use core_customfield\api;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
/**
|
||||
@@ -53,8 +51,7 @@ class data_controller extends \core_customfield\data_controller {
|
||||
public function get_default_value() {
|
||||
$defaultvalue = $this->get_field()->get_configdata_property('defaultvalue');
|
||||
if ('' . $defaultvalue !== '') {
|
||||
$options = field_controller::get_options_array($this->get_field());
|
||||
$key = array_search($defaultvalue, $options);
|
||||
$key = array_search($defaultvalue, $this->get_field()->get_options());
|
||||
if ($key !== false) {
|
||||
return $key;
|
||||
}
|
||||
@@ -70,7 +67,7 @@ class data_controller extends \core_customfield\data_controller {
|
||||
public function instance_form_definition(\MoodleQuickForm $mform) {
|
||||
$field = $this->get_field();
|
||||
$config = $field->get('configdata');
|
||||
$options = field_controller::get_options_array($field);
|
||||
$options = $field->get_options();
|
||||
$formattedoptions = array();
|
||||
$context = $this->get_field()->get_handler()->get_configuration_context();
|
||||
foreach ($options as $key => $option) {
|
||||
@@ -120,7 +117,7 @@ class data_controller extends \core_customfield\data_controller {
|
||||
return null;
|
||||
}
|
||||
|
||||
$options = field_controller::get_options_array($this->get_field());
|
||||
$options = $this->get_field()->get_options();
|
||||
if (array_key_exists($value, $options)) {
|
||||
return format_string($options[$value], true,
|
||||
['context' => $this->get_field()->get_handler()->get_configuration_context()]);
|
||||
|
@@ -60,10 +60,24 @@ class field_controller extends \core_customfield\field_controller {
|
||||
*
|
||||
* @param \core_customfield\field_controller $field
|
||||
* @return array
|
||||
*
|
||||
* @deprecated since Moodle 3.10 - MDL-68569 please use $field->get_options
|
||||
*/
|
||||
public static function get_options_array(\core_customfield\field_controller $field) : array {
|
||||
if ($field->get_configdata_property('options')) {
|
||||
$options = preg_split("/\s*\n\s*/", trim($field->get_configdata_property('options')));
|
||||
debugging('get_options_array() is deprecated, please use $field->get_options() instead', DEBUG_DEVELOPER);
|
||||
|
||||
return $field->get_options();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return configured field options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_options(): array {
|
||||
$optionconfig = $this->get_configdata_property('options');
|
||||
if ($optionconfig) {
|
||||
$options = preg_split("/\s*\n\s*/", trim($optionconfig));
|
||||
} else {
|
||||
$options = array();
|
||||
}
|
||||
@@ -108,7 +122,7 @@ class field_controller extends \core_customfield\field_controller {
|
||||
* @return array
|
||||
*/
|
||||
public function course_grouping_format_values($values): array {
|
||||
$options = self::get_options_array($this);
|
||||
$options = $this->get_options();
|
||||
$ret = [];
|
||||
foreach ($values as $value) {
|
||||
if (isset($options[$value])) {
|
||||
@@ -127,6 +141,6 @@ class field_controller extends \core_customfield\field_controller {
|
||||
* @return int
|
||||
*/
|
||||
public function parse_value(string $value) {
|
||||
return (int) array_search($value, self::get_options_array($this));
|
||||
return (int) array_search($value, $this->get_options());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user