Overriding Mod Assign Renderer - Correctly?

Overriding Mod Assign Renderer - Correctly?

by Anthony Rimmer -
Number of replies: 2

Moodle: 3.5 / Theme: Boost

Hi all,

I'm investigating a method of including standard submission text (regulations, advice on document compression etc.) into the Assignment activity. I understand that I can add this manually per assignment activity or within the integrity statement, but that isn't ideal for what I wish to do.

As it stands, I've managed to override (specifically) the edit submission page with the following code ('theme/boost/renderers.php') - This is taken from 'mod/assign/renderer.php', using the 'Overriding a Renderer' guidance note.


include_once($CFG->dirroot . '/mod/assign/renderer.php');

class theme_boost_mod_assign_renderer extends mod_assign_renderer {
public function render_assign_header(assign_header $header) {
        $o = '';

        if ($header->subpage) {
            $this->page->navbar->add($header->subpage);
        }

        $this->page->set_title(get_string('pluginname', 'assign'));
        $this->page->set_heading($this->page->course->fullname);

        $o .= $this->output->header();
        $heading = format_string($header->assign->name, false, array('context' => $header->context));
        $o .= $this->output->heading($heading);
        if ($header->preface) {
            $o .= $header->preface;
        }

        // Additions
        global $PAGE;

        if($PAGE->pagetype === "mod-assign-editsubmission") {
            $header->postfix = "Common Submission Instructions";
        }
        // Additions End

        if ($header->showintro) {
            $o .= $this->output->box_start('generalbox boxaligncenter', 'intro');
            $o .= format_module_intro('assign', $header->assign, $header->coursemoduleid);
            $o .= $header->postfix;
            $o .= $this->output->box_end();
        }

        return $o;
    }

}

I'm essentially assigning content to the existing postfix property of the header. My question is whether this is a correct method for achieving my goal, and what drawbacks I might encounter.

I have another query open for a different root, which implements a block across a category, and inclusive of all assignments:
https://moodle.org/mod/forum/discuss.php?d=388124

Many thanks,

Anthony

Average of ratings: -
In reply to Anthony Rimmer

Re: Overriding Mod Assign Renderer - Correctly?

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Hi Anthony,

Modifying core code is almost never a good idea as it makes updates error prone due to needing to go and modify the new code. Instead, it probably would be much simpler to use the Generico filter. You create a Generico filter template containing your "standard submission text" and add it to the assignment description. If you ever need to reword the text, you only need to make the changes in one place, the template.

A side benefit is that once you install the Generico filter plugin, there are MANY different templates for it that let you do all sorts of things.

Average of ratings: Useful (2)
In reply to AL Rachels

Re: Overriding Mod Assign Renderer - Correctly?

by Anthony Rimmer -
Hi Al, Thanks for the reply.

Apologies, I maybe didn't clarify that I was overriding with the theme as opposed to changing core code. I could append my content to the output variable without using the $header->postfix property though, which may be a better solution going forward. That would mean that I don't change any of the copied function.

I'm interested in the Generico plugin though, that could be another option, and help with other template content on our site - So thanks for the useful recommendation there.

Anthony