Making my first plugin (general process?)

Making my first plugin (general process?)

by Doug Funnie -
Number of replies: 10

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: -
In reply to Doug Funnie

Re: Making my first plugin (general process?)

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin 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

In reply to Tim Hunt

Re: Making my first plugin (general process?)

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

Purge caches regularly

yourmoodle/admin/purgecaches.php

Average of ratings: Useful (2)
In reply to Marcus Green

Re: Making my first plugin (general process?)

by Doug Funnie -

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?

In reply to Doug Funnie

Re: Making my first plugin (general process?)

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

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.

In reply to Doug Funnie

Re: Making my first plugin (general process?)

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

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.

In reply to Richard Oelmann

Re: Making my first plugin (general process?)

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

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 (5)
In reply to AL Rachels

Re: Making my first plugin (general process?)

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

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: Useful (1)
In reply to AL Rachels

Re: Making my first plugin (general process?)

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin 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 (2)
In reply to Doug Funnie

Re: Making my first plugin (general process?)

by Mark Sharp -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin 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.

Attachment development-environment.png
Average of ratings: Useful (1)
In reply to Mark Sharp

Re: Making my first plugin (general process?)

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

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

Average of ratings: Useful (1)