Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Learning Joomla! 3 Extension Development
Learning Joomla! 3 Extension Development

Learning Joomla! 3 Extension Development: If you have ideas for additional Joomla 3! features, this book will allow you to realize them. It's a complete practical guide to building and extending plugins, modules, and components. Ideal for professional developers and enthusiasts. , Third Edition

eBook
€24.99 €36.99
Paperback
€45.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Learning Joomla! 3 Extension Development

Chapter 2. Getting Started with Plugin Development

By now, I'm sure you are itching to get your hands dirty and start playing with some code. If you skipped the first chapter, don't worry, you can come back to the theory later. Most development books will start out with a "hello world" example, but that's been done before and is really boring, so we are going to skip that and start out by creating a simple plugin that actually does something useful. By the end of this chapter, you will have made your first Joomla! plugin. You will learn the following things in this chapter:

  • An overview of the various types of Joomla! plugins

  • How to create a content plugin

  • How to package your plugin so you can share it with others

  • How to make your plugin more flexible by adding parameters

  • How to create language files for your plugin

  • The power of language overrides

Plugin types


Before we create our first plugin, let's talk about the different types of plugins that you can create for Joomla!. Plugin code is executed when certain events are triggered. You can skip the next couple of pages if you just want to get stuck in with the hands-on example and just go straight to the Where do I start? section, but you may want to refer back to this introduction later when you are creating your own plugins. The different types of plugins are explained as follows:

  • Authentication: When you log in to your website, an authentication plugin runs to check your credentials and decide if you should have access to the site. Authentication plugins are used when you want to use other login methods too, such as Facebook, Gmail, or LDAP. You can use more than one authentication plugin on the same site so that you can give your users a choice and not force them to have to remember another password by allowing them to reuse one of their existing accounts in another system. The...

Plugin event triggers


Each plugin type has its own set of events that trigger these plugins to execute. Each plugin can use one or more event triggers but there is no need to use all the event triggers available, just pick out the ones you need. You also have the freedom to create your own custom plugin event triggers in your components, however, that is also outside the scope of this book. The following table summarizes the types of plugins available and their respective event triggers:

Plugin type

Event trigger

Authentication

onUserAuthenticate

onUserAuthorisationFailure

Captcha

onCheckAnswer

onDisplay

onInit

Content

onContentAfterDelete

onContentAfterDisplay

onContentAfterSave

onContentAfterTitle

onContentBeforeDelete

onContentBeforeDisplay

onContentBeforeSave

onContentChangeState

onContentPrepare

onContentPrepareData

onContentPrepareForm

onContentSearch

onContentSearchAreas

Editors

onDisplay

onGetContent

onGetInsertMethod

onInit

onSave...

Where do I start?


To get started with plugin development, first we need to decide what problem we are trying to solve or what functionality we are trying to implement.

Let's assume that you have a website with various phone numbers listed on the site, and that this site is popular with people who access the site through a smartphone. Currently, to call one of the numbers, the user has to remember the number to dial it, or perhaps they jot it down on a piece of paper or attempt to select and copy the number through their browser. This is not very user-friendly, a much better way to do this would be to change the phone number to a click-to-call link, so the user can just click the phone number and their phone will call it. Now, you could go through the website and manually change all the phone numbers to these links, but that would be inconvenient. Assuming our phone number is in the format 1234-5678, we could change it to this HTML code to create a click-to-call link.

<a href="tel: 1234...

Creating the installation XML file


The first file we need to create is the installation XML file (also known as the XML Manifest) which tells Joomla! all about this plugin when you install it through an extension manager. This XML file describes all the files and folders used by this plugin, and what parameters the plugin has. The naming standard of the installation XML file is extensionname.xml, in our case it will be clicktocall.xml as we drop the plg_content_ prefix.

Create a folder called plg_content_clicktocall.

In this folder, create a file called clicktocall.xml and insert the following code:

<?xml version="1.0" encoding="UTF-8"?>
<extension
    version="3.0"
    type="plugin"
    group="content"
    method="upgrade">
  <name>Content - Click To Call</name>
  <author>Tim Plummer</author>
  <creationDate>April 2013</creationDate>
  <copyright>Copyright (C) 2013 Packt Publishing. All rights reserved.</copyright>
  <license&gt...

Creating the plugin PHP file


So now we need to write the PHP file that does all the hard work for this plugin and implements the functionality that we are trying to achieve. In your plg_content_clicktocall folder, create the file clicktocall.php with the following code:

<?php
defined('_JEXEC') or die;

jimport('joomla.plugin.plugin');

class plgContentClicktocall extends JPlugin
{
  function plgContentClicktocall( &$subject, $params )
  {
    parent::__construct( $subject, $params );
  }

  public function onContentPrepare($context, &$row, &$params, $page = 0)
  {
    // Do not run this plugin when the content is being indexed
    if ($context == 'com_finder.indexer')
    {
      return true;
    }

    if (is_object($row))
    {
      return $this->clickToCall($row->text, $params);
    }
    return $this->clickToCall($row, $params);
  }

  protected function clickToCall(&$text, &$params)
  {
    // matches 4 numbers followed by an optional hyphen or space...

Zip it up and install your plugin


Now that you have created all the code for the Click to Call plugin, you need to test it in your Joomla! site to see if it works correctly. We will start out with a way that you might get this running on your development site, then, we will zip it all up into an installable file that you could distribute to other people.

Before we do that, you will need to add some phone numbers in your articles that we are going to turn into Click to Call links, so that we know the plugin works. Add some phone numbers in 1234-5678 or 1234 5768 format.

In your Joomla! 3 development website, find the /plugins/content/ folder and create a new folder clicktocall.

Copy into this folder the files you have created, clicktocall.xml, clicktocall.php, and index.html.

Now in your Joomla! Administrator, navigate to Extensions | Extension Manager, and select the Discover view at the left side. Click on the Discover button and you should see the Content - Click To Call plugin appearing....

Adding the parameters to our plugin


Our plugin works well, but what if the phone number format in your country is not 1234-5678? For example, Germany uses the format 123-45678. Wouldn't it be better if we had a parameter where we could set the phone number format? As this is a simple plugin, we are not going to worry about area code prefix or numbers in more complex formats such as 123-456-7890; we are concentrating on numbers that consist of two groups of digits.

We are going to add two parameters to our plugin (also known as options), one that sets the number of digits in the first group, and one that sets the number of digits in the second group.

So open up your clicktocall.xml file, and add in the highlighted code shown as follows (everything between the config tags):

<?xml version="1.0" encoding="UTF-8"?>
<extension
    version="3.0"
    type="plugin"
    group="content"
    method="upgrade">
  <name>Content - Click To Call</name>
  <author>Tim Plummer&lt...

Adding the language files


At the moment, all the text used in our plugin is hardcoded, so if a user wanted to change any of the text, they would have to edit the source code which is something we want to avoid for our end users. A lot of people use Joomla! in their native language and not everyone is going to want the text in English. Even if your plugin is only ever going to be used by English speakers, you still want them to be able to easily override the text to suit their needs. So we are going to create a language file, and instead of hardcoding the text, we will use a language string.

Firstly, we are going to replace the text in the parameters we have just added with language strings. Edit the clicktocall.xml file, and make the following changes:

<?xml version="1.0" encoding="UTF-8"?>
<extension
    version="3.0"
    type="plugin"
    group="content"
    method="upgrade">
  <name>Content - Click To Call</name>
  <author>Tim Plummer</author>
  <creationDate...

Summary


Congratulations, you have now created your first extension for Joomla!: a plugin to change phone numbers in articles into Click to Call links. We learned about the installation XML file, and the PHP code required to make a simple plugin. We took a look at the different types of plugins in Joomla! and what events can trigger them. We then created an installable package of our plugin and tried it out on a Joomla! website. You can now add Joomla! Extension Developer to your resume!

In the next chapter, you will create your first Joomla! module.

Left arrow icon Right arrow icon

Key benefits

  • Clear steps to create your own plugins, modules, and components for Joomla 3
  • Guides you through extending your components by allowing them to interact with modules and plugins
  • Introduces you to packaging your extensions for distribution to other Joomla users
  • Enables you to secure your extensions and avoid common vulnerabilities by gaining some white hat hacking experience

Description

Joomla 3 is the first of the major open source content management systems that was meant to be mobile friendly by default. Joomla uses object-oriented principles, is database agnostic, and has the best mix of functionality, extensibility, and user friendliness. Add to that the fact that Joomla is completely community driven, and you have a winning combination that is available to everyone, and is the perfect platform to build your own custom applications. "Learning Joomla! 3 Extension Development" is an integrated series of practical, hands-on tutorials that guide you through building and extending Joomla plugins, modules, and components. With Joomla having been downloaded well over 35 million times, there is a huge market for Joomla extensions, so you could potentially earn some extra cash in your spare time using your newly acquired Joomla extension development skills. We will start with developing simple plugins and modules, and then progress to more complex backend and frontend component development. Then we will try our hand at ethical hacking, so you will learn about common security vulnerabilities and what you can do to avoid them. After that we will look at how you can prepare your extensions for distribution and updates, as well as how you can extend your components with various plugins and modules. Finally, you will end up with a fully functioning package of extensions that you can use on your own site or share with others. If you want to build your own custom applications in Joomla, then "Learning Joomla! 3 Extension Development" will teach you everything you need to know in a practical, hands-on manner.

Who is this book for?

"Learning Joomla! 3 Extension Development" is for developers who want to create their own Joomla extensions. It is assumed you will have some basic PHP, HTML, and CSS knowledge, but you don't need any prior Joomla programming experience. This book will also be useful to people who just want to make minor customizations to existing Joomla extensions and build on the work of others in the open source spirit.

What you will learn

  • Extend Joomla using plugins
  • Develop both frontend and backend modules
  • Build a Joomla component that looks and behaves like the core components, to reduce the learning curve for your users
  • Discover common security vulnerabilities and what you can do to avoid them
  • Prepare your extensions for distribution
  • Manage updates and set up an update server
  • Integrate third party extensions in your component

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jul 26, 2013
Length: 458 pages
Edition : 3rd
Language : English
ISBN-13 : 9781782168386
Languages :
Concepts :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : Jul 26, 2013
Length: 458 pages
Edition : 3rd
Language : English
ISBN-13 : 9781782168386
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 124.98
Learning Joomla! 3 Extension Development
€45.99
Learning Joomla! 3 Extension Development
€78.99
Total 124.98 Stars icon

Table of Contents

10 Chapters
Before you Start Chevron down icon Chevron up icon
Getting Started with Plugin Development Chevron down icon Chevron up icon
Getting Started with Module Development Chevron down icon Chevron up icon
Getting Started with Component Development Chevron down icon Chevron up icon
Backend Component Development – Part 1 Chevron down icon Chevron up icon
Backend Component Development – Part 2 Chevron down icon Chevron up icon
Frontend Component Development Chevron down icon Chevron up icon
Security – Avoiding Common Vulnerabilities Chevron down icon Chevron up icon
Packing Everything Together Chevron down icon Chevron up icon
Extending your Component with Plugins and Modules Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3
(23 Ratings)
5 star 52.2%
4 star 39.1%
3 star 4.3%
2 star 0%
1 star 4.3%
Filter icon Filter
Top Reviews

Filter reviews by




herman van cauwelaert Aug 23, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Clearly explained without getting lost in details.Who to start from scratch and make your own component work.A good understanding of Object Oriented programming is a must for as far as I see things.
Amazon Verified review Amazon
Dan Oct 02, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Good book to start with joomla developing
Amazon Verified review Amazon
Ammar Arwany Jan 30, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I have been reading this book for the past 2 weeks, reviewing every page of it, well I must say, it covers the most important parts of the development process for joomla extensions in all aspects, that help every newly joint developer or even an expert to get his job well done, and even to get your extension listed on the JED without any issues (there are really good writings on that).Joomla as a CMS is wiedly used in creating the websites, and is the choice number 1 for most of the webmasters who want to create a website on the go, and it got that because of the core functionalties that provide security, and creativity and user-friendly and fast responding experience for both of the user and the webmaster, in this book, you get a really nice tips and information about how to make the life of the user and the webmaster easy and make the working with your component a funny thing, and get it recommended from everyone, This book has just got me on the right road, and shown me the way to the successfull development.Just to mention, that the author is a very kind person, and he replies to the emails in an amazing short time, I even wonder how he got time to write back tot he users (and not even few words, but long answers of course with helpful tips and informations).I thank you Tim Plummer for your nice book! just keep it up and I am burning to see your next book!
Amazon Verified review Amazon
Lüttmen Mar 01, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
für den Freund meiner Tochter, Informatiker das Buch schlecht hin.Ich kann leider weniger dazu mitteilen. Als Geschenk für die Compifreaksgenau richtig, Hinweis: Sprache in Englisch.
Amazon Verified review Amazon
Amazon Customer Sep 17, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Si lo que quieres es programar con los criterios de Joomla, entonces este es tu libro.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.