Using larger profile image in forums

Using larger profile image in forums

by Jez H -
Number of replies: 31
Hi All,

Moodle uses the smaller "f2" profile image in forum posts.
I would like to use the larger "f1" but have not found a theme that does this.

I know it can be done because here on Moodle.Org the larger "f1" will be rendered when I make this post:

https://moodle.org/pluginfile.php/63803/user/icon/moodleorgcleaned_moodleorg/f1?rev=1382365

But by default Moodle renders the smaller "F2":

https://moodle.org/pluginfile.php/63803/user/icon/moodleorgcleaned_moodleorg/f2?rev=1382365

I thought this would simply be a matter of overriding a renderer in /mod/forum, but there isnt a renderer there for fetching the profile image.

Does anyone know how to get a theme to rendeer larger profile images in forums?
Average of ratings: -
In reply to Jez H

Re: Using larger profile image in forums

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Down to this line: https://github.com/moodle/moodle/blob/MOODLE_30_STABLE/mod/forum/lib.php#L3279 - I'm sure you can figure out the rest by what it implies.

In reply to Gareth J Barnard

Re: Using larger profile image in forums

by Jez H -

Thanks Gareth,

What that implies to me is it cannot be overidden and would require a core mod to that lib file?
In reply to Jez H

Re: Using larger profile image in forums

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi Jez,

The $OUTPUT global is an instance of the core_renderer.  This can be overridden in a theme.....

Cheers,

Gareth

In reply to Gareth J Barnard

Re: Using larger profile image in forums

by Jez H -

Hi Gareth,

Thanks for your help but I am still not clear on what you are suggesting, ok you werent suggesting anything but trying to give me a steer smile

Never the less if you have a moment to sanity check the following it would be appreciated.

The line you gave is a call to the renderer sat in the middle of mass of code in a lib file and to my knowledge cannot be overridden?

The core renderer that is calling already accepts an argument for the image size, but I cannot override the call.

I could override the core renderer and within the function code try to determine whether we are in a forum and if so set the option there but its a bit of a botch, unless you have an alternative suggestion?

Its a shame that call was not moved to the forum renderer instead of being stuck in lib.

In reply to Jez H

Re: Using larger profile image in forums

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

"The line you gave is a call to the renderer sat in the middle of mass of code in a lib file and to my knowledge cannot be overridden?" = true.

"The core renderer that is calling already accepts an argument for the image size, but I cannot override the call." = oh yes you can.

"I could override the core renderer and within the function code try to determine whether we are in a forum and if so set the option there but its a bit of a botch, unless you have an alternative suggestion?" = easy = ($this->page->pagetype == 'mod-forum-discuss')

"Its a shame that call was not moved to the forum renderer instead of being stuck in lib." = true, but moving from a functional model to an OO one takes time.

In reply to Gareth J Barnard

Re: Using larger profile image in forums

by Jez H -

That wont work either, I can override the renderer as it is called in the theme but dont think I can do so for call made in mod/forum ?

By that I mean if I override user_picture in the theme then any calls made by the theme will be overidden, but calls made from the forum will not.

In reply to Jez H

Re: Using larger profile image in forums

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

RE: "That wont work either, I can override the renderer as it is called in the theme but dont think I can do so for call made in mod/forum ?" = $OUTPUT is an instance of the theme's overridden 'core' renderer.  Think about it!

In reply to Gareth J Barnard

Re: Using larger profile image in forums

by Jez H -

Sorry if I am being slow on the uptake here but if /mod/forum/lib.php calls a core renderer which is not overridden it in /mod/forum/renderers.php why would it apply an override in /theme/themename/renderer.php as opposed to core?

To put it another way how is the call in /mod/forum/lib.php an instance of the themes overriden renderer, surely its an instance of the core renderer not the themes?

Do overrides in themes take precedence over the renderers or lack of them in /mod/?

In reply to Jez H

Re: Using larger profile image in forums

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Core code is written as such that the instance pointed to by the $OUTPUT global variable is an instance of the overridden core_renderer class in the theme if it is declared there.  Therefore 'everything' that uses $OUTPUT will call an overridden method in the theme if it has been overridden.

renderer.php in the forum is not in the class hierarchy as core_renderer, it is another renderer.

Average of ratings: Useful (1)
In reply to Gareth J Barnard

Re: Using larger profile image in forums

by Jez H -

Thanks very much for explaining that, a big help.

In reply to Jez H

Re: Using larger profile image in forums

by Mary Evans -
In reply to Mary Evans

Re: Using larger profile image in forums

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
In reply to Gareth J Barnard

Re: Using larger profile image in forums

by Mary Evans -
In reply to Mary Evans

Re: Using larger profile image in forums

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
In reply to Gareth J Barnard

Re: Using larger profile image in forums

by David Scotson -

I've often wondered whether it makes sense to just force all the profile images to the f1 size.

In the Snap theme we want to emphasis the user images, and once you've got the large user image cached from viewing the forum, it perhaps doesn't make sense to then load a small copy when looking at another page. You trade off loading the larger image by default, with not having to load two different ones.

(A recent-ish change to use jpg for user images made this decision easier, as it reduced the file size of the larger user images)
In reply to David Scotson

Re: Using larger profile image in forums

by Jez H -

I think larger images would be better, connection speeds are a lot faster than they once were and in countries where that is not the case is the bw consumed is going to be significant compared with document upload / download?

In reply to Gareth J Barnard

Re: Using larger profile image in forums

by Mary Evans -

Cool beans!

Copyrighted I hope?

LOL

Mary

In reply to Mary Evans

Re: Using larger profile image in forums

by Jez H -

Thanks Mary,

I was looking at that having noticed the "theme developers do not override" in the other method, but have not been able to get this working. Will give it another go this evening.

In reply to Jez H

Re: Using larger profile image in forums

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi Jez,

Umm (https://moodle.org/mod/forum/discuss.php?d=327064#p1315251)....

    protected function render_user_picture(user_picture $userpicture) {
        if ($this->page->pagetype == 'mod-forum-discuss') {
            $userpicture->size = 1;
        }
        return parent::render_user_picture($userpicture);
    }

Cheers,

G

Average of ratings: Useful (1)
In reply to Gareth J Barnard

Re: Using larger profile image in forums

by Mary Evans -

Hi Gareth,

I think this is a case of..."You can take a horse to water but you can't make it drink..."

Cheers

Mary

In reply to Mary Evans

Re: Using larger profile image in forums

by Jez H -

Aside from missing Gareths snippet it was a case of putting the override under the wrong class and being perplexed as to why it wasnt working rather than not listenting to what you were trying to tell me.

Thanks for your help with this.

In reply to Jez H

Re: Using larger profile image in forums

by Mary Evans -

Hi Jez,

Sorry, I just thought it a little bit funny as Gareth was trying to point you in the right direction but you kept missing the signposts.

Cheers

Mary

In reply to Gareth J Barnard

Re: Using larger profile image in forums

by Jez H -

Hi Gareth,

Thanks very much for that, I did not have chance to go through all those links earlier and missed the significance of that one.

In reply to Gareth J Barnard

Re: Using larger profile image in forums

by Jez H -

Right I got that working in the end, no thanks to a muddled renderers.php which I need to re organise sad

Many thanks for bearing with me, I have a lot to learn about renderers.

In reply to Jez H

Re: Using larger profile image in forums

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

I'm glad you got it working in the end Jez.  I've learnt most of what I know about Moodle Themes through trial and error.  Mostly error ;)

& thanks Mary smile

In reply to Gareth J Barnard

Re: Using larger profile image in forums

by Jez H -

One of the reasons it took me so long is our renderers.php is a mess and I was putting overrides under the wrong class blush

I notice essential breaks down the renderers in a nice orderly fashion. I am not at a point where I want to do that but had wondered if custom renderers for the theme need to go under:


class theme_themename_core_renderer extends core_renderer


Or whether you can add your own classes to split out custom renderers but still have them called by $OUTPUT, possibly by extending the above class?

In reply to Jez H

Re: Using larger profile image in forums

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

I think they do need to go in a class that extends the renderer they are originally from Jez (core_renderer, course_renderer, etc) and you can only extend that renderer class in one place as far as I am aware (Gareth may correct that as I continue learning more about renderers every day! smile )

There is though the move towards the namespaced renderers such as the one here

https://github.com/roelmann/moodle-theme_flexibase/blob/master/classes/output/core_user/myprofile/renderer.php#L17-L21

And the fun I had with Gareth's and Mary's support as we tried to work out what the correct namespace and folder/file structure for it was for this newer way of adding classes smile It does make sense - it was just, I think, new to all three of us and the documentation wasn't 100% clear.

Hopefully, as we move towards that (and templates???) we'll eventually get a consistent way of doing things and it will result in better code that can be organised on the theme overrides in a logical way smile

Richard

Average of ratings: Useful (1)
In reply to Richard Oelmann

Re: Using larger profile image in forums

by Jez H -

"I think they do need to go in a class that extends the renderer they are originally from"

I am talking about my own functions which are not originally from core but are all sat all under the core_renderer class.

In reply to Jez H

Re: Using larger profile image in forums

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

If you add your own methods to your class that extends the 'core_renderer' then you'll be able to call them with the $OUTPUT global when it is set to an instance of your class.  This is because of the 'theme_overridden_renderer_factory' you define here: https://github.com/gjb2048/moodle-theme_essential/blob/master/config.php#L199.

Ultimately this is just bog standard OO concepts.

The other renderer files that Essential defines here: https://github.com/gjb2048/moodle-theme_essential/tree/master/classes for the most part override other core renderers.  This works because of class autoloading (look it up in the Moodle dev docs please).  The toolbox is a bespoke class to be used (and autoloaded for speed / cache reasons explained in the Moodle docs) by the other classes / code - keeps things tidy.  Namespaces are another thing.

The other thing I've done is used 'traits' (https://github.com/gjb2048/moodle-theme_essential/blob/master/classes/output/core_renderer_toolbox.php#L27) such that common methods used by both the core and core maintenance renderers can be defined once and used without bumping into multiple inheritance.  Which I've only used a few times in C++.  PHP has 'traits' with implemented methods.  Java has interfaces where the specific class decides how the method is implemented using the same name.  This all helps to be able to iterate over objects of different specialised classes from a common parent, call the same method name but get different results based upon what object has been instantiated.  All this helps to have a 'define once - use many' strategy to prevent copy / paste bugs when maintaining the same code in different places because there is no duplication.

So...

New methods can go anywhere you think are suitable and the surrounding code could get access to.  Even in a new renderer with this sort of call: https://github.com/gjb2048/moodle-theme_essential/blob/master/lib.php#L145.  But if you are overriding core methods then clearly they need to go in a class that extends that core class.

In reply to Jez H

Re: Using larger profile image in forums

by Mary Evans -

MDL-50839 may help too. This explains how to override a renderer.

You could try to fool your Moodle site into using a larger image by saving it into your theme as...

moodle/theme/yourthemename/pix_core/u /f2.jpg

avator

In reply to Mary Evans

Re: Using larger profile image in forums

by Jez H -

Thanks Mary,

It was not the default image I wanted to change but the actual user profile image.

When you upload a profile image to Moodle it crops (to square) and saves the image in different sizes.

If you look at the links in my original post they both link to my profile image here on Moodle.org, and as you will see there are two image sizes.

By default Moodle uses the smaller "f2" image, I would like to use "f1" so that user profile images can be displayed at a larger size in forums withuot blurring which is what happens if you simply display the smaller f2 image at a larger size.