PR-6.1-dev Pending

User tests: Successful: Unsuccessful:

avatar joomdonation
joomdonation
8 Dec 2025

Pull Request for Issue # .

Summary of Changes

The getTemplate() method in SiteApplication has grown too large, become quite complicated and hard to follow. It also contains several issues:

  • Inconsistent template validation logic - in some areas the parent template is considered during validation, while in others it is not.

  • Repeat the same code for to handle logic for case standard template and for child template

This PR refactors getTemplate() into smaller, focused methods, removes duplicated code, and unifies the template validation process. The result is cleaner, more consistent, and easier-to-maintain code without changing existing behavior.

The same logic change was also updated to AdministratorApplication class to make the logic/code consistent

Testing Instructions

  • Uses Joomla 6.1
  • Apply patch
  • Access to administrator area of your site, navigate to random pages, make sure it is still working as expected.
  • Browse frontend of your site and make sure nothing is broken
  • Should also test frontend of your site with child template as well
  • Require careful code review from maintainer

Actual result BEFORE applying this Pull Request

Works

Expected result AFTER applying this Pull Request

Works, with better, cleaner code

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

avatar joomdonation joomdonation - open - 8 Dec 2025
avatar joomdonation joomdonation - change - 8 Dec 2025
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 8 Dec 2025
Category Libraries
avatar joomdonation joomdonation - change - 8 Dec 2025
Labels Added: PR-6.1-dev
5731e33 8 Dec 2025 avatar joomdonation CS
a9d09b7 9 Dec 2025 avatar joomdonation CS
avatar joomdonation joomdonation - change - 9 Dec 2025
The description was changed
avatar joomdonation joomdonation - edited - 9 Dec 2025
avatar joomdonation
joomdonation - comment - 9 Dec 2025

I made the same logic change for AdministratorApplication. @dgrammatiko I guess many of these code was implemented by yourself, so it would be great if you could review/test this PR. Thanks !

avatar richard67 richard67 - change - 9 Dec 2025
Title
[6.1]Refactor SiteApplication getTemplate method
[6.1] Refactor SiteApplication getTemplate method
avatar richard67 richard67 - edited - 9 Dec 2025
avatar richard67
richard67 - comment - 11 Dec 2025

I made the same logic change for AdministratorApplication.

@joomdonation Are title and description of this PR still right after that change?

avatar joomdonation joomdonation - change - 11 Dec 2025
Title
[6.1] Refactor SiteApplication getTemplate method
[6.1] Refactor SiteApplication and AdministratorApplication detect template logic
avatar joomdonation joomdonation - edited - 11 Dec 2025
avatar joomdonation joomdonation - change - 11 Dec 2025
Title
[6.1] Refactor SiteApplication and AdministratorApplication detect template logic
[6.1] Refactor Site and Administrator detect template logic
avatar joomdonation joomdonation - edited - 11 Dec 2025
avatar joomdonation
joomdonation - comment - 11 Dec 2025

@richard67 I updated the title to reflect the additional change

avatar HLeithner
HLeithner - comment - 11 Dec 2025

Thanks, maybe we can complete the optimization and move the
CMSApplication::getTemplate() to CMSApplication::initialiseTemplate()
and the new code fore
SiteApplication::getTemplate() to CMSApplication::getTemplate()

// this code should be the same for all 3 Applications
if (!\is_object($this->template)) {
    $this->initialiseTemplate();
}

if ($params) {
    return $this->template;
}

return $this->template->template;

Remove SiteApplication::getTemplate() because it's in CMSApplication::getTemplate() now
Remove AdministratorApplication::getTemplate() because it's in CMSApplication::getTemplate() now
Remove ApiApplication::getTemplate() because it's in CMSApplication::getTemplate() now

if 3rd Party extensions extend the CMSApplication they would have already overridden getTemplate() or will still get the same "system" template as before.

Or do I miss something?

avatar joomdonation
joomdonation - comment - 11 Dec 2025

Nice idea. Thanks @HLeithner

if 3rd Party extensions extend the CMSApplication they would have already overridden getTemplate() or will still get the same "system" template as before.

We do not have to worry about this one. The CMSApplication initialiseTemplate method will still set the template to system like before, so there is no backward incompatible change here. If we want, we can even use same logic for Installation application. Let me know if you want me to do that or we should leave Installation app as how it is.

482611d 11 Dec 2025 avatar joomdonation CS
avatar joomdonation joomdonation - change - 11 Dec 2025
Title
[6.1] Refactor Site and Administrator detect template logic
[6.1] Refactor CMSApplication getTemplate logic
avatar joomdonation joomdonation - edited - 11 Dec 2025
9297ec6 11 Dec 2025 avatar joomdonation CS
avatar HLeithner
HLeithner - comment - 11 Dec 2025

Yes of course, I missed the installer but yes that should also use the new method.

avatar HLeithner
HLeithner - comment - 11 Dec 2025

@AlterBrains @dgrammatiko it's a rearrange not a refactoring, if you like to change this please create own PR so they can be tested in an isolated way, thanks.

avatar joomla-cms-bot joomla-cms-bot - change - 12 Dec 2025
Category Libraries Installation Libraries
918579c 12 Dec 2025 avatar joomdonation CS
avatar joomdonation
joomdonation - comment - 12 Dec 2025

Thanks @AlterBrains @dgrammatiko for your review and suggested changes. I applied all the suggestions which I find safe to be included in this PR. For other details, while I agree with most it, I don't want to include in this PR to avoid too much details changes, which makes it harder for maintainers/release managers to review. It can always be improved later in a separate PR

@AlterBrains About your suggestions about making the methods protected, not private: The reason I have it private because I think the logic in these methods really suitable for SiteApplication (getTemplates for example, call model to get site template style, so I don't think a class which extends SiteApplication will need to re-use it). Having methods as protected make it more flexible, allow custom code to extends it, but it also hold us back if we want to improve it in the future due to backward compatible promise. The method findTemplate for example, it is just an utility method and maybe have it as a member of SiteApplication for now, maybe in the future, we can introduce a new class (TemplateHelper or TemplateService..., something like that) to replace that, and having the method as private allow us to safe to remove.... I will ask Harald about it, but for now, I will keep these methods as private.

ee60d8b 12 Dec 2025 avatar joomdonation CS
avatar AlterBrains
AlterBrains - comment - 12 Dec 2025

@joomdonation Many thanks for applying the changes, I am sure that we should add even small improvements with each PR to keep the code modern and efficient, but not just apply simple refactoring. There are not so many developers and PRs are not merged fast.
Agree, moving template logic into a separate utility service sounds great, but it's really time-cost effort right now. I still dislike private and final statements in open source code, along with implicit class name requirements, but we can leave with this class for now.

Add a Comment

Login with GitHub to post a comment