1

I have a custom profile plugin to extend user profile data. I want to add a switch to hide all BUT the core group of fields when the user checks and edits their profile. In my plugin (profileabc.php) file, within the function I have the following:

public function onContentPrepareForm(Form $form, $data) { // Check we are manipulating a valid form. $name = $form->getName(); $limit_pw = $this->params->get('limit_pw', 0); if ($limit_pw) { $fsets = $form->getFieldsets(); foreach ($fsets as $fgroup) { if ($fgroup !== 'core') { $form->removeGroup($fgroup); } } // do nothing regarding the custom profile data return true; } .... 

This works brilliantly except, the custom fields group/s remain exposed and accessible. Any guidance appreciated. Cheers.

1 Answer 1

3

I don't think it's safe to remove field groups based on fieldset names. They are unrelated and could be named differently, leading to unexpected results. And that is exactly the issue you're running into. The fieldsets of Custom Fields are named fields-0, fields-1 and so on based number of custom field groups (the ones you can create in backend). Meanwhile, the form field group is com_fields. So you have to remove this group manually:

$form->removeGroup('com_fields'); 

Or find a way to get the names of all field groups instead of fieldsets.

1
  • Thanks for this, works a treat. Cheers. Commented Jan 28, 2022 at 7:21

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.