Using module helpers
Joomla! module architecture relies on the getLayoutData()
method from the dispatcher to process the information that we will display in the module.
We could place all our logic inside this method and let it grow to whatever size we need, but that will make our code break lots of coding principles, such as DRY (short for Don’t Repeat Yourself), single responsibility, and more.
As module helpers are a core part of Joomla! Module classes, we should take advantage of them and work with helper classes that lead to cleaner code.
Following the Dispatcher.php
code from the previous section, there was a call to the module helper. Now, we need to create the code for our helper, so we create the src/module/mod_projectslist/src/Helper/ProjectsListHelper.php
file with the following content:
<?php namespace Piedpiper\Module\ProjectsList\Site\Helper; use Piedpiper\Component\Spm\Site\Model\ProjectsModel; use Joomla\CMS\Application\SiteApplication; use Joomla...