General developer forum

Making my first plugin (general process?)

 
Picture of Doug Funnie
Making my first plugin (general process?)
 

Hello,

I was wondering what the general process for creating my own plugin should be. I have a few questions in particular that I'm curious about. Is there a way to get a live visualization of what I'm building?

I downloaded the Scheduler plugin awhile back, and I modified it, but I couldn't see the live results of code modifications. I would have to save the document, zip the file, dump it on the server, then 2 - 3 minutes later I would finally be able to see my results. Obviously this is too slow. So my main question is, should I be using the Windows version of Moodle with some way to visualize code being updated live in its proper format?

Thanks.

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Making my first plugin (general process?)
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

You should be able to see the results of your changes immediately. (PHP is a non-compiled language, after all.)

Certainly, zip should not be involved between editing the code and seeing the results.

You should have a server on your local machine (Apache / PHP / MySQL or Postgres). See https://docs.moodle.org/dev/Setting_up_development_environment

 
Average of ratings: -
Picture of Marcus Green
Re: Making my first plugin (general process?)
Core developersParticularly helpful MoodlersPlugin developersTesters

Purge caches regularly

yourmoodle/admin/purgecaches.php

 
Average of ratings: Useful (2)
Picture of Doug Funnie
Re: Making my first plugin (general process?)
 

Ah, this was great advice.

As soon as I hit the Purge all caches button everything was updated. Is there no way to have code auto-update without me having to purge the cache any time I want to see actual changes?

 
Average of ratings: -
Picture of Marcus Green
Re: Making my first plugin (general process?)
Core developersParticularly helpful MoodlersPlugin developersTesters

Not really, purging caches is the moodle dev equivalent of 'Have you tried turning it off an on again'. Annoying but frequently very effective. Don't turn on theme designer mode, that will remove the need to purge caches but it is like being heavily sedated in terms of performance.

 
Average of ratings: -
Picture of Richard Oelmann
Re: Making my first plugin (general process?)
Core developersParticularly helpful MoodlersPlugin developersTesters

If you update the version number in your plugin, then it would reinstall each time - but tbh that can be more intrusive than clicking the purge cache button. I tend to just keep a browser tab open on the purge caches page and then its literally just one click away.

 
Average of ratings: -
Picture of AL Rachels
Re: Making my first plugin (general process?)
Core developersParticularly helpful MoodlersPlugin developersTesters

When working on plugins, I turn on debug messages to Developer, Display debug to Yes, Performance info to Yes, and Show page information to Yes. These settings will include a Purge all caches in each pages footer. Then if I am working on any language string changes, I keep a browser tab open to the Language settings page. When you save a change to any string, all you have to do is click, Save changes, on that page for it to immediately be used by your code.

 
Average of ratings: Useful (4)
Picture of Marcus Green
Re: Making my first plugin (general process?)
Core developersParticularly helpful MoodlersPlugin developersTesters

I have been doing Moodle dev for about 10 years and Al has just made a suggestion that will tweak how I do it. Nobody is ever to old to learn.

 
Average of ratings: -
Picture of Mark Johnson
Re: Making my first plugin (general process?)
Core developersParticularly helpful MoodlersPlugin developers

As of Moodle 3.6 (MDL-61244) there will be an option on the Purge Caches screen to selectively purge the language cache (and a few other specific caches) so you dont have to purge everything or find a specific settings screen if you're just changing a specific type of cached data.

 
Average of ratings: Useful (1)
Picture of Mark Sharp
Re: Making my first plugin (general process?)
Core developersParticularly helpful MoodlersPlugin developers

I've recently started using Microsoft's Visual Studio Code editor, and one of the things I like about it is having embedded Terminal windows. So when I'm developing (especially javascript and css) I have one terminal open for purging the caches and the other with "grunt watch" running to pick up any changes in AMD code.

It's much faster than clicking links in the browser.


 
Average of ratings: -
Picture of Marcus Green
Re: Making my first plugin (general process?)
Core developersParticularly helpful MoodlersPlugin developersTesters

It's support for debugging with xdebug is also very good.

 
Average of ratings: -