From 7d4db46aa8c8f82f35f32311cee5c581139d2e91 Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Wed, 4 Apr 2007 04:09:47 +0000 Subject: [PATCH] MDL-9136: Added a $selected attribute to the profile_field_menu object, which gets set during initialisation. --- user/profile/field/menu/field.class.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/user/profile/field/menu/field.class.php b/user/profile/field/menu/field.class.php index 9faa510d81..37f37925cd 100644 --- a/user/profile/field/menu/field.class.php +++ b/user/profile/field/menu/field.class.php @@ -2,6 +2,7 @@ class profile_field_menu extends profile_field_base { var $options; + var $selected; function profile_field_menu($fieldid) { //first call parent constructor @@ -10,8 +11,11 @@ class profile_field_menu extends profile_field_base { /// Param 1 for menu type is the options $options = explode("\n", $this->field->param1); $this->options = array(); - foreach($options as $option) { - $this->options[] = format_string($option);//multilang formatting + foreach($options as $key => $option) { + $this->options[$key] = format_string($option);//multilang formatting + if ($option == $this->field->defaultdata) { + $this->selected = $key; + } } } @@ -19,6 +23,7 @@ class profile_field_menu extends profile_field_base { function display_field_add(&$mform) { /// Create the form field $mform->addElement('select', $this->inputname, format_string($this->field->name), $this->options); + $mform->setDefault($this->inputname, $this->selected); } /// Override base class method -- 2.39.5