Editing moodle activity-module sources

Editing moodle activity-module sources

by J P -
Number of replies: 5

HI everyone! I'm starting with moodle modules development. I previously developed browser's extensions, so I'm not used to IDES and all its related stuff. I'm just a pure js developer, so I need to ask you some very basic questions.

I was provided with a module that I have to modify and fix some bugs. When I run the module, I got an error at certain point of a .js file in the 'js' folder. So I opened the file with a text editor and added a console.log('hello!') before the line the error is thrown. I'm used to just edit and reload the page, but this time is not working. The log is never shown. Should I do extra steps for updating the code in my local server

Moreover, do you know any step-by-step tutorial for module development? (Better if it is a non-IDE explanation). I found some resourcer in official docs, but all of them just describes the files that should be added, not things like the one I'm asking in this post.

Thanks a lot for your tme,

Average of ratings: -
In reply to J P

Re: Editing moodle activity-module sources

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

If you want to debug javascript use the debugger built into a browser (Chrome or Firefox). However most modules only use javascript for a small amount of functionality so you are likely to need to be able to modify and test php code.

In reply to Marcus Green

Re: Editing moodle activity-module sources

by J P -

Yep, I did it with the Firefox console. But there is no log. Is it enogh by editing the files in the var/www/html/moodle... files and reload the proper page? nothing extra to do for making valid the changes?

In reply to J P

Re: Editing moodle activity-module sources

by Trevor Furtado -
Picture of Plugin developers

You have cleared the cache?

Site Administration > Development > Purge all caches


If you are in a development environment, you should turn off:

Site Administration > Appereance > Ajax and Javascript > Cache Javascript

and turn on:

Site Administration > Appereance > Theme > Theme settings > Theme designer mode

In reply to J P

Re: Editing moodle activity-module sources

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
There are different styles of javascript in Moodle, so it is hard to give general advice about how to refresh the javascript on a site without knowing exactly which bit of code you are looking at (and which Moodle version).

Firstly, always open up config.php and add '$CFG->jsrev = -1;' (without quotes) - this disables much of the caching for javascript (very important on a live site, but gets in the way on a dev site).

Now, you may have a bit of code in a module.js file directly inside a plugin - with jsrev set to -1, you should just be able to edit this and it will be loaded.

You may have some code in a yui subfolder, in which case you have to edit the files in 'yui/src' then run 'shifter' to compile the versions that go in 'yui/build' (the exact file loaded from there depends on whether debugging is on for your site).

You may, with more recent versions of Moodle, have some code in an 'amd' folder - in which case, you should use 'grunt' to compile the code in 'amd/src' into 'amd/bulid' (actually, with debugging on, you can get away with just editing 'amd/src', but it will need to pass through 'grunt' to get it ready for the production site).

Note that for recent versions, grunt will handle both the 'amd' and 'yui' javascript, so you don't need a separate 'shifter' call of your own.

Take a look at: 

https://docs.moodle.org/dev/YUI/Shifter

https://docs.moodle.org/dev/Javascript_Modules


Average of ratings: Useful (2)
In reply to Davo Smith

Re: Editing moodle activity-module sources

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

"Firstly, always open up config.php and add '$CFG->jsrev = -1;' (without quotes) - this disables much of the caching for javascript (very important on a live site, but gets in the way on a dev site)."

Now that is useful to know.