Theme Error Message

Theme Error Message

by Simelweyinkosi Sibindi -
Number of replies: 6

Good day, Please assist. I am getting the below error message on my Moodle when i try to login. I recently changed the theme to the theme called "Adaptable". I am using Version 4 moodle.


Error

Exception - Call to undefined method theme_adaptable\output\core_renderer::firstview_fakeblocks()
Debug info:
Error code: generalexceptionmessage
Stack trace:
  • line 65 of /theme/boost/layout/drawers.php: Error thrown
  • line 1472 of /lib/outputrenderers.php: call to include()
  • line 1398 of /lib/outputrenderers.php: call to core_renderer->render_page_layout()
  • line 86 of /my/courses.php: call to core_renderer->header()

Average of ratings: -
In reply to Simelweyinkosi Sibindi

Re: Theme Error Message

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

Re: Theme Error Message

by Ricardo Moreira -
Hi, Gareth I saw this post because I think I had the same problem but I have some doubts before I mess up even more.
My problem is with the theme Edumy, but the error is the same.
But for example I don't have the file below.

And then here on the file classes/output/core_renderer.php you have like that 
class core_renderer extends \core_renderer {
class core_renderer extends core_renderer_base {
    use core_renderer_toolbox;
}

This means that I delete de core_renderer and add core_rendender_base and the toolbox even if my theme doesn't have that file?
Sorry that seems confused, I am confused myselfsmile



code of a php file
In reply to Ricardo Moreira

Re: Theme Error Message

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

Each theme is written in a given way and one fix for one may not work for another, and so an Adaptable fix may not work on Edumy. You're also reading the patch wrong, thinking that there are two 'class' statements, when in fact the patch is showing the before and after for the same line.

Gareth
In reply to Simelweyinkosi Sibindi

Re: Theme Error Message

by Saroj Sahoo -

Hello Sir ,

Please added this function in core_renderer.php

and i fixed this issue


public function firstview_fakeblocks(): bool {

        global $SESSION;


        $firstview = false;

        if ($this->page->cm) {

            if (!$this->page->blocks->region_has_fakeblocks('side-pre')) {

                return false;

            }

            if (!property_exists($SESSION, 'firstview_fakeblocks')) {

                $SESSION->firstview_fakeblocks = [];

            }

            if (array_key_exists($this->page->cm->id, $SESSION->firstview_fakeblocks)) {

                $firstview = false;

            } else {

                $SESSION->firstview_fakeblocks[$this->page->cm->id] = true;

                $firstview = true;

                if (count($SESSION->firstview_fakeblocks) > 100) {

                    array_shift($SESSION->firstview_fakeblocks);

                }

            }

        }

        return $firstview;

    }


Thanks,

(Edited by Gareth J Barnard - moderation decision - original submission Wednesday, 22 February 2023, 8:04 AM)

In reply to Saroj Sahoo

Re: Theme Error Message

by Jose Fernando Arias -
Hi everyone,
I had the same issue when in my theme based in boost I tried to change the core_render.  I created in my theme a classes/output folder with the new class to modified heading. When purgue chache appeared the same error
theme_themename_core_renderer does not have firstview_fakeblocks funtion. I copied from boost/class/output/core_renderer.php this function and it worked. 
However I am wondering. boost/class/output/core_rendered.php has other functions that i don't have in my new php. is thies man that in advance I will ahve the same issue when moodle ask for those functions?

Somebody knows where I can fond docuemtnation in english or spanish abouth override renders?

Best regards
Jose

In reply to Jose Fernando Arias

Re: Theme Error Message

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

The solution posted by Saroj, whist works, is not really the best solution to the problem and will as you've encountered possibly have issues. The situation here is not so much to do with overriding renderers but understanding OO. Therefore as the 'firstview_flakeblocks' method is defined in Boost's core_renderer, which in turn extends the core core_renderer, then all you need to do is extend the Boost core_renderer rather than the core core_renderer as the Classic core_renderer does, then you won't need the method or indeed copy any of the others and they will be available in your core renderer. There is documentation in the Moodle developer docs somewhere about overriding and overriding renderers - I forget where off the top of my head. So, as a guess you need:

class theme_themename_core_renderer extends \theme_boost\output\core_renderer {
// Only your methods or if they are changed from the parent.
}

Kind regards,

Gareth