0

I'm trying to load a plugin's form into my component form in Joomla4. So my components getForm method is:

$form = $this->loadForm(
    'com_mycomponent.member',
    'memberform',
    array( 'control'   => 'jform', 'load_data' => $loadData )
);

Now I wish to get any possible custom user profile plugin based on a suffix added to the profile name. So if there is a custom profile plugin with the suffix "abc" then I want to get the form located at:

JPATH_SITE.'plugins/user/profileabc/forms'

I've tried the following with no success:

$this->loadForm('plg_user_profileabc','profileabc');

$this->loadForm('plg_user_profileabc','profileabc');

Form::loadFile(JPATH_SITE.'plugins/user/profileabc/forms/profileabc');

And I guess the second part of the process is to actually "merge" the forms into one? Any advice/guidance gratefully appreciated.

2
  • What's the reason you need the component to load the plugin form? Misusing plugins like this is generally a bad idea. The plugin should be loading its form into the component.
    – Sharky
    Sep 25 at 9:01
  • Hmmm, ok so I should rethink this a bit. I'm trying to cater for unknown profile plugins that may be present other than the ones I create. My component (members listing) for clubs so their membership secretary can do some basic updates. So when they click on a member record for updating it will show the basics plus load any profile plugin forms as necessary. @Carlitorweb - thanks this at least doesn't give me any errors and is reasonably simple when you show it to me like this, thanks. Sep 26 at 2:47
1

If I got it right, you need first check if that plugin exists. If he does, then add the plugin form folder to the global list of form paths and then load the .xml form file.

use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Form\FormHelper;

/** 
 * Check if the plugin you looking for exists, then add the form he hold
 *
 * string  $type The plugin type, relates to the subdirectory in the plugins directory.
 * string  $plugin  The plugin name.
 *
if(PluginHelper::isEnabled($type, $plugin)) {

   // Add the form path to the list of form include paths
   FormHelper::addFormPath(JPATH_PLUGINS . '/user/profileabc/forms');

   // Load the file
   $form->loadFile('profileabc');

   // rest of the code.....
   
}
2
  • This has worked a treat thanks. The next part is loading the data to the form? In the loadFormData() step I'm using the UserHelper::getProfile($data->id) to get all profile data and loading each element to the $data array, but the data doesn't show in the form? Again any help here is appreciated. Cheers. Sep 26 at 22:55
  • @GlennArkell reading now the comment you wrote to Sharky, I think you need handle this extra form, from the plugin, and not from the component itself. So, the component will handle the basic form, and each plugin will add the extra form. If you follow this, then you need use the event onContentPrepareForm(Form $form, $data) and put there part of the code I shared before (except the condition check, you will no need it inside the plugin). Then use the event onContentPrepareData($context, $data) for accomplish the next part you wanted do with the loadFormData() Sep 27 at 20:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.