Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Extend Joomla Forms 
Using Plugins 
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo 
Jisse ...
My name is Jisse Reitsma 
Developer 
Owner of Yireo 
Joomla! & Magento 
Extensions & services 
Tutorials & blogs 
Sponsori...
Plugins I wrote 
Language Domains 
Auto Login IP 
Demo Site 
Fancybox 
HTTP Authenticatie 
New Relic 
Piwik 
WebP 
ScriptM...
Book release in November 2014 
English 
368 pages 
Available through: 
Yireo Shop (Europe) 
Amazon (US & world wide) 
#dea...
Extend Joomla Forms Using Plugins 
Part I - Events & JForm 
Part II - Code 
Part III - Braindump 
Presentation online: htt...
Part I: 
Events & JForm 
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo 
Jisse Reitsma (ji...
Extensions 
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo 
Jisse Reitsma (jisse@yireo.com...
Plugin groups 
Authentication 
Content 
System 
User 
Editors 
Editor Buttons 
Search 
Finder 
CAPTCHA 
Extension 
Quick I...
Content events 
onContentPrepareForm 
onContentAfterSave 
onContentAfterDelete 
onContentBeforeDisplay 
Presentation “Exte...
JForm 
Joomla core library for handling forms 
XML form definition + PHP logic 
Presentation “Extend Joomla Forms Using Pl...
MVC 
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo 
Jisse Reitsma (jisse@yireo.com) - Twi...
MVC workflow (simple) 
User requests page 
Controller calls view 
View fetches data from model 
View shows page 
Presentat...
MVC workflow (form) 
User requests form 
Controller calls view 
View shows form 
User submits form (POST) 
Controller pick...
MVC workflow (form) 
User requests form 
Controller calls view 
View shows form (JForm) 
User submits form (POST) 
Control...
Part II: 
Code 
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo 
Jisse Reitsma (jisse@yireo...
Content events 
onContentPrepareForm 
onContentAfterSave 
onContentAfterDelete 
onContentBeforeDisplay 
Presentation “Exte...
Goal 
Add a custom field to backends article form 
Store that fields value in a separate database table 
Show that fields ...
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo 
Jisse Reitsma (jisse@yireo.com) - Twitter ...
Goal 
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo 
Jisse Reitsma (jisse@yireo.com) - Tw...
Goal 
Add a custom field to backends article form 
Store that fields value in a separate database table 
Show that fields ...
Goal 
Add a custom field to backends article form 
onContentPrepareForm 
Store that fields value in a separate database ta...
Content Plugin files 
plugins/content/example/example.php 
plugins/content/example/example.xml 
plugins/content/exampe/for...
Content Plugin files 
plugins/content/example/example.php 
plugins/content/example/example.xml 
plugins/content/exampe/for...
Language files (1/2) 
PLG_CONTENT_EXAMPLE="Content ­Example" 
PLG_CONTENT_EXAMPLE_DESC="An example Content Plugin" 
PLG_CO...
Language files (2/2) 
*.sys.ini = Always loaded 
Add plugin title + description, but not much more 
*.ini = Only loaded sp...
Content Plugin files 
plugins/content/example/example.php 
plugins/content/example/example.xml 
plugins/content/exampe/for...
XML manifest 
<?xml version="1.0" encoding="utf­8"?> 
<extension version="3.0" type="plugin" group="content"> 
<name>PLG_C...
Content Plugin files 
plugins/content/example/example.php 
plugins/content/example/example.xml 
plugins/content/exampe/for...
XML form 
<?xml version="1.0" encoding="utf­8"?> 
<form> 
Presentation “Extend Joomla Forms Using Plugins” - http://slides...
Content Plugin files 
plugins/content/example/example.php 
plugins/content/example/example.xml 
plugins/content/exampe/for...
Content Plugin - basic structure 
<?php 
defined('_JEXEC') or die(); 
class plgContentExample extends JPlugin 
{ 
} 
Prese...
Content Plugin - basic structure 
<?php 
defined('_JEXEC') or die(); 
class plgContentExample extends JPlugin 
{ 
public f...
Goal 
Add a custom field to backends article form 
onContentPrepareForm 
Store that fields value in a separate database ta...
onContentPrepareForm 
public function onContentPrepareForm($form, $data) 
{ 
... 
JForm::addFormPath(__DIR__.'/form'); // ...
onContentPrepareForm 
public function onContentPrepareForm($form, $data) 
{ 
if (!($form instanceof JForm)) 
{ 
$this­>_ 
...
onContentPrepareForm 
... 
if(!empty($data­> 
id)) 
{ 
$data = $this­> 
loadExample($data); 
Presentation “Extend Joomla F...
loadExample 
protected function loadExample($data) 
{ 
$db = JFactory::getDbo(); 
$query = $db­> 
getQuery(true); 
$query­...
Goal 
Add a custom field to backends article form 
onContentPrepareForm 
Store that fields value in a separate database ta...
onContentAfterSave 
public function onContentAfterSave( 
$context, $article, $isNew 
Presentation “Extend Joomla Forms Usi...
onContentAfterSave 
... 
$jinput = JFactory::getApplication()­> 
input; 
$form = $jinput­> 
post­> 
get('jform', null, 'ar...
onContentAfterSave 
... 
$content_id = $article­> 
id; 
$this­> 
saveExample($content_id, $context, $example); 
return tru...
saveExample 
protected function saveExample($content_id, $context, $test) 
{ 
$db = JFactory::getDbo(); 
$query = $db­> 
g...
saveExample 
... 
$data = new stdClass(); 
$data­> 
content_id = $content_id; 
$data­> 
context = $context; 
$data­> 
exam...
Goal 
Add a custom field to backends article form 
onContentPrepareForm 
Store that fields value in a separate database ta...
onContentBeforeDisplay 
public function onContentBeforeDisplay( 
$context, &$row, &$params, $page = 0) 
Presentation “Exte...
Part 3: 
Braindump 
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo 
Jisse Reitsma (jisse@y...
Forms are everywhere 
Article form 
Category form 
User profile form 
Menu-Item form 
Contact form 
Presentation “Extend J...
JForm manipulation 
$form->load($xml) 
$form->loadFile($file) 
$form->bind($data) 
$form->getField($name, $group, $value) ...
JForm output 
$form->getInput($field, $group) 
$form->getLabel($field, $group) 
$form->getName($field, $group) 
$form->get...
Showing new field values 
4 times the same event 
onContentPrepare 
onContentAfterTitle 
onContentBeforeDisplay 
onContent...
Loading a language file - Joomla! 2.5 
public function __construct(& $subject, $config) 
{ 
parent::__construct($subject, ...
Loading a language file - Joomla! 3.x 
protected $autoloadLanguage = true; 
Presentation “Extend Joomla Forms Using Plugin...
github.com 
/yireo 
/JoomlaPluginsBook 
/chapter05 
https://github.com/yireo/JoomlaPluginsBook/tree/master/chapter05 
Pres...
@yireo 
opening up technology 
Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo 
Jisse Reits...
Upcoming SlideShare
Loading in …5
×

Extend Joomla Forms Using Plugins

1,301 views

Published on

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.

Published in: Technology
  • Very nice tips on this. In case you need help on any kind of academic writing visit website ⇒ www.HelpWriting.net ⇐ and place your order
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Writing good research paper is quite easy and very difficult simultaneously. It depends on the individual skill set also. You can get help from research paper writing. Check out, please ⇒ www.HelpWriting.net ⇐
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Extend Joomla Forms Using Plugins

  1. 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. 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. 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. 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. 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. 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. 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. 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
  9. 9. Content events onContentPrepareForm onContentAfterSave onContentAfterDelete onContentBeforeDisplay Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
  10. 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. 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. 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. 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. 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. 15. Part II: Code Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
  16. 16. Content events onContentPrepareForm onContentAfterSave onContentAfterDelete onContentBeforeDisplay Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
  17. 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. 18. Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
  19. 19. Goal Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
  20. 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. 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
  22. 22. Content Plugin files plugins/content/example/example.php plugins/content/example/example.xml plugins/content/exampe/form/default.xml administrator/languages/en-GB/en-GB.plg_content_example.ini administrator/languages/en-GB/en-GB.plg_content_example.sys.ini Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
  23. 23. Content Plugin files plugins/content/example/example.php plugins/content/example/example.xml plugins/content/exampe/form/default.xml administrator/languages/en-GB/en-GB.plg_content_example.ini administrator/languages/en-GB/en-GB.plg_content_example.sys.ini Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
  24. 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. 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
  26. 26. Content Plugin files plugins/content/example/example.php plugins/content/example/example.xml plugins/content/exampe/form/default.xml administrator/languages/en-GB/en-GB.plg_content_example.ini administrator/languages/en-GB/en-GB.plg_content_example.sys.ini Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
  27. 27. XML manifest <?xml version="1.0" encoding="utf­8"?> <extension version="3.0" type="plugin" group="content"> <name>PLG_CONTENT_EXAMPLE</name> <description>PLG_CONTENT_EXAMPLE_DESC</description> <version>0.0.1</version> <files> <filename plugin=”example”>example.php</filename> <folder>form</folder> Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14 </files> <languages> <language tag=”en­GB”> en­GB. plg_content_example.ini</language> <language tag=”en­GB”> en­GB. plg_content_example.sys.ini</language> </languages> </extension>
  28. 28. Content Plugin files plugins/content/example/example.php plugins/content/example/example.xml plugins/content/exampe/form/default.xml administrator/languages/en-GB/en-GB.plg_content_example.ini administrator/languages/en-GB/en-GB.plg_content_example.sys.ini Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
  29. 29. XML form <?xml version="1.0" encoding="utf­8"?> <form> Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14 <fields> <fieldset name="jmetadata"> <field name="example" type="text" label="PLG_CONTENT_EXAMPLE_FIELD_EXAMPLE_LABEL" description="PLG_CONTENT_EXAMPLE_FIELD_EXAMPLE_DESC" /> </fieldset> </fields> </form>
  30. 30. Content Plugin files plugins/content/example/example.php plugins/content/example/example.xml plugins/content/exampe/form/default.xml administrator/languages/en-GB/en-GB.plg_content_example.ini administrator/languages/en-GB/en-GB.plg_content_example.sys.ini Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
  31. 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. 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. 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. 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. 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; } ...
  36. 36. onContentPrepareForm ... if(!empty($data­> id)) { $data = $this­> loadExample($data); Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14 } return true; }
  37. 37. loadExample protected function loadExample($data) { $db = JFactory::getDbo(); $query = $db­> getQuery(true); $query­> select('*') ­> from($db­> quoteName('#__example')) ­> where($db­> quoteName('content_id') . ' = '.$data­> id); $db­> setQuery($query); $exampleData = $db­> loadAssoc(); $data­> example = $exampleData['example']; return $data; Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14 }
  38. 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. 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; } ...
  40. 40. onContentAfterSave ... $jinput = JFactory::getApplication()­> input; $form = $jinput­> post­> get('jform', null, 'array'); if (is_array($form) && isset($form['example'])) { $example = $form['example']; Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14 } else { return true; } ...
  41. 41. onContentAfterSave ... $content_id = $article­> id; $this­> saveExample($content_id, $context, $example); return true; Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14 }
  42. 42. saveExample protected function saveExample($content_id, $context, $test) { $db = JFactory::getDbo(); $query = $db­> getQuery(true); $query­> select($db­> quoteName('content_id')) ­> from($db­> quoteName('#__example')) ­> where($db­> quoteName('content_id').'='.$content_id); $db­> setQuery($query); $db­> execute() $exists = (bool)$db­> getNumRows(); ... Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
  43. 43. saveExample ... $data = new stdClass(); $data­> content_id = $content_id; $data­> context = $context; $data­> example = $example; if($exists) { $result = $db­> updateObject('#__example', $data, 'content_id'); Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14 } else { $result = $db­> insertObject('#__example', $data); } return true; }
  44. 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. 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. 46. Part 3: Braindump Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
  47. 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
  48. 48. JForm manipulation $form->load($xml) $form->loadFile($file) $form->bind($data) $form->getField($name, $group, $value) $form->removeField($field) $form->setField($xml) Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
  49. 49. JForm output $form->getInput($field, $group) $form->getLabel($field, $group) $form->getName($field, $group) $form->getValue($field, $group) $form->renderField($field, $group) $form->getFieldset($fieldset) $form->getFieldsets($group) Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
  50. 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. 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. 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
  53. 53. github.com /yireo /JoomlaPluginsBook /chapter05 https://github.com/yireo/JoomlaPluginsBook/tree/master/chapter05 Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14
  54. 54. @yireo opening up technology Presentation “Extend Joomla Forms Using Plugins” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo @jissereitsma #jwc14

×