I have a component com_something
that I am developing. Whenever a user goes to any view in this component (i.e. when the URL starts with index.php?option=com_something
), I want to check the URL for a parameter trackingToken=2
. If it exists, I log something into the database.
Does Joomla have a URL middleware hook that I can use (like below)?
public function handleUrl(string $url): void
{
$app = $this->getApplication();
$db = $this->getDatabase();
$trackingToken = $app->input->getString('trackingToken', null);
if (!is_null($trackingToken)) {
trackToken($db, $trackingToken);
}
}
Or do I have to make sure that every HtmlView.php
also extends some base HtmlView
that does this?
abstract class MiddlewareHtmlView extends \Joomla\CMS\MVC\View\HtmlView
{
public function display($tpl = null): void
{
$app = \Joomla\CMS\Factory::getApplication();
$db = \Joomla\CMS\Factory::getDbo();
$trackingToken = $app->input->getString('trackingToken', null);
if (!is_null($trackingToken)) {
trackToken($db, $trackingToken);
}
parent::display($tpl);
}
}
final class HtmlView extends MiddlewareHtmlView
{
public function display($tpl = null): void
{
parent::display($tpl);
}
}