From: ikawhero Date: Tue, 6 Jan 2009 07:31:26 +0000 (+0000) Subject: MDL-17791 Can make a link from user data when adding a new custom user X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=410fc5a24d714ba28dcca0bd714a04833e6ebb4e;p=moodle.git MDL-17791 Can make a link from user data when adding a new custom user profile text field --- diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php index 96d44d9d44..93efdcd317 100644 --- a/lang/en_utf8/admin.php +++ b/lang/en_utf8/admin.php @@ -430,6 +430,7 @@ $string['guestroleid'] = 'Role for guest'; $string['helpadminseesall'] = 'Do admins see all calendar events or just those that apply to themselves?'; $string['helpcalendarsettings'] = 'Configure various calendar and date/time-related aspects of Moodle'; $string['helpforcetimezone'] = 'You can allow users to individually select their timezone, or force a timezone for everyone.'; +$string['helpprofilefieldlink'] = 'Create a link from the user data'; $string['helpsitemaintenance'] = 'For upgrades and other work'; $string['helpstartofweek'] = 'Which day starts the week in the calendar?'; $string['helpupcominglookahead'] = 'How many days in the future does the calendar look for upcoming events by default?'; @@ -620,6 +621,8 @@ $string['profileeditcategory'] = 'Editing category: $a'; $string['profileeditfield'] = 'Editing profile field: $a'; $string['profilefield'] = 'Profile Field'; $string['profilefieldcolumns'] = 'Columns'; +$string['profilefieldlink'] = 'Link'; +$string['profilefieldlinktarget'] = 'Link target'; $string['profilefieldrows'] = 'Rows'; $string['profilefields'] = 'User profile fields'; $string['profilefieldsize'] = 'Display size'; diff --git a/user/profile/field/text/define.class.php b/user/profile/field/text/define.class.php index 74d20770dd..876311c298 100644 --- a/user/profile/field/text/define.class.php +++ b/user/profile/field/text/define.class.php @@ -21,6 +21,20 @@ class profile_define_text extends profile_define_base { $form->addElement('selectyesno', 'param3', get_string('profilefieldispassword', 'admin')); $form->setDefault('param3', 0); // defaults to 'no' $form->setType('param3', PARAM_INT); + + /// Param 4 for text type contains a link + $form->addElement('text', 'param4', get_string('profilefieldlink', 'admin')); + $form->setType('param4', PARAM_URL); + $form->setHelpButton('param4', array('profilefieldlink', get_string('helpprofilefieldlink', 'admin'))); + + /// Param 5 for text type contains link target + $targetoptions = array( '' => get_string('linktargetnone', 'editor'), + '_blank' => get_string('linktargetblank', 'editor'), + '_self' => get_string('linktargetself', 'editor'), + '_top' => get_string('linktargettop', 'editor') + ); + $form->addElement('select', 'param5', get_string('profilefieldlinktarget', 'admin'), $targetoptions); + $form->setType('param5', PARAM_RAW); } } diff --git a/user/profile/field/text/field.class.php b/user/profile/field/text/field.class.php index 2c0ae1a45a..5506b6e169 100644 --- a/user/profile/field/text/field.class.php +++ b/user/profile/field/text/field.class.php @@ -2,6 +2,30 @@ class profile_field_text extends profile_field_base { + /** + * Overwrite the base class to display the data for this field + */ + function display_data() { + /// Default formatting + $data = parent::display_data(); + + /// Are we creating a link? + if (!empty($this->field->param4) and !empty($data)) { + + /// Define the target + if (! empty($this->field->param5)) { + $target = 'target="'.$this->field->param5.'"'; + } else { + $target = ''; + } + + /// Create the link + $data = ''.htmlspecialchars($data).''; + } + + return $data; + } + function edit_field_add(&$mform) { $size = $this->field->param1; $maxlength = $this->field->param2;