]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17791 Can make a link from user data when adding a new custom user
authorikawhero <ikawhero>
Tue, 6 Jan 2009 07:31:26 +0000 (07:31 +0000)
committerikawhero <ikawhero>
Tue, 6 Jan 2009 07:31:26 +0000 (07:31 +0000)
profile text field

lang/en_utf8/admin.php
user/profile/field/text/define.class.php
user/profile/field/text/field.class.php

index 96d44d9d44fedccc296eb0ac7f7ddc59e3e6918d..93efdcd317d3ce321fe5820e1baa8da782dc8b07 100644 (file)
@@ -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';
index 74d20770ddadd2b6581d0bc8a5029214eb9b77fa..876311c29871131560e952b4d6e7bf1286850293 100644 (file)
@@ -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);
     }
 
 }
index 2c0ae1a45a8c38238e0d3d2aaa5226e2130bf3d4..5506b6e169e86edf966ca6996c6073cebb751390 100644 (file)
@@ -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 = '<a href="'.str_replace('$$', urlencode($data), $this->field->param4).'" '.$target.'>'.htmlspecialchars($data).'</a>';
+        }
+
+        return $data;
+    }
+
     function edit_field_add(&$mform) {
         $size = $this->field->param1;
         $maxlength = $this->field->param2;