First Things to Understand about Joomla Development

Ok so you're already a PHP web developer and you're coming to Joomla for the first time. Perhaps you're starting out and have been writing native PHP for a while, perhaps you're a Wordpress or Drupal person, perhaps you're one of those people who trolls Laraval fans on Reddit. A client has dumped a Joomla site on you and you need to get your head around the fundamental question "where do I stick my code?"

Just calm down already

Joomla is a CMS and an extension platform. When you write Joomla code you're either a core contributor to the CMS itself or you're building a custom application inside the Joomla application. Components, modules and plugins are folders of files with a php entry file that the Joomla application will include under the right conditions. Once you know how to make your Joomla site call your code you can do what ever you want.

The fact that it is primarily a CMS directed at end users means that it's built so that extension developers can put all the power into the administration interface to let users with no code experience create a website, configure applications, organise structure, content, access logic. For this reason you should have some familiarity with the interface before you write any code. You also need to understand the difference between the types of extensions, know what upgrading Joomla and extensions involves and a few other things.

Quick tour of the Joomla Administrator Interface

That being said most of the time, once you understand the difference between the extension types, how to install and uninstall them, how and why they run and how to control which users have access to what, the actually amount of code you need to write in order to get back to the PHP you wanted to write in the first place is incredibly minimal. Have no doubt that you can treat Joomla like an application framework that has very little in common with “content management”.

If you're not distributing an extension, ie. no one else is ever going to install your extension, then you're free to take a very opt-in approach to Joomla conventions. All you need to care about is sticking your code where it will not get overriden when the Joomla CMS gets upgraded. But you also want to be able to leverage the things that Joomla's taking care of and work around Joomla when you don't want to follow where it's leading.

You can also extend 3rd party extensions. Some of the time you will be able to build a custom application by putting your own layer of code over an existing application using the template override system or a plugin event. Furthermore there are numerous extensions that can be customised with both interface level config and PHP to produce a wide variety of application types. If you’re building an application then the place to start is often the Joomla Extension Directory.

So let's run through the exension types and work out which one is appropriate for which use case.

Types of Joomla Extensions

Components, Modules, Plugins, Templates, Libraries

As a general rule, you can often see how things are done by looking at the code of Joomla core extesions. Joomla comes installed with a lot of components, modules and plugins, and some of these are really only there to see what a Joomla entension looks like when built the Joomla way.

Components

Joomla comes with a bunch of pre-installed 'core' components - the one you most use to make content is com_content. Some core components are there to support the site and other components, eg. com_config.

Every Joomla request runs 1 component (though other component's code may also be running as part of the lifecycle, eg. com_menus). Take a second to get your head around this concept. It means that Joomla is a CMS insofar as you're looking at a page where a menu item has been mapped to a single view served up by the com_content component. But if the menu item is pointed to a different component, then the site is doing whatever that component is built to do, which can be anything PHP can do.

The output of the component is the main thing on the page - the bit in the the middle. Generally components have a frontend and a backend interface (though they can have just one, and more rarely none at all). Generally they have their own database tables and generally are effectly a standalone application that can employ Joomla services whereever required. Components can have their own router and thereby take over the routing of the url from their menu entry point.

Joomla Components

Modules

Around the outside of the page are the modules. Modules generally are used for displaying accompanying material, and generally don't handle input. They can be set to run on every page like a (logo or menu) or just on certain pages. They can be set to only show to certain access groups (like registred users).

Joomla Modules

Plugins

Event driven code. There are so many types of plugins that they are best thought of as everything else.

Joomla Plugins

Templates

Generally you never have to code in the template. And for this reason you'll find that using a third party template won't get in your way. But making you template can be pretty easy too.

Joomla Templates

Libraries

Allow for custom code reuse betwen extensions. Libraries have to be initilised (registered with Joomla's autoloader) elsewhere, eg. in a system plugin if the library is to be accessible from anywhere.

Joomla Custom Library

The Joomla Life Cycle

Joomla has three applications, the installer, the site and the admin. Generally we only caring about the frontend, but most of what we deal with there also applies to the backend.

  • Bootstrap Framework & Application (including the User (which belongs to one or many usergroups that are each mapped to access groups) and a Document object (which gathers up the headtag, component output, and module output) .)
  • Router (This reads the url and figures out which menu item is the best candidate to be in charge. the internal non-SEF query url is built and handed over to the component. The menu item is mapped to a single layout of a view of a single component. NB: The id of the menu is called the ItemId.)
  • 1 Component and generally one layout of one view class will render its html which gets buffered in the Document
  • X number of Modules and rendered (Modules are mapped to the ItemId.)
  • Template (which contains position placeholders for the headtag content, the modules and the component.)
  • Render