Work In Progress

This book is currently work in progress. Some sections are not yet written. Thank you for your understanding!

Joomla Extensions Development

The missing Joomla™ reference for extension developers

Nicholas K. Dionysopoulos

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".

This work is not affiliated with or endorsed by the Joomla! Project. It is not supported or warranted by the Joomla! Project or Open Source Matters. The Joomla! logo is used under a limited license granted by Open Source Matters, the trademark holder in the United States and other countries.

All code found in the code samples in this book is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This sample program code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this sample program code; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

January 2024

Abstract

Developing Joomla extensions is fun and fulfilling. However, its API evolves to better suit the changing times and PHP best practices. When Joomla 4 came out with its richer, brand new API there was no documentation to tell developers how to update and keep developing their extensions. Moreover, over a decade of API stagnation and lack of documentation led developers to complacency, bad code, and unmaintainable code. This book aims to distill my experience writing Joomla software since 2006 and includes some useful background on how some features were decided, how they are meant to be used, and where they fit in the larger picture of writing efficient, maintainable code. This is neither a tutorial nor a reference book. It's more of a practical guide through the Joomla extensions development API.

This book covers development of Joomla! extensions under Joomla versions 4 and 5.


Table of Contents

Introduction
About this book
About the author
New Joomla 4 features at a glance
1. Basic concepts
Namespaces
Dependency Injection Container / Service Locator
Web Asset Management
2. Components
The Joomla MVC: an introduction
Joomla 3 MVC vs Joomla 4 MVC
The lifetime of a component
Booting the component
Getting the Dispatcher
Dispatching the component
Directory structure
Service provider
Extension class
Naming your extension class
Using your extension class in the service provider
Using your extension class from outside the component
Getting access to the component's DIC anytime, anywhere
Dispatcher
Namespaces and MVC
How things worked from Joomla 1.5 to 3.10
How things work Joomla 4.0 onwards
The MVCFactory
Models
Interfaces and Traits
Pushing services to the Model: the Joomla Way
Pushing services to the Model: an alternative
Controllers
Basic services in your Controller
Views
Tables
Getting the table object
Customising the validation
Using plugin events
Add type hints with phpDoc DocBlocks and @property
Basic relation management with getters and setters
Asset management
Working with arrays and JSON data
HTML helper service
Categories
Database schema changes
Changes to your XML manifest and forms
The Category service
Router
The case for URL routing
Intermission: abandon all hope ye who enter here
Joomla 3 vs Joomla 4
Using RouterView
Pushing dependencies to the Router
Dashboard
The installation script
Component menus
The default component menu
Backend menu items
Frontend menu items
Passing data from the backend to the JavaScript on the page
Language files
Mail Templates
The CLI application
Command classes
Console plugins
The API application
Overview
Access and Authentication
The API part of your component
Adding it to your XML manifest
Controllers
Models
Views
Web services plugin
Integration with Scheduled Tasks
Custom fields
3. Plugins
The many forms of a Joomla plugin
Legacy (Joomla 1.x to 3.x)
Joomla 4 classic
Joomla 4 with SubscriberInterface
Legacy vs Event Listener methods
Namespaces
Service Provider
Extension class (plugin)
Language files
View Templates
Plugins and com_ajax
How NOT to break Joomla with your plugin
Generic versus Concrete events
4. Modules
Legacy vs Joomla 4 modules
Legacy modules (Joomla 1.x to 3.x)
Joomla 4 modules
Service provider
Dispatcher class
Language files
The Helper
View templates
Modules and com_ajax
Interfacing with your component (HMVC)
5. General advice and code magic
Clarity unlocks efficiency
Write code which doesn't suck
DON'T: Hard-coded database queries
DON'T: Using superglobals ($_REQUEST, $_SERVER, $_GET, $_POST etc)
DON'T: Using REMOTE_ADDR to get the user's IP
DON'T: Include duplicate copies of libraries shipped with Joomla itself
DON'T: Using eval()
The fine art of writing error messages
Adding Composer dependencies
Library packages
Use the right core folder
A. GNU Free Documentation License
B. GNU General Public License