Skip to content

Commit

Permalink
{profile_field_shortname} now supports textarea type custom fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-milette committed Nov 8, 2020
1 parent 2771d2a commit 7da63d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ All notable changes to this project will be documented in this file.
- FAQ: Information on how to patch Moodle to enable FilterCodes in the custom menu.
- FAQ: Search the README.md file for the word Troubleshooting to now find helpful information.
- Fixed {diskfreespace} and {diskfreespacedata} on very large/unlimited storage. Note: Greater than about 84,703.29 Yottabyte (YB) is now considered infinite.
- {profile_field_shortname} now supports textarea type custom fields.

## [2.0.0] 2020-07-01
### Added
Expand Down
22 changes: 13 additions & 9 deletions filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,19 +427,23 @@ public function filter($text, array $options = []) {
// Custom Profile Fields.
if (stripos($text, '{profile_field') !== false) {
if (isloggedin() && !isguestuser()) {
// Cached the visibity status of all the defined custom profile fields.
// Cached the defined custom profile fields and data.
static $profilefields;
static $profiledata;
if (!isset($profilefields)) {
$profilefields = $DB->get_records('user_info_field', null, '', 'shortname, visible');
$profilefields = $DB->get_records('user_info_field', null, '', 'id, shortname, visible');
if (!empty($profilefields)) {
$profiledata = $DB->get_records_menu('user_info_data', ['userid' => $USER->id], '', 'fieldid, data');
}
}
foreach ($USER->profile as $field => $value) {
$shortname = strtolower($field);
// If the tag exists and it is not hidden in the custom profile field's settings.
if (stripos($text, '{profile_field_' . $shortname . '}') !== false
&& $profilefields[$field]->visible != '0') {
$replace['/\{profile_field_' . $shortname . '\}/i'] = $value;

foreach ($profilefields as $field) {
// If the tag exists and is not set to "Not visible" in the custom profile field's settings.
if (stripos($text, '{profile_field_' . $field->shortname . '}') !== false && $field->visible != '0') {
$data = !empty($profiledata[$field->id]) ? $profiledata[$field->id] : '';
$replace['/\{profile_field_' . $field->shortname . '\}/i'] = $data;
} else {
$replace['/\{profile_field_' . $shortname . '\}/i'] = '';
$replace['/\{profile_field_' . $field->shortname . '\}/i'] = '';
}
}
}
Expand Down

0 comments on commit 7da63d5

Please sign in to comment.