J4 How to handle tables xref (map) on load and save data to DB

14 views
Skip to first unread message

GhiaMar

unread,
Jul 13, 2022, 9:05:49 AM7/13/22
to Joomla! General Development
Hi! I need to be able to filter my component Content admin list according to the admin logged in and his user group, if Super User, can see all content of my component, if it's added to specific group or his childs, then can only see his own created content and other same group users content, for that I think this table structure should work.

#__com_mycomponent_contents
  • id
  • title
  • slug
  • Other table fields
#__com_mycomponent_contents_user_map
I want to be able to get the associated user id's from each content using the contents_user_map table and to store that associations on content save.

So far,  I have added this field in my Content form
<field
  name="allowed_content_users"
  type="contentuserlist" // custom field that gets all users name and id
  label="Allowed Users"
  multiple="true"
  layout="joomla.form.field.list-fancy-select"
/>


Also added this field to the Content edit.php tmpl file, so far so good, the field appears but on save, I can't see that field in the ContentTable.php file in the store method

How can I solve this, or there is a more Joomla way to handle auxiliary tables (xref, map tables)

Thanks!


MarkRS

unread,
Jul 13, 2022, 9:40:36 AM7/13/22
to Joomla! General Development
Looks to me that it would be better to add a "usergroup(id)" field to your content.

GhiaMar

unread,
Jul 13, 2022, 9:55:40 AM7/13/22
to Joomla! General Development
Hi @MarkRS Thanks for the tip, will look into that!

GhiaMar

unread,
Jul 13, 2022, 10:49:53 AM7/13/22
to Joomla! General Development
Yes, you are right, it's perfect for my model to have a group assigned to the content, thenn all users from that group can list/edit content, and users from another group can tamper other user groups content, but only Super Admins can see all contents from all groups!

My form field now looks like this
<field
name="allowed_user_group"
type="usergrouplist"
label="Allowed User Group"
/>


Thanks in advise!

Reply all
Reply to author
Forward
0 new messages