1

I am trying to write a Joomla plugin to add fields to the user group admin form.

I have previously written plugins that have added a new tab to the user form. This is possible by having a plugin with the onContentPrepareForm method, and calling $form->load() or $form->loadFile() to inject the XML for the new tab of fields into the existing form.

As I say, this works well for the user form, but does absolutely nothing at all on the group form.

I have written a plugin, referenced the form name as com_users.group, and called $form->load() to inject my form XML. The XML is valid and no errors are reported, but the new form fields do no show up.

I guess that this is because the user form is already defined with multiple tabs, whereas the group form is much simpler and is not.

I've also tried adding the individual fields to the existing form (with without creating a new tab) by using $form->setField(), but this also isn't having any effect.

In either case, when I do a var_dump($form) after injecting my fields, I can see the new fields in the form's XML object structure, but they are not in the right place in the structure, which I guess is why they're not showing up.

Can anyone help point me in the right direction here? It's getting quite frustrating.

Thank you.

1
  • For now I've admitted defeat on this one -- I haven't found a solution other than actually editing the core to make group admin work more like user admin form. I don't think I have the time for that right now so I'm going to have to put this whole thing on the back-burner.
    – Simba
    May 15, 2017 at 14:24

1 Answer 1

1

The group edit.php template file won't render any additional fields that might exist on the form, as it seems to be quite simple and somewhat static.

Likely you are going to need a template override, where you will iterate over the custom fields of your fieldset and render them.

Under the core fields, something like below could work:

<?php foreach ($this->form->getFieldset('YOUR_CUSTOM_FIELDSET') as $field) : ?>
    <div class="control-group">
        <div class="control-label">
            <?php echo $field->label; ?>
        </div>
        <div class="controls">
            <?php echo $field->input; ?>
        </div>
    </div>
<?php endforeach; ?>
5
  • Thanks for the reply. That's kinda the direction I was heading with it although I'm not sure how to set it up with in the plugin -- would I eveb be able to include a template override with my plugin? I want this to be simple to install but it sounds like it'll make the plugin a fair bit more complex.
    – Simba
    May 12, 2017 at 13:10
  • Which version of Joomla? Now that 3.7 is out, custom fields are much easier to add.
    – James
    May 12, 2017 at 18:17
  • @JamesShaver, the case is similar for jcustom fields - the way user.group is now isn't supporting it - and jcustom fields aren't available for user.group. It looks like J doesn't think a user.group will ever need other fields than it's name.
    – FFrewin
    May 12, 2017 at 18:24
  • @Simba, it doesn't sound good idea to include the override with the installation. I thought this would be a custom implementation for a single site. If you are going to make the plugin available for many installations, maybe better ship it with instructions on how to place the override for those that will need the functionality you are going to provide with this plugin.
    – FFrewin
    May 13, 2017 at 6:00
  • For now I've admitted defeat on this one -- I haven't found a solution other than actually editing the core to make group admin work more like user admin form. I don't think I have the time for that right now so I'm going to have to put this whole thing on the back-burner.
    – Simba
    May 15, 2017 at 14:24

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.