-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Capability for plugins to modify group form in admin #16026
Description
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.userorcom_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.