mod_assign Grader overriding in a theme.

mod_assign Grader overriding in a theme.

by Gareth J Barnard -
Number of replies: 4
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hello,

As the new Grader in M3.1 is lacking in navigation bar obscure course link I want to improve it by overriding grading_app.php in /mod/assign/classes/output - I've managed to have the template overridden in the theme, but for the life of me cannot get the autoloading to pick up and use my replacement 'grading_app' class:

namespace theme_essential\output;
use renderer_base;
class grading_app extends \mod_assign\output\grading_app {
    /**
     * Export this class data as a flat list for rendering in a template.
     *
     * @param renderer_base $output The current page renderer.
     * @return stdClass - Flat list of exported data.
     */
    public function export_for_template(renderer_base $output) {
error_log('Overridden');
        $export = parent::export_for_template($output);
        return $export;
    }
}

Which is in /theme/essential/classes/output/grading_app.php.  The 'error_log' statement is just there as proof that its being used before I spend time writing code.

I've already read:

And https://docs.moodle.org/dev/Templates#How_to_I_override_a_template_in_my_theme.3F says nothing about the 'data' side of the template overriding process.

Does anybody have any idea what I'm doing wrong please?

Thanks,

Gareth

Average of ratings: -
In reply to Gareth J Barnard

Re: mod_assign Grader overriding in a theme.

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

If its any help Gareth, the user profile renderer class that you helped me solve a while back ended up as

namespace theme_themename\output\core_user\myprofile;
use \core_user\output\myprofile\category;

defined('MOODLE_INTERNAL') || die();
class renderer extends \core_user\output\myprofile\renderer {

which sits in themename\classes\output\core_user\myprofile\renderer.php

I think from the reading you've done (and I did back then) there are several ways to accomplish this, but that is what worked for me

Richard

In reply to Richard Oelmann

Re: mod_assign Grader overriding in a theme.

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

Thanks for your reply Richard.

As the file is in the /mod/assign/classes/output folder, I tried 'namespace theme_essential\output\mod_assign;' with the file in the same place but did not work - 'Purge all caches' etc.

Humm!  Perhaps a web-server restart..... nope! Humm!

In reply to Gareth J Barnard

Re: mod_assign Grader overriding in a theme.

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

Looking at MDL-41663 - I think there could be an issue with naming not being postfixed with '_renderable' in the filename - could be a core bug.

And indeed the line 'use \mod_assign\output\grading_app;' in /mod/assign/renderer.php preventing that class from being overridden.

In reply to Gareth J Barnard

Re: mod_assign Grader overriding in a theme.

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

Bingo!  Another solution using older method in the theme's 'classes' folder:

use \mod_assign\output\grading_app;
class theme_essential_mod_assign_renderer extends mod_assign_renderer {
    /**
     * Defer to template..
     *
     * @param grading_app $app - All the data to render the grading app.
     */
    public function render_grading_app(grading_app $app) {
        $context = $app->export_for_template($this);
error_log('Overridden');
        return $this->render_from_template('mod_assign/grading_app', $context);
    }
}
Average of ratings: Useful (1)