[BUG]: usergroup field doesn't work when compiling towards Joomla 4 (works in J3) #1100

Open
opened 2024-03-27 22:16:23 +00:00 by dyvel · 6 comments

What Happened?

I added a field of type usergroup to the demo project look view. When I compile towards Joomla 3, I can see and select the usergroups as expected. However, when I compile towards Joomla 4, the field is just blank.

Steps to reproduce the Bug

Create a field of type usergroup and add it to a view, then compile towards Joomla 4.

Which Joomla version are you compiling in?

3.10.12

Which PHP version are you compiling in?

8.1.27

Which Joomla versions are you targeting?

4

Which PHP version are you targeting?

8.1

Which Web server is JCB running on?

Apache 2.4

Which Relational Database is JCB running on?

MariaDB 10.4

Which OS is JCB running on?

Ubuntu 20.4

Which JCB version are you using?

3.2.0 stable

Which Joomla version is JCB installed on?

Joomla 3

Where in JCB did this issue occur?

Joomla Component(admin_view)

On which browsers did you encounter the issue?

Safari

Additional Comments

No response

### What Happened? I added a field of type usergroup to the demo project look view. When I compile towards Joomla 3, I can see and select the usergroups as expected. However, when I compile towards Joomla 4, the field is just blank. ### Steps to reproduce the Bug Create a field of type usergroup and add it to a view, then compile towards Joomla 4. ### Which Joomla version are you compiling in? 3.10.12 ### Which PHP version are you compiling in? 8.1.27 ### Which Joomla versions are you targeting? 4 ### Which PHP version are you targeting? 8.1 ### Which Web server is JCB running on? Apache 2.4 ### Which Relational Database is JCB running on? MariaDB 10.4 ### Which OS is JCB running on? Ubuntu 20.4 ### Which JCB version are you using? 3.2.0 stable ### Which Joomla version is JCB installed on? Joomla 3 ### Where in JCB did this issue occur? Joomla Component(admin_view) ### On which browsers did you encounter the issue? Safari ### Additional Comments _No response_
dyvel added the
Bug
label 2024-03-27 22:16:23 +00:00
Member

I had the same problem.
After some digging, I find out that this problem is resolvable without coding.
Joomla website: Since Joomla 3.2 use usergrouplist instead.

General steps:

  1. Go to your Joomla website admin where you're using JCB
  2. Then Components > Component Builder > Fieldtypes
  3. Click on New button and create a new Fieldtype base on Joomla Docs / User Group List form field type or use below SQL insert query (change "<db_prefix>" to your db prefix):
INSERT INTO `<db_prefix>__componentbuilder_fieldtype` (`id`, `description`, `name`, `properties`, `short_description`, `params`, `published`, `version`, `hits`, `ordering`, `guid`)
VALUES (45,
		'Field to load a drop down list of available user groups.',
		'Usergrouplist',
		'{\"properties0\":{\"name\":\"type\",\"example\":\"usergrouplist\",\"mandatory\":\"1\",\"description\":\"(mandatory) must be usergrouplist.\"},\"properties1\":{\"name\":\"name\",\"example\":\"usergrouplist\",\"adjustable\":\"1\",\"mandatory\":\"1\",\"description\":\"(mandatory) is the unique name of the field. This must match the name of the query results column that contains the values that will be shown to the user in the drop-down list, unless a different name is specified in the value_field attribute.\"},\"properties2\":{\"name\":\"label\",\"example\":\"Group List\",\"adjustable\":\"1\",\"mandatory\":\"1\",\"translatable\":\"1\",\"description\":\"(mandatory) (translatable) is the descriptive title of the field.\"},\"properties3\":{\"name\":\"description\",\"example\":\"Select a group\\\/groups\",\"adjustable\":\"1\",\"translatable\":\"1\",\"description\":\"(optional) (translatable) is text that will be shown as a tooltip when the user moves the mouse over the drop-down box.\"},\"properties4\":{\"name\":\"layout\",\"example\":\"\",\"adjustable\":\"1\",\"description\":\"(optional) (translatable) is the layout, for example joomla.form.field.list-fancy-select.\"},\"properties5\":{\"name\":\"checksuperusergroup\",\"example\":\"\",\"adjustable\":\"1\",\"description\":\"(optional) is boolean to omit Super User groups. Values 1 or 0.\"},\"properties6\":{\"name\":\"default\",\"example\":\"\",\"adjustable\":\"1\",\"description\":\"(optional) is the usergroup id of the default selection in the dropdown list.\"},\"properties7\":{\"name\":\"multiple\",\"example\":\"\",\"adjustable\":\"1\",\"description\":\"(optional) If set to true then allows more than one usergroup to be selected.\"},\"properties8\":{\"name\":\"required\",\"example\":\"\",\"adjustable\":\"1\",\"description\":\"(optional) is the field required true if yes.\"},\"properties9\":{\"name\":\"showon\",\"example\":\"\",\"adjustable\":\"1\",\"description\":\"(optional) show this field on the bases of the value in another field. https:\\\/\\\/joomla.stackexchange.com\\\/a\\\/17682\\\/2166\"},\"properties10\":{\"name\":\"class\",\"example\":\"\",\"adjustable\":\"1\",\"description\":\"(optional) is a CSS class name for the HTML form field. If omitted this will default to ''inputbox''.\"},\"properties11\":{\"name\":\"labelclass\",\"example\":\"\",\"adjustable\":\"1\",\"description\":\"Adding the attribute labelclass adds a CSS class for form field''s label. Source: http:\\\/\\\/joomlacode.org\\\/gf\\\/project\\\/joomla\\\/tracker\\\/?action=TrackerItemEdit&tracker_item_id=28450\"}}',
		'Field to load a drop down list of available user groups.',
		'',
		1,
		1,
		'',
		'',
		'3213a9e4-b1a9-40ae-a5bf-31788bb4e27c');
  1. Go to Component Builder > Fields
  2. Edit fields with type Usergroup. Change their type to Usergrouplist that you just created. Save.
  3. Compile & Enjoy JCB

@Llewellyn, I think this problem could be resolved by adding this insert query to #__componentbuilder_fieldtype multiple insert query in install.mysql.utf8.sql and also adding it to 3.2.0-beta.sql.
I wanted to send a Pull Request to fix this problem. May I? Could you give me Pull Request permission please?
Or you could fix it yourself, that's totally cool too 😀

I had the same problem. After some digging, I find out that this problem is resolvable without coding. [Joomla website](https://docs.joomla.org/Standard_form_field_types): Since Joomla 3.2 use usergrouplist instead. General steps: 1. Go to your Joomla website admin where you're using JCB 2. Then Components > Component Builder > Fieldtypes 3. Click on New button and create a new Fieldtype base on Joomla [Docs / User Group List form field type](https://docs.joomla.org/User_Group_List_form_field_type) or use below SQL insert query (change "<db_prefix>" to your db prefix): ```sql INSERT INTO `<db_prefix>__componentbuilder_fieldtype` (`id`, `description`, `name`, `properties`, `short_description`, `params`, `published`, `version`, `hits`, `ordering`, `guid`) VALUES (45, 'Field to load a drop down list of available user groups.', 'Usergrouplist', '{\"properties0\":{\"name\":\"type\",\"example\":\"usergrouplist\",\"mandatory\":\"1\",\"description\":\"(mandatory) must be usergrouplist.\"},\"properties1\":{\"name\":\"name\",\"example\":\"usergrouplist\",\"adjustable\":\"1\",\"mandatory\":\"1\",\"description\":\"(mandatory) is the unique name of the field. This must match the name of the query results column that contains the values that will be shown to the user in the drop-down list, unless a different name is specified in the value_field attribute.\"},\"properties2\":{\"name\":\"label\",\"example\":\"Group List\",\"adjustable\":\"1\",\"mandatory\":\"1\",\"translatable\":\"1\",\"description\":\"(mandatory) (translatable) is the descriptive title of the field.\"},\"properties3\":{\"name\":\"description\",\"example\":\"Select a group\\\/groups\",\"adjustable\":\"1\",\"translatable\":\"1\",\"description\":\"(optional) (translatable) is text that will be shown as a tooltip when the user moves the mouse over the drop-down box.\"},\"properties4\":{\"name\":\"layout\",\"example\":\"\",\"adjustable\":\"1\",\"description\":\"(optional) (translatable) is the layout, for example joomla.form.field.list-fancy-select.\"},\"properties5\":{\"name\":\"checksuperusergroup\",\"example\":\"\",\"adjustable\":\"1\",\"description\":\"(optional) is boolean to omit Super User groups. Values 1 or 0.\"},\"properties6\":{\"name\":\"default\",\"example\":\"\",\"adjustable\":\"1\",\"description\":\"(optional) is the usergroup id of the default selection in the dropdown list.\"},\"properties7\":{\"name\":\"multiple\",\"example\":\"\",\"adjustable\":\"1\",\"description\":\"(optional) If set to true then allows more than one usergroup to be selected.\"},\"properties8\":{\"name\":\"required\",\"example\":\"\",\"adjustable\":\"1\",\"description\":\"(optional) is the field required true if yes.\"},\"properties9\":{\"name\":\"showon\",\"example\":\"\",\"adjustable\":\"1\",\"description\":\"(optional) show this field on the bases of the value in another field. https:\\\/\\\/joomla.stackexchange.com\\\/a\\\/17682\\\/2166\"},\"properties10\":{\"name\":\"class\",\"example\":\"\",\"adjustable\":\"1\",\"description\":\"(optional) is a CSS class name for the HTML form field. If omitted this will default to ''inputbox''.\"},\"properties11\":{\"name\":\"labelclass\",\"example\":\"\",\"adjustable\":\"1\",\"description\":\"Adding the attribute labelclass adds a CSS class for form field''s label. Source: http:\\\/\\\/joomlacode.org\\\/gf\\\/project\\\/joomla\\\/tracker\\\/?action=TrackerItemEdit&tracker_item_id=28450\"}}', 'Field to load a drop down list of available user groups.', '', 1, 1, '', '', '3213a9e4-b1a9-40ae-a5bf-31788bb4e27c'); ``` 4. Go to Component Builder > Fields 5. Edit fields with type Usergroup. Change their type to Usergrouplist that you just created. Save. 6. Compile & Enjoy JCB @Llewellyn, I think this problem could be resolved by adding this insert query to `#__componentbuilder_fieldtype` multiple insert query in `install.mysql.utf8.sql` and also adding it to `3.2.0-beta.sql`. I wanted to send a Pull Request to fix this problem. May I? Could you give me Pull Request permission please? Or you could fix it yourself, that's totally cool too 😀
Owner

Since field_types are all DB maintained we currently do not update existing Installs. We are working on an option to also maintain this the way we do powers. So you have power => [init] and power => [reset] in the the Powers list view, we are planning to add this to the field_types as well but this is not yet finished.

I can fix the Usergrouplist so that it will be correct with new JCB installs, but adding an update script to the install is not the direction we would like to take to resolve this going forward.

And I done not want these kind of links in this area of JCB: http:\\\/\\\/joomlacode.org\\\/gf\\\/project\\\/joomla\\\/tracker\\\/?action=TrackerItemEdit&tracker_item_id=28450

Since field_types are all DB maintained we currently do not update existing Installs. We are working on an option to also maintain this the way we do powers. So you have `power => [init]` and `power => [reset]` in the the **Powers list** view, we are planning to add this to the field_types as well but this is not yet finished. I can fix the `Usergrouplist` so that it will be correct with **new JCB installs**, but adding an update script to the install is **not the direction** we would like to take to resolve this going forward. And I done not want these kind of links in this area of JCB: `http:\\\/\\\/joomlacode.org\\\/gf\\\/project\\\/joomla\\\/tracker\\\/?action=TrackerItemEdit&tracker_item_id=28450`
Member

I'm having an problem with the usergrouplist field in version 4.0.3-alpha2. The field works and saves correctly but when using a usergrouplist field and showing it in a admin view list it crashesimage
The culprit seems to be this line in /web/administrator/components/COMPONENTNAME/src/Model
image
Changing the line to this fixes the error:
image
I can't find a spot to override this line (which is fair) so for now i just have to change the files and make them readonly so updates don't change them back.

I'm having an problem with the usergrouplist field in version 4.0.3-alpha2. The field works and saves correctly but when using a usergrouplist field and showing it in a admin view list it crashes![image](/attachments/637b5424-a8c5-4940-817e-7e2f5c4da397) The culprit seems to be this line in /web/administrator/components/COMPONENTNAME/src/Model ![image](/attachments/b7b0265d-8300-4eb0-ba5e-4d7b5e983221) Changing the line to this fixes the error: ![image](/attachments/d6ac052e-b212-4a72-8ce2-0316d66cfceb) I can't find a spot to override this line (which is fair) so for now i just have to change the files and make them readonly so updates don't change them back.
Owner

There is a catch for the usergroup and it might be because we now have a different name... that it ends up instead triggered the generic code. Since it should validate true for usergroup field type on line 20680. So if you change the 20680 lines to:

				if (($item['type'] === 'usergroup'  || $item['type'] === 'usergrouplist') && !$export
					&& $item['method'] != 6)
				{

This should resolve the issue... I will add the update to the next stable release, if you can confirm its fixed. There might be more areas... I will search the compiler and ensure to catch all these tweaks for the usergroup field type.

There is a [catch for the usergroup](https://git.vdm.dev/joomla/Component-Builder/src/commit/045e6df2e23596cce4de5ef29e22b401baa40122/libraries/vendor_jcb/VDM.Joomla/src/Componentbuilder/Compiler/Helper/Interpretation.php#L20680-L20706) and it might be because we now have a different name... that it ends up [instead triggered the generic code](https://git.vdm.dev/joomla/Component-Builder/src/commit/045e6df2e23596cce4de5ef29e22b401baa40122/libraries/vendor_jcb/VDM.Joomla/src/Componentbuilder/Compiler/Helper/Interpretation.php#L20941-L20955). [Since it should validate true for usergroup field type on line 20680](https://git.vdm.dev/joomla/Component-Builder/src/commit/045e6df2e23596cce4de5ef29e22b401baa40122/libraries/vendor_jcb/VDM.Joomla/src/Componentbuilder/Compiler/Helper/Interpretation.php#L20680). So if you change the 20680 lines to: ``` if (($item['type'] === 'usergroup' || $item['type'] === 'usergrouplist') && !$export && $item['method'] != 6) { ``` This should resolve the issue... I will add the update to the next stable release, if you can confirm its fixed. There might be more areas... I will search the compiler and ensure to catch all these tweaks for the usergroup field type.
Member

Yes that seems to fix the issue! A final thing i see is that i have selected the usergrouplist field to sortable,searchable and filter. image
But the filtering does not appear, and sorting doesn't work either.
image
Searching in the search field gives an error due to this:
image
a.usergroup does not exists, as it should be a.fieldname where fieldname is set in the field defenition
Not the biggest issue in the world, just means you can't have the search box ticked for usergrouplist fields.

Yes that seems to fix the issue! A final thing i see is that i have selected the usergrouplist field to sortable,searchable and filter. ![image](/attachments/10f3333c-cc33-497c-9c5b-ffcdd0f7bcfa) But the filtering does not appear, and sorting doesn't work either. ![image](/attachments/cb3f672b-61b6-4192-a5f8-001d4efa1bc2) Searching in the search field gives an error due to this: ![image](/attachments/574a4b5b-4bcb-4419-8ba6-5d012510c828) a.usergroup does not exists, as it should be a.fieldname where fieldname is set in the field defenition Not the biggest issue in the world, just means you can't have the search box ticked for usergrouplist fields.
Owner

Yes a found a few more places this needs updating, I am nearly ready to push out another alpha release, with these fixes.

Yes a found a few more places this needs updating, I am nearly ready to push out another alpha release, with these fixes.
Sign in to join this conversation.
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#1100
No description provided.