Joomla Custom Plugin Development
Joomla plugins react to system events. They intercept moments of the lifecycle: before/after saving an article, on authentication, on search, on form submission. This is the correct way to extend system behavior without core modification.
Plugin Groups
| Group | Event | Use |
|---|---|---|
| content | onContentBeforeSave, onContentAfterSave | Content processing |
| user | onUserLogin, onUserAfterSave | Authentication, synchronization |
| system | onAfterRoute, onBeforeRender | Global interceptions |
| authentication | onUserAuthenticate | External login providers |
| finder | onFinderIndexItem | Search index Smart Search |
| task | onExecuteTask | Task scheduler (Joomla 4+) |
Plugin Structure
plg_content_synccrm/
├── plg_content_synccrm.php # Entry point (for legacy)
├── plg_content_synccrm.xml # Manifest
├── services/
│ └── provider.php # DI Provider
└── src/
└── Extension/
└── SyncCrmPlugin.php # Main class
Manifest
<?xml version="1.0" encoding="utf-8"?>
<extension version="4.0" type="plugin" group="content">
<name>plg_content_synccrm</name>
<author>Your Company</author>
<version>1.0.0</version>
<description>Sync content with CRM on publish</description>
<namespace path="src">MyCompany\Plugin\Content\SyncCrm</namespace>
<files>
<filename plugin="plg_content_synccrm">plg_content_synccrm.php</filename>
<folder>services</folder>
<folder>src</folder>
</files>
<config>
<fields name="params">
<fieldset name="basic">
<field name="crm_api_url" type="text" label="CRM API URL" />
<field name="crm_api_key" type="password" label="CRM API Key" />
<field name="sync_types" type="checkboxes" label="Sync Types">
<option value="article">Articles</option>
<option value="product">Products</option>
</field>
</fieldset>
</fields>
</config>
</extension>
DI Provider
// services/provider.php
use Joomla\CMS\Extension\PluginInterface;
use Joomla\DI\Container;
use MyCompany\Plugin\Content\SyncCrm\Extension\SyncCrmPlugin;
return new class implements \Joomla\DI\ServiceProviderInterface {
public function register(Container $container): void {
$container->set(PluginInterface::class, function (Container $container) {
$dispatcher = $container->get(\Joomla\Event\DispatcherInterface::class);
$plugin = new SyncCrmPlugin($dispatcher, []);
$plugin->setApplication($container->get(\Joomla\CMS\Application\CMSApplicationInterface::class));
return $plugin;
});
}
};
Main Plugin Class
// src/Extension/SyncCrmPlugin.php
namespace MyCompany\Plugin\Content\SyncCrm\Extension;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Event\Event;
use Joomla\Event\SubscriberInterface;
class SyncCrmPlugin extends CMSPlugin implements SubscriberInterface {
public static function getSubscribedEvents(): array {
return [
'onContentAfterSave' => 'syncToCrm',
];
}
public function syncToCrm(Event $event): void {
[$context, $article, $isNew] = array_values($event->getArguments());
// Sync articles only
if ($context !== 'com_content.article') return;
// Only published
if ((int) $article->state !== 1) return;
$syncTypes = $this->params->get('sync_types', []);
if (!in_array('article', (array) $syncTypes)) return;
try {
$this->sendToCrm([
'type' => 'article',
'external_id'=> $article->id,
'title' => $article->title,
'url' => \Joomla\CMS\Router\Route::link('site', 'index.php?option=com_content&view=article&id=' . $article->id),
'published' => (bool) $article->state,
'updated_at' => $article->modified,
]);
} catch (\Exception $e) {
$this->getApplication()->getLogger()->error('CRM sync failed: ' . $e->getMessage());
}
}
private function sendToCrm(array $data): void {
$apiUrl = rtrim($this->params->get('crm_api_url'), '/') . '/articles';
$apiKey = $this->params->get('crm_api_key');
$http = \Joomla\CMS\Factory::getContainer()
->get(\Joomla\Http\HttpFactory::class)
->getHttp();
$response = $http->post($apiUrl, json_encode($data), [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $apiKey,
]);
if ($response->code >= 400) {
throw new \RuntimeException('CRM API error: ' . $response->code);
}
}
}
Authentication Plugin (External SSO)
public static function getSubscribedEvents(): array {
return ['onUserAuthenticate' => 'authenticate'];
}
public function authenticate(Event $event): void {
$credentials = $event->getArgument('credentials');
$options = $event->getArgument('options');
$response = $event->getArgument('response');
// Check via external OAuth server
$token = $this->verifyWithOAuthServer($credentials['username'], $credentials['password']);
if ($token) {
$response->status = \Joomla\CMS\Authentication\Authentication::STATUS_SUCCESS;
$response->email = $token['email'];
$response->fullname = $token['name'];
$response->type = 'OAuth';
} else {
$response->status = \Joomla\CMS\Authentication\Authentication::STATUS_FAILURE;
$response->error_message = 'Invalid credentials';
}
}
Timeline
Plugin development for one event group (content, user or system) with configurable parameters — 1–3 days.







