From bc85d2be3b1e8e07401e421eafee8d5ef1a383fd Mon Sep 17 00:00:00 2001 From: nordmograph Date: Sun, 2 Nov 2025 16:15:18 +0100 Subject: [PATCH 1/3] Do not get the profile info for the linked user when no user is linked The method loads the profile info for the linked user even when no user is linked ($contact->user_id == 0), loading unnecessary stuff (UserModel, form, data, plugin) for nothing. --- .../com_contact/src/Model/ContactModel.php | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/components/com_contact/src/Model/ContactModel.php b/components/com_contact/src/Model/ContactModel.php index 5aa1483f720f6..0fe6046cad2b0 100644 --- a/components/com_contact/src/Model/ContactModel.php +++ b/components/com_contact/src/Model/ContactModel.php @@ -365,26 +365,28 @@ protected function buildContactExtendedData($contact) } // Get the profile information for the linked user - $userModel = $this->bootComponent('com_users')->getMVCFactory() - ->createModel('User', 'Administrator', ['ignore_request' => true]); - $data = $userModel->getItem((int) $contact->user_id); - - PluginHelper::importPlugin('user'); - - // Get the form. - Form::addFormPath(JPATH_SITE . '/components/com_users/forms'); - - $form = Form::getInstance('com_users.profile', 'profile'); - - // Trigger the form preparation event. - Factory::getApplication()->triggerEvent('onContentPrepareForm', [$form, $data]); - - // Trigger the data preparation event. - Factory::getApplication()->triggerEvent('onContentPrepareData', ['com_users.profile', $data]); - - // Load the data into the form after the plugins have operated. - $form->bind($data); - $contact->profile = $form; + if ((int) $contact->user_id > 0) { + $userModel = $this->bootComponent('com_users')->getMVCFactory() + ->createModel('User', 'Administrator', ['ignore_request' => true]); + $data = $userModel->getItem((int) $contact->user_id); + + PluginHelper::importPlugin('user'); + + // Get the form. + Form::addFormPath(JPATH_SITE . '/components/com_users/forms'); + + $form = Form::getInstance('com_users.profile', 'profile'); + + // Trigger the form preparation event. + Factory::getApplication()->triggerEvent('onContentPrepareForm', [$form, $data]); + + // Trigger the data preparation event. + Factory::getApplication()->triggerEvent('onContentPrepareData', ['com_users.profile', $data]); + + // Load the data into the form after the plugins have operated. + $form->bind($data); + $contact->profile = $form; + } } /** From 92db54042da33d16da58ee0d98ad88f666311cc6 Mon Sep 17 00:00:00 2001 From: nordmograph Date: Mon, 3 Nov 2025 17:44:21 +0100 Subject: [PATCH 2/3] Check linked user_id for an early return Check linked user_id for an early return as suggested --- .../com_contact/src/Model/ContactModel.php | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/components/com_contact/src/Model/ContactModel.php b/components/com_contact/src/Model/ContactModel.php index 0fe6046cad2b0..523945b77bab6 100644 --- a/components/com_contact/src/Model/ContactModel.php +++ b/components/com_contact/src/Model/ContactModel.php @@ -365,28 +365,30 @@ protected function buildContactExtendedData($contact) } // Get the profile information for the linked user - if ((int) $contact->user_id > 0) { - $userModel = $this->bootComponent('com_users')->getMVCFactory() - ->createModel('User', 'Administrator', ['ignore_request' => true]); - $data = $userModel->getItem((int) $contact->user_id); - - PluginHelper::importPlugin('user'); - - // Get the form. - Form::addFormPath(JPATH_SITE . '/components/com_users/forms'); - - $form = Form::getInstance('com_users.profile', 'profile'); - - // Trigger the form preparation event. - Factory::getApplication()->triggerEvent('onContentPrepareForm', [$form, $data]); - - // Trigger the data preparation event. - Factory::getApplication()->triggerEvent('onContentPrepareData', ['com_users.profile', $data]); - - // Load the data into the form after the plugins have operated. - $form->bind($data); - $contact->profile = $form; + if (empty($contact->user_id)) { + return; } + + $userModel = $this->bootComponent('com_users')->getMVCFactory() + ->createModel('User', 'Administrator', ['ignore_request' => true]); + $data = $userModel->getItem((int) $contact->user_id); + + PluginHelper::importPlugin('user'); + + // Get the form. + Form::addFormPath(JPATH_SITE . '/components/com_users/forms'); + + $form = Form::getInstance('com_users.profile', 'profile'); + + // Trigger the form preparation event. + Factory::getApplication()->triggerEvent('onContentPrepareForm', [$form, $data]); + + // Trigger the data preparation event. + Factory::getApplication()->triggerEvent('onContentPrepareData', ['com_users.profile', $data]); + + // Load the data into the form after the plugins have operated. + $form->bind($data); + $contact->profile = $form; } /** From 8c3376fee6c54a6c7c5b604e88ee139ebf6b3e4d Mon Sep 17 00:00:00 2001 From: nordmograph Date: Mon, 3 Nov 2025 17:51:16 +0100 Subject: [PATCH 3/3] Reorder comments for clarity in ContactModel.php --- components/com_contact/src/Model/ContactModel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/com_contact/src/Model/ContactModel.php b/components/com_contact/src/Model/ContactModel.php index 523945b77bab6..dd0f3eb7e210e 100644 --- a/components/com_contact/src/Model/ContactModel.php +++ b/components/com_contact/src/Model/ContactModel.php @@ -364,11 +364,11 @@ protected function buildContactExtendedData($contact) $contact->articles = null; } - // Get the profile information for the linked user if (empty($contact->user_id)) { return; } - + + // Get the profile information for the linked user $userModel = $this->bootComponent('com_users')->getMVCFactory() ->createModel('User', 'Administrator', ['ignore_request' => true]); $data = $userModel->getItem((int) $contact->user_id);