General developer forum

How to edit core files with plugins?

 
Picture of Hossam Ahmed
How to edit core files with plugins?
 

Hello,


I was trying to make some features inside my version of Moodle but that requires to alter or edit the core files or add new functions to the core files and for sure if I tried to upgrade my version all edits will be gone so I was trying to create a plugin for this edits but couldn't find any how to do it .. and most of the documents for older version .. so my question now is how to modify core files with a plugin?


Thanks

 
Average of ratings: -
Picture of Richard Oelmann
Re: How to edit core files with plugins?
Core developersParticularly helpful MoodlersPlugin developersTesters

Well, that very much depends on what you are trying to do:

You could create a plugin that clones a function and edit that

You could create a renderer override within your theme

Without knowing what you are actually trying to do, its impossible to say.

 
Average of ratings: -
Picture of Hossam Ahmed
Re: How to edit core files with plugins?
 

I was trying to add a drop down menu in "calendar/view.php" to create a new event from this menu. So I edited the view.php and added this lines



$html = html_writer::start_tag('form', array('action' => new moodle_url('/calendar/event.php'), 'method' => 'post'));

        $html .= html_writer::start_tag('div', array('style' => 'float:left;'));

          $html .= html_writer::select(array('Year_Start_'.date("Y")."/".date("Y", strtotime("+1 year")) => 'Year Start '.date("Y")."/".date("Y", strtotime("+1 year")),'Year_End_'.date("Y")."/".date("Y", strtotime("+1 year")) => 'Year End '.date("Y")."/".date("Y", strtotime("+1 year")), 'First_Term_Start_'.date("Y")."/".date("Y", strtotime("+1 year")) => 'First Term Start '.date("Y")."/".date("Y", strtotime("+1 year")),'First_Term_End_'.date("Y")."/".date("Y", strtotime("+1 year")) => 'First Term End '.date("Y")."/".date("Y", strtotime("+1 year")),'First_Term_Break_'.date("Y")."/".date("Y", strtotime("+1 year")) => 'First Term Break '.date("Y")."/".date("Y", strtotime("+1 year")), 'Second_Term_Start_'.date("Y")."/".date("Y", strtotime("+1 year")) => 'Second Term Start '.date("Y")."/".date("Y", strtotime("+1 year")),  'Second_Term_End_'.date("Y")."/".date("Y", strtotime("+1 year")) => 'Second Term End '.date("Y")."/".date("Y", strtotime("+1 year")),'Second_Term_Break_'.date("Y")."/".date("Y", strtotime("+1 year")) => 'Second Term Break '.date("Y")."/".date("Y", strtotime("+1 year"))), 'chooseevent');

           // $html .= html_writer::addElement('select', 'eventtype', get_string('eventkind', 'calendar'), $options);


           // $html .= html_writer::tag('option', 'firstterm', 'First Term');

            $html .= html_writer::tag('button','New Event',array('type'  => 'submit','name' => 'action','class' => 'btn btn-secondary','value' => 'submit'));

           

            $html .= html_writer::end_tag('div');


        $html .= html_writer::end_tag('form');



        return $html;



but for sure at the next update i'd lose all that codes so I'm trying to make a plugin that do the same job.

 
Average of ratings: -
Picture of Raad Al-Rawi
Re: How to edit core files with plugins?
 

Hi Hossam


If you have used git to deploy your Moodle code (git clone + git checkout), then once you have made the changes you need, you can get git to generate a patch file:

git diff changedfile.php > changed.patch

You can then save the patch file somewhere and re-apply it using "patch" if you refresh or upgrade your Moodle codebase.

We use that approach and store patch files in a directory structure that mirrors the Moodle codebase, and I have a custom bash script that works it's way through the structure, picks up the patch files and applies them.

Hope that helps - let me know if you need any more info.


Cheers

Raad

 
Average of ratings: -