joomla plugin & module develpment - presented at sydney jug 09/04/2013

25
Joomla Plugin & Module Develpment Tim Plummer http://twitter.com/ bfsurvey Presented at Sydney JUG 09/04/2013

Upload: tim-plummer

Post on 10-May-2015

2.610 views

Category:

Technology


4 download

DESCRIPTION

This is an introduction to plugin and module extension development for Joomla 3. It was presented at Sydney JUG in April 2013, and was accompanied with some live demos of a simple content plugin and simple module. If you want the source code from the live demos, feel free to get in touch with me.

TRANSCRIPT

Page 1: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

Joomla Plugin & Module Develpment

Tim Plummerhttp://twitter.com/bfsurvey

Presented at Sydney JUG 09/04/2013

Page 2: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

What is a plugin?

Page 3: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

What is a module?

Page 4: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

Tools you need

• Web Server & PHP & MySQL (XAMPP)

• Text editor or IDE (Textpad / Notepad++ or Eclipse / Netbeans)

• Web browser (Firefox with firebug)

Page 5: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

Getting started with plugins

• Can be as simple as two files– yourplugin.xml– yourplugin.php

• Located in /plugins/plugintype/yourplugin• Triggered by events

Page 6: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

Installation XML (aka manifest)

• yourplugin.xml file located in your plugin folder

• Used when installing your plugin – tells Joomla all the files used, and the type of plugin it is.

• Contains information about the plugin, such as it’s name, author, version number etc.

• Has all the parameters (aka options)

Page 7: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

Entry point

• yourplugin.php file located in your plugin folder

• This code is executed when the plugin runs, and can call other files.

• Does all the hard work

Page 8: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

Types of plugins

• Authentication• Captcha• Content• Editors• Editors-XTD• Extension

• Quick Icon• Search• Smart Search (finder)• User• System

Page 9: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

Plugin Event Triggers

• Authentication– onUserAuthenticate– onUserAuthorisationFailure

• Captcha– onCheckAnswer– onDisplay– onInit

• Content– onContentAfterDelete– onContentAfterDisplay– onContentAfterSave– onContentAfterTitle– onContentBeforeDelete– onContentBeforeDisplay– onContentBeforeSave– onContentChangeState– onContentPrepare– onContentPrepareData– onContentPrepareForm– onContentSearch– onContentSearchAreas

Page 10: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

Plugin Event Triggers…cont

• Editors– onDisplay– onGetContent– onGetInsertMethod– onInit– onSave– onSetContent

• Editors-XTD– onDisplay

• Extension– onExtensionAfterInstall– onExtensionAfterSave– onExtensionAfterUninstall– onExtensionAfterUpdate– onExtensionBeforeInstall– onExtensionBeforeSave– onExtensionBeforeUninst

all– onExtensionBeforeUpdate

Page 11: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

Plugin Event Triggers…cont

• Quick Icon– onGetIcons

• Search– onContentSearchAreas– onContentSearch

• Smart Search– onFinderAfterDelete– onFinderAfterSave– onFinderBeforeSave– onFinderCategoryChangeState– onFinderChangeState

• System– onAfterDispatch– onAfterInitialise– onAfterRender– onAfterRoute

• User– onUserAfterDelete– onUserAfterSave– onUserBeforeDelete– onUserBeforeSave– onUserLogin– onUserLogout

Page 12: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

plg_content_joomlarocks

• Hello World sucks, so instead tonight we are going to create a plugin called plg_content_joomlarocks

• This plugin will find all the “Joomla!” text in articles and replace it with “Joomla Rocks” and turn this into a link that goes to www.joomla.org

Page 13: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

Set Error Reporting to Maximum

Only do

this on a

dev site

Page 14: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

Demo time…

Page 15: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

Getting Started with modules

• Slightly more complex than plugins, but still way simpler than components.

• Can be as little as three files (but usually 4+)– mod_yourmodule.xml– mod_yourmodule.php– helper.php– /tmpl/default.php

Page 16: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

Types of modules

• Two types– Frontend Module (aka site)• /modules/yourmodule

– Backend Module (aka administrator)• /administrator/modules/yourmodule

Page 17: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

Installation XML (aka manifest)

• mod_yourmodule.xml file located in your module folder

• Used when installing your module – tells Joomla all the files used, and the type of module it is.

• Contains information about the module, such as it’s name, author, version number etc.

• Has all the parameters (aka options)

Page 18: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

Entry Point

• mod_yourmodule.php file located in your module folder

• This code is executed when the plugin runs, and can call other files.

• Is lazy and makes the helper and view do all the work.

Page 19: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

Helper

• helper.php file located in module folder• Talks to the database and prepares data for

the view.

Page 20: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

The View• Located in /tmpl/default.php in the module

folder• Presents the data to the user• Doesn’t know where the data came from or

how it is stored and doesn’t care (as Sargent Schultz would say, I know nothing!).

Page 21: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

mod_random_article

• Tonight we are going to create an article mod_random_article

• This will randomly select an article and show the title with a link.

Page 22: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

Demo time…

Page 23: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

Now you are ready to start creating your own plugins and modules

Page 24: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

Questions?

Page 25: Joomla plugin & module develpment - Presented at Sydney JUG 09/04/2013

Tim Plummer@bfsurvey

[email protected]