General developer forum

Moodle calendar override

 
Picture of Azmat Ullah
Moodle calendar override
 

Hello!


I'm using Moodle 3.4 boost theme and overriding core_calendar_renderer, its shown error "Fatal error: Cannot declare class core_calendar_renderer, because the name is already in use in....." 

Filename : /boost/classes/output/core_calendar_renderer.php

Code:

namespace \theme\boost\output;

include_once($CFG->dirroot . "/calendar/renderer.php");


class core_calendar_renderer extends core_calendar_renderer {

  protected function add_event_button($courseid, $day=null, $month=null, $year=null) {

    return '';

   }

}

 
Average of ratings: -
Picture of Mark Johnson
Re: Moodle calendar override
Core developersParticularly helpful MoodlersPlugin developers

This error is happening for one of two reasons (possibly both):

  1. You've called your class "core_calendar_renderer" which already exists in /calendar/renderer.php, and you can't have two classes with the same name.
  2. Because your class is in a namespace and you've not prefixed the extended class with \, it is trying to extend itself.
Looking at other examples in the boost theme, you probably want to try something like:
class calendar_renderer extends \core_calendar_renderer {
 
Average of ratings: -
Picture of Azmat Ullah
Re: Moodle calendar override
 

Thank you Mark for reply.  I've changed the code showing above but still changes were not showing in calendar which I wants to do.

 
Average of ratings: -
Picture of Azmat Ullah
Re: Moodle calendar override
 

I've changed the code and placement of file but no changes showing on frontend.  I'm trying to remove Add new event button on calendar page.

CODE:

include_once($CFG->dirroot . "/calendar/renderer.php");

class theme_boost_core_calendar_renderer extends core_calendar_renderer {

    public function add_event_button($courseid, $unused1 = null, $unused2 = null, $unused3 = null, $unused4 = null){

        return false;

    }

}

 
Average of ratings: -
Picture of Nitesh Kumar
Re: Moodle calendar override
 

Hi Azmat,

I have tried to override the add_event_button() but it's not overriding but when you override the start_layout() function and go to calendar page you can see that it's working.

class theme_boost_core_calendar_renderer extends core_calendar_renderer {

  public function start_layout(){

        die("just for testing");

        return html_writer::start_tag('div', ['data-region' => 'calendar', 'class' => 'maincalendar']);

    }

}


 
Average of ratings: Useful (1)
Picture of Azmat Ullah
Re: Moodle calendar override
 

Thanks Nitesh.

 
Average of ratings: -