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

Arrow left icon
Profile Icon Timothy John Plummer
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3 (23 Ratings)
Paperback Jul 2013 458 pages 3rd Edition
eBook
$24.99 $36.99
Paperback
$60.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Timothy John Plummer
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3 (23 Ratings)
Paperback Jul 2013 458 pages 3rd Edition
eBook
$24.99 $36.99
Paperback
$60.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$24.99 $36.99
Paperback
$60.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781782168379
Languages :
Concepts :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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
$279.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 $ 153.98
Learning Joomla! 3 Extension Development
$60.99
Learning Joomla! 3 Extension Development
$92.99
Total $ 153.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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.