MDL-17791 Can make a link from user data when adding a new custom user
profile text field
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user