J3 Issue ?
avatar Spudley
Spudley
15 May 2017

I have been trying to write a plugin that adds fields to the group admin form.

Unfortunately, it seems to be impossible to do this in Joomla as it stands.

Extending the user admin form is easy and well documented, via the user.onContentPrepareForm event. Since this event is also triggered by the group admin form, I would expect to be able to do something similar, but it doesn't work.

Steps to reproduce the issue

  • Write a user plugin with onContentPrepareForm() method.
  • Within the method, check the formname is either com_users.user or com_users.group.
  • Add a tab comtaining a new field to the form.

... something like this:

class plgUserFoobar extends JPlugin
{
    protected $baseXML = <<<'eof'
    <?xml version="1.0" encoding="utf-8"?>
    <form>
        <fields name="foo">
            <fieldset name="team" label="Foo">
                <field name="baz" type="text" label="Baz" />
            </fieldset>
        </fields>
    </form>
    eof;

    public function onContentPrepareForm($form, $data)
    {
        $formName = $form->getName();
        if ($formName != 'com_users.group' && $formname !='com_users.user') {
            return true;
        }
        $form->load($this->baseXML, false);
    }
}

Expected result

The admin panel forms for managing both users and groups should now have a new tab named 'Foo', comtaining a single text field labelled 'Baz'.

Actual result

The user form does indeed get the new tab and field, but the group form does not.

System information (as much as possible)

Joomla 3.7.0

Additional comments

Looking at the XML that defines the user and group forms, the group form is much simpler in structure; its <fieldset> element is not even named (and thus cannot be accessed by JForm::getGroup and similar methods). The user form has several fieldsets with a parent <fields> element to contain them; this element is not present in the groups form.

The result is that although $form->load() does work and the new formset/fields are loaded into the form object, the resulting XML structure does not match the initial structure of group form, and the fields are not rendered. I have tried numerous variations of the XML to try to get the structure right, but it doesn't seem to be possible.

avatar Spudley Spudley - open - 15 May 2017
avatar joomla-cms-bot joomla-cms-bot - change - 15 May 2017
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 15 May 2017
avatar franz-wohlkoenig franz-wohlkoenig - change - 15 May 2017
Category com_plugins
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 2 Sep 2017

@Spudley is this still a valid issue?

avatar franz-wohlkoenig franz-wohlkoenig - change - 2 Sep 2017
Status New Information Required
avatar Spudley
Spudley - comment - 2 Sep 2017

Hi @franz-wohlkoenig.

Yes, it is. Nothing has changed as far as I know that would have resolved it. It's fairly easy to verify though.

I had to work around it when I encountered the issue as I needed to complete the project I was working on, so I haven't looked back at it since posting it in May, but my solution is ugly and hacky and I would very much like to replace it with nice simply plugin with a tab in the group admin form if at all possible.

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 2 Sep 2017

@Spudley thanks for Comment. Hopefully this makes Progress.

avatar franz-wohlkoenig franz-wohlkoenig - change - 17 Sep 2017
Status Information Required Discussion
avatar brianteeman brianteeman - change - 25 Mar 2018
Labels Added: J3 Issue
avatar brianteeman brianteeman - labeled - 25 Mar 2018
avatar wilsonge
wilsonge - comment - 18 Aug 2018

Closed as we have a PR #21696

avatar wilsonge wilsonge - change - 18 Aug 2018
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2018-08-18 17:10:44
Closed_By wilsonge
avatar wilsonge wilsonge - close - 18 Aug 2018

Add a Comment

Login with GitHub to post a comment