Presentation given by Jisse Reitsma during Joomla World Conference 2014 in Cancun, on how to write a Joomla Content Plugin that allows you to add or modify existing Joomla Forms.
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
EXTEND JOOMLA FORMS
1. Extend Joomla Forms
Using Plugins
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
2. My name is Jisse Reitsma
Developer
Owner of Yireo
Joomla! & Magento
Extensions & services
Tutorials & blogs
Sponsoring JWC2014
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
3. Plugins I wrote
Language Domains
Auto Login IP
Demo Site
Fancybox
HTTP Authenticatie
New Relic
Piwik
WebP
ScriptMerge
SEF Test
SSL Redirection
Static Content
Trademark
32+ MageBridge plugins
10+ SimpleLists plugins
8+ Dynamic404 plugins
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
4. Book release in November 2014
English
368 pages
Available through:
Yireo Shop (Europe)
Amazon (US & world wide)
#deadtreeformat (no ebook)
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
5. Extend Joomla Forms Using Plugins
Part I - Events & JForm
Part II - Code
Part III - Braindump
Presentation online: http://slideshare.net/yireo
Tweets: @yireo / @jissereitsma
Code: github.com/yireo/JoomlaPluginsBook
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
6. Part I:
Events & JForm
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
7. Extensions
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
Component
Modules
Plugins
Libraries
Language files
8. Plugin groups
Authentication
Content
System
User
Editors
Editor Buttons
Search
Finder
CAPTCHA
Extension
Quick Icon
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
10. JForm
Joomla core library for handling forms
XML form definition + PHP logic
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
Tasks
Form generation (HTML)
Validation
Filtering
11. MVC
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
Model
View
Controller
12. MVC workflow (simple)
User requests page
Controller calls view
View fetches data from model
View shows page
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
13. MVC workflow (form)
User requests form
Controller calls view
View shows form
User submits form (POST)
Controller picks up on POST
Controller validates & filters form
Model stores form data
Controller redirects back to form or other page
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
14. MVC workflow (form)
User requests form
Controller calls view
View shows form (JForm)
User submits form (POST)
Controller picks up on POST
Controller validates & filters form (JForm)
Model stores form data
Controller redirects back to form or other page
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
15. Part II:
Code
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
17. Goal
Add a custom field to backends article form
Store that fields value in a separate database table
Show that fields value in the same form again
Show that fields value in the frontend
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
18. Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
19. Goal
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
20. Goal
Add a custom field to backends article form
Store that fields value in a separate database table
Show that fields value in the same form again
Show that fields value in the frontend
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
21. Goal
Add a custom field to backends article form
onContentPrepareForm
Store that fields value in a separate database table
onContentAfterSave
Show that fields value in the same form again
onContentPrepareForm
Show that fields value in the frontend
onContentBeforeDisplay
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
24. Language files (1/2)
PLG_CONTENT_EXAMPLE="Content Example"
PLG_CONTENT_EXAMPLE_DESC="An example Content Plugin"
PLG_CONTENT_EXAMPLE_FIELD_EXAMPLE_LABEL=”Test”
PLG_CONTENT_EXAMPLE_FIELD_EXAMPLE_DESC=”New field”
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
25. Language files (2/2)
*.sys.ini = Always loaded
Add plugin title + description, but not much more
*.ini = Only loaded specifically
When editing a plugin in backend
When showing plugin in frontend ($autoLoadLanguage = true)
Add all language strings you need (backend + frontend)
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
31. Content Plugin - basic structure
<?php
defined('_JEXEC') or die();
class plgContentExample extends JPlugin
{
}
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
32. Content Plugin - basic structure
<?php
defined('_JEXEC') or die();
class plgContentExample extends JPlugin
{
public function onContentPrepareForm($form, $data) {}
public function onContentAfterSave($context, $item, $isNew) {}
public function onContentBeforeDisplay($context, $item, $params, $page) {}
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
}
33. Goal
Add a custom field to backends article form
onContentPrepareForm
Store that fields value in a separate database table
onContentAfterSave
Show that fields value in the same form again
onContentPrepareForm
Show that fields value in the frontend
onContentBeforeDisplay
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
34. onContentPrepareForm
public function onContentPrepareForm($form, $data)
{
...
JForm::addFormPath(__DIR__.'/form'); // subfolder “form”
$form>
loadFile('default'); // file “form/default.xml”
...
return true;
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
}
35. onContentPrepareForm
public function onContentPrepareForm($form, $data)
{
if (!($form instanceof JForm))
{
$this>_
subject>
setError('JERROR_NOT_A_FORM');
return false;
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
}
$name = $form>
getName();
if (!in_array($name, array('com_content.article')))
{
return true;
}
...
38. Goal
Add a custom field to backends article form
onContentPrepareForm
Store that fields value in a separate database table
onContentAfterSave
Show that fields value in the same form again
onContentPrepareForm
Show that fields value in the frontend
onContentBeforeDisplay
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
39. onContentAfterSave
public function onContentAfterSave(
$context, $article, $isNew
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
)
{
if (!in_array($context, array('com_content.article')))
{
return true;
}
...
44. Goal
Add a custom field to backends article form
onContentPrepareForm
Store that fields value in a separate database table
onContentAfterSave
Show that fields value in the same form again
onContentPrepareForm
Show that fields value in the frontend
onContentBeforeDisplay
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
45. onContentBeforeDisplay
public function onContentBeforeDisplay(
$context, &$row, &$params, $page = 0)
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
{
if(!empty($row>
id))
{
$row = $this>
loadExample($row);
}
if (!empty($row>
example))
{
$row>
text .= '<p>EXAMPLE: '.$row>
example.'<p>';
}
}
46. Part 3:
Braindump
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
47. Forms are everywhere
Article form
Category form
User profile form
Menu-Item form
Contact form
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
50. Showing new field values
4 times the same event
onContentPrepare
onContentAfterTitle
onContentBeforeDisplay
onContentAfterDisplay
Template override
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
51. Loading a language file - Joomla! 2.5
public function __construct(& $subject, $config)
{
parent::__construct($subject, $config);
$this>
loadLanguage();
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
}
52. Loading a language file - Joomla! 3.x
protected $autoloadLanguage = true;
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14