Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_extra_user_fields() has been removed (Moodle 4.3.3) #75

Open
lcassisi opened this issue Apr 4, 2024 · 4 comments
Open

get_extra_user_fields() has been removed (Moodle 4.3.3) #75

lcassisi opened this issue Apr 4, 2024 · 4 comments

Comments

@lcassisi
Copy link

lcassisi commented Apr 4, 2024

Stopped working. Got this error:

Detectado un error de codificación, debe ser corregido por un programador: get_extra_user_fields() has been removed. Please use the \core_user\fields API instead.

@mike-d-howell
Copy link

mike-d-howell commented Apr 23, 2024

Piling on :)

Moodle 4.3.3, mod_certificate build 2016061700 while trying to view a certificate, with debugging turned on:

Stack trace:
line 2774 of /lib/deprecatedlib.php: coding_exception thrown
line 451 of /mod/certificate/locallib.php: call to get_extra_user_fields()
line 106 of /mod/certificate/view.php: call to certificate_get_issues()

EDIT
I modified /mod/certificate/locallib.php following stupidchief's recommendation. I commented out line 451 and added chief's code, and it worked.

Additionally, we saw the same error message with /mod/certificate/report.php. I found a Moodle dev page (https://docs.moodle.org/dev/User_fields) that recommends what to edit, and I made a similar changes:

/mod/certificate/report.php: Comment out line 108 and add:

// Get extra fields to show the user.
// $extrafields = get_extra_user_fields($context);
$extrafields = \core_user\fields::for_identity($context, false)->get_required_fields();

/mod/certificate/report.php: Comment out line 274 and add:

$table->align = array('left');
foreach ($extrafields as $field) {
//    $table->head[] = get_user_field_name($field);
    $table->head[] = \core_user\fields::get_display_name($field);
    $table->align[] = 'left';
}

This seems to work, although I'm not familiar enough with Moodle code to say if all invalid codepaths have been exorcised!

@stupidchief
Copy link

stupidchief commented May 17, 2024

line 451 of /mod/certificate/locallib.php: call to get_extra_user_fields()

I don't know much about moodle so this could be dumb but it worked for me.
I changed the above line to this:

$picturefields = \core_user\fields::for_userpic()->get_required_fields();
$picturefields = preg_filter('/^/', 'u.', $picturefields);
$picturefields = implode(', ', $picturefields);

@onclick-mark
Copy link

onclick-mark commented Jun 19, 2024

Hi - thanks for thew advice above. This has fixed the original issues I was seeing but now when I go to generate a new certificate, I get the below error:

Exception - core_user::get_fullname(): Argument #1 ($user) must be of type stdClass, string given, called in [dirroot]/lib/moodlelib.php on line 3636

Any advice would be massively appreciated. Thanks

@Esheads
Copy link

Esheads commented Jun 19, 2024

Hello everyone.
I have Moodle 4.4.1 and have the same issue. (mod_certificate version: 2020082500 that I have downloaded from here)
While the above methods fixed the original issue (I am truly thankful for that)
I have this now (debugging on - developer mode)
Issue

*Edit: It seems that when removing developer mode debugging the certificates are working correctly (correct name-course and grade). Are the above warnings anything serious?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants