PR-6.2-dev Pending

User tests: Successful: Unsuccessful:

avatar sshekhar563
sshekhar563
14 Apr 2026

Pull Request resolves #46369.

  • I read the Generative AI policy and my contribution is either not created with the help of AI or is compatible with the policy and GNU/GPL 2 or later.

Summary of Changes

Addresses the caching concerns raised in #46369 regarding the removal of getInstance() methods, following the approach suggested by @HLeithner in the review of PR #46428.

1. Subform Registry in Form class (libraries/src/Form/Form.php)

  • Adds a $subforms property to hold cached child Form instances within the parent form context
  • Adds getSubForm(), setSubForm(), hasSubForm(), and clearSubForms() methods
  • Caching is local to the Form object — no global static state or super globals

2. SubformField integration (libraries/src/Form/Field/SubformField.php)

  • loadSubForm() now checks the parent form's subform registry before calling Form::getInstance()
  • loadSubFormData() similarly uses the registry for per-row subform instances
  • Newly loaded subforms are stored back in the parent form's registry for reuse

3. Per-request user caching in UserFactory (libraries/src/User/UserFactory.php)

  • Adds per-request identity map ($cacheById and $cacheByUsername) using protected properties
  • loadUserById() returns cached User instance if already loaded during current request
  • loadUserByUsername() benefits from the same cache
  • Adds clearCache() method for explicit cache invalidation
  • Only caches valid users (!empty($user->id))

Testing Instructions

  1. Install Joomla with this branch
  2. Create an article with a subform field (e.g., custom fields with repeatable/subform type)
  3. Verify that subforms load correctly and display properly
  4. Edit a user profile, verify user data loads without repeated DB queries
  5. Check that user management (list, edit, save) works as expected
  6. Test with components that use multiple user lookups (e.g., article listing showing author names)

Actual result BEFORE applying this Pull Request

  • FormFactory::createForm() creates a new Form instance every time, no caching — causes repeated XML parsing for the same subform source
  • UserFactory::loadUserById() creates a new User instance and performs a DB query every time — causes repeated DB queries for the same user within a single request

Expected result AFTER applying this Pull Request

  • Subforms loaded via SubformField are cached in the parent Form's subform registry and reused within the same form context
  • User instances are cached per-request in UserFactory — subsequent calls for the same user ID return the cached instance without a DB query
  • All existing functionality continues working without BC breaks

Link to documentations

Please select:

  • Documentation link for guide.joomla.org:

  • No documentation changes for guide.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

avatar sshekhar563 sshekhar563 - open - 14 Apr 2026
avatar sshekhar563 sshekhar563 - change - 14 Apr 2026
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 14 Apr 2026
Category Libraries
avatar brianteeman
brianteeman - comment - 14 Apr 2026

There was a reason that you were given a template to complete when you submitted your PR. Please update the pr description accordingly. You can find the template here https://github.com/joomla/joomla-cms/blob/6.2-dev/.github/PULL_REQUEST_TEMPLATE.md

avatar sshekhar563 sshekhar563 - change - 14 Apr 2026
Labels Added: PR-6.2-dev
avatar sshekhar563 sshekhar563 - change - 14 Apr 2026
The description was changed
avatar sshekhar563 sshekhar563 - edited - 14 Apr 2026
avatar sshekhar563 sshekhar563 - change - 14 Apr 2026
The description was changed
avatar sshekhar563 sshekhar563 - edited - 14 Apr 2026
avatar sshekhar563 sshekhar563 - change - 14 Apr 2026
The description was changed
avatar sshekhar563 sshekhar563 - edited - 14 Apr 2026
avatar sshekhar563
sshekhar563 - comment - 15 Apr 2026

Thanks @richard67! All feedback addressed:

  • Replaced all @since 6.2.0 with __DEPLOY_VERSION__ across both Form.php and UserFactory.php
  • Fixed PHPCS alignment for = signs in loadUserById() and clearCache()

Add a Comment

Login with GitHub to post a comment