Repositioning user defined profile fields

Repositioning user defined profile fields

by Todd Johnson -
Number of replies: 7

Chris,


I have recently upgraded the theme to 1.4.3 and on Moodle 3.1and I have been doing a lot of research on how to modify the User Profile Page, in particular the fields that are displayed in the General Category.  What I would like to do is move a user field from the Other Fields area and place it in the General area.

Other Fields


and place it here.  I can see the source code and do it there as a test.... But unable to located it in the correct either PHP or CSS sheets.  Can you direct me?



Average of ratings: -
In reply to Todd Johnson

Re: Pioneer v1.4.3 Support Discussion

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

Todd,

That wouldn't be controlled by the theme, as you can see by testing in Clean as well.

I believe that would take some editing of core code to be able to insert a user defined field in with the core fields already in place. I'll try and take a look over the next few days if there is a renderer that could help (and be overridden in the theme) but I'm not sure off the top of my head. I suspect it would be quite complex to achieve as different people will (by definition) have their own set of site defined user fields and where they want to put them.

It might though be possible to do it in a bespoke way for a particular single field for a particular single site.

I'd be very interested though if anyone can come up with a better solution as I have been asked this in the past and not come up with anything previously smile

Richard


In reply to Richard Oelmann

Re: Pioneer v1.4.3 Support Discussion

by Todd Johnson -

Thanks Richard for the reply... I have been racking my brain and googling to find a easy solution and there is none that I can find.  You would think this would be just an easy fix.. Even modifying some html like you can under F12 on a browser.  I been trying to locate the source files that controls those blocks and having a hard time locating them....

In reply to Todd Johnson

Positioning User defined profile fields

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

The difficulty is that the html you see in the browser tools, such as firebug, or by looking at the page source from the browser, is actually generated by php. It isn't like a static web page, it has to be able to deal with pulling data from the database (such as the user defined profile fields) as well as the standard fields.

If it was just a case of modifying the html output, as you say that wouldn't be too difficult, you could simply copy the required form element and put it where you need it, but the way dynamic web pages work, being generated from php (in the case of Moodle) makes that a bit more complex.

As I said, it may be possible to do this as a bespoke customisation for a known user defined field going into a known position, I suspect it will be much more complex to create something more generic to allow admins to both define the field (which they can do now) and position it within the existing fields.

Todd, I'm going to move this thread to the general developer forum to see if anyone there has any other suggestions to contribute as it isn't theme related.

Richard

In reply to Todd Johnson

Re: Repositioning user defined profile fields

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Todd,

Have you checked out moodle/user/ directory?

You will find a renderer.php file there as well.

Have fun!

Mary

 

 

In reply to Mary Evans

Re: Repositioning user defined profile fields

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

I have Mary - it was one of the first things I looked at, but I don't think there is anything in the user/renderer.php that would help this. It seems to be limited to printing user files and searching for users. If you can suggest what in there I could use to override, then I will give it a go.

As far as I can see in the user/profile/lib.php the user defined fields are pulled from the database, user_info_field and user_info_data, but I can't see any way to insert that at a given location within the fields from the $user (or user database field) when the profile form is generated.

I believe it comes from user/editadvanced_form.php

        // Shared fields.
        useredit_shared_definition($mform, $editoroptions, $filemanageroptions, $user);

        // Next the customisable profile fields.
        profile_definition($mform, $userid);

which calls the two functions from editlib.php and from user/profile/lib.php respectively.

But as you can see these are self contained functions, one for the 'standard' list of profile fields, the other for the custom categories and fields.

I think - but only from a quick look through the code - that the only way to do this would be to override the class user_editadvanced_form in the editadvanced_form.php and create a single function to call both the standard and custom profile fields.

But as that class is not in a lib file or renderer, that is the point at which I get stuck and don't know how to progress - or if it can be progressed without a core hack.

Any ideas welcomed.

In reply to Richard Oelmann

Re: Repositioning user defined profile fields

by Johan de Bruin -

Hi Richard

I want to do the same, except I have +- 15 hours of Moodle experience sad

Falling back on my JS & css knowledge a ugly hack (but not in Moodle core)  would be to move the items using javascript and css to hide the items you don't want
    but this will show a visible jump of the items and if the names change it will break. smile

Have you had any success?

In reply to Johan de Bruin

Re: Repositioning user defined profile fields

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

None to date, Johan. But realistically this is not something I have been able to (or will be able to) spend much time on over the next few weeks, but may get to look at later in the summer.