mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-74500 user: method to determine whether to show profile fields.
The new API replaces identical behaviour in existing calling code, but allows for profile field types to override/separate the logic used to show the field and determine whether it's empty
This commit is contained in:
parent
f30110b5eb
commit
0ac237d542
@ -333,7 +333,7 @@ function core_myprofile_navigation(core_user\output\myprofile\tree $tree, $user,
|
||||
$categories = profile_get_user_fields_with_data_by_category($user->id);
|
||||
foreach ($categories as $categoryid => $fields) {
|
||||
foreach ($fields as $formfield) {
|
||||
if ($formfield->is_visible() and !$formfield->is_empty()) {
|
||||
if ($formfield->show_field_content()) {
|
||||
$node = new core_user\output\myprofile\node('contact', 'custom_field_' . $formfield->field->shortname,
|
||||
format_string($formfield->field->name), null, null, $formfield->display_data());
|
||||
$tree->add_node($node);
|
||||
|
@ -399,8 +399,7 @@ function user_get_user_details($user, $course = null, array $userfields = array(
|
||||
$userdetails['customfields'] = array();
|
||||
foreach ($categories as $categoryid => $fields) {
|
||||
foreach ($fields as $formfield) {
|
||||
if ($formfield->is_visible() and !$formfield->is_empty()) {
|
||||
|
||||
if ($formfield->show_field_content()) {
|
||||
$userdetails['customfields'][] = [
|
||||
'name' => $formfield->field->name,
|
||||
'value' => $formfield->data,
|
||||
|
@ -587,6 +587,16 @@ class profile_field_base {
|
||||
return array(PARAM_RAW, NULL_NOT_ALLOWED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to display the field and content to the user
|
||||
*
|
||||
* @param context|null $context
|
||||
* @return bool
|
||||
*/
|
||||
public function show_field_content(?context $context = null): bool {
|
||||
return $this->is_visible($context) && !$this->is_empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the field should convert the raw data into user-friendly data when exporting
|
||||
*
|
||||
|
@ -1,5 +1,10 @@
|
||||
This files describes API changes for code that uses the user API.
|
||||
|
||||
=== 4.4 ===
|
||||
|
||||
* The `profile_field_base` class now contains a `show_field_content` method to determine whether the field and
|
||||
content should be shown to the user. Can be overridden in child classes as required
|
||||
|
||||
=== 4.3 ===
|
||||
|
||||
* Added new methods:
|
||||
|
Loading…
x
Reference in New Issue
Block a user