1

I'm creating a site that is an intranet portal for a company. All the users will be employees that work in different offices. I am adding several fields to the users to be used within the roster display. ie Cell phone, personal email, etc.

I will also have a content type of Office that will have fields relating to the individual locations. ie Address, phone, wifi code, etc.

I need to be able to display the full roster for any given office location. Views seem to be the way to go but getting the relationship between users and the offices is my problem. I know this is a pretty basic application but not something that I haven't done before.

What are possible ways to tie the office content type with the system users so that I can create a view that would have access to all of the fields from both content types?

1
  • Entity reference field in the user entity maybe? Welcome to Drupal Answers! You are stating specs and asking for the best of something. One is too broad and the latter is an opinion-based thing. But Drupal Answers is no forum. Drupal Answers seeks to provide canonical answers to narrowly scoped and detailed questions. Please update your question to provide a reproducible problem and what has been tried so far to solve it. Many thanks :)
    – leymannx
    Commented Jun 29, 2019 at 20:19

2 Answers 2

0

This is usually configured through an Entity Reference field. Either create one on People's accounts that references Content of the "Office" type, or create one on the Office Content type referencing Users.

In most cases it will make sense to create the reference on the People accounts. I guess it mostly depends on when the information is being added, to make it most user-friendly. It's more likely People will change their jobs than it is likely that Office information will change, so it's quickest to keep the that data with the person. The ER field will display on user profiles which Office the person belongs to (you can Manage display to turn it off).

Using Views you can create lists that display information in both directions, but you'll probably want the backwards direction of showing all the people referencing a particular office (list ER children that reference a particular parent).

You can do this by creating User type Views, adding a Contextual filter for the ER field and setting it to Provide the default value from the Content URL. There are many questions and answers about this with details about every step.

The ER field solution doesn't change access configuration. If you need to restrict what people belonging to different Offices are allowed to see then using Groups, as suggested in another answer, might help.

6
  • Thank you so much. This really lays out the task at hand nicely.
    – paulfm
    Commented Jun 30, 2019 at 23:03
  • I was able to successfully add the reference to the content type "Office" within the Users. I created a page view for the "Office" with a block view for the "Users" that used the reference to the Office to display the correct users for any given office based on the URL. Now the client is asking to display multiple offices on the same page. Ugg! I can certainly create a block view of the Offices but how can I now filter the correct users without using the URL?
    – paulfm
    Commented Jul 26, 2019 at 13:05
  • Add another Page Display to your views that will show all Offices. You'll need to override the Contextual settings for that display only, so the individual block keeps working as it was set up earlier. There are two strategies I can think of: 1. list all users as you already have, remove the contextual filter, add the Office Field to your Views, under Format choose the Office field under "Group by field", 2. just change the Contextual filter from providing default value to a "Summary", don't forget to include your path in there, this will list Office links, click through for people list.
    – prkos
    Commented Jul 26, 2019 at 14:19
  • What I thought was going to be easier was to create pages using paragraphs that allowed inserting views. I am then able to send the Argument of each office to the block view. This works great to display the office as a block. The problem is that some of the Users are tied to more than one office and they show up multiple times for each individual office that they are part of. Not sure why this is happening. If I can get past this bump I will be good to go! Using the "aggregation" option does not seem viable.
    – paulfm
    Commented Jul 28, 2019 at 14:53
  • Paragraphs are reference fields. It doesn't matter how you pull the Views to be displayed on a page, you still have to take care of the Views Contextual filters if you want to make it work, it doesn't happen automatically. Multiple results can happen with Relationships, you can use Distinct in SQL settings or Aggregation with proper field settings. There are answers you can search through to help you with that.
    – prkos
    Commented Jul 28, 2019 at 20:38
0

Sounds like a perfect usecase for the Group module, whereas you'd use a group type like Offices. And so that you create 1 group (of group type Offices). From then on you have the Group permission system to configure access rules to fit your needs.

And BTW, this can be for either D7 or D8.

5
  • Groups are great if you need to keep the content between groups separate and with different user role access, but it can be an overkill if everything is allowed to be viewed by everyone.
    – prkos
    Commented Jun 30, 2019 at 9:35
  • @prkos I trust you mean "Group", not "Groups" ... Also, the overkill you mentioned may not apply if you know how to correctly use the permissions for what in Group is called the Outsiders. Commented Jul 4, 2019 at 18:01
  • I was naming entities, not the module. I'm sorry for the confusion, Group is the module. I didn't know about Outsiders, it sounds very useful! I'm glad to see the Group module is getting new features.
    – prkos
    Commented Jul 4, 2019 at 18:28
  • @prkos to my knowldge, "Outsiders" have always been one of the key concepts of the Group module. Refer to this answer (disclosure: it's mine ...) for a few more details on that. Commented Jul 4, 2019 at 18:50
  • I think I may have melded Group and Organic groups in my memory, I haven't used either lately. I'll have to try it out and compare with the ER solution. Thank you for the answer link!
    – prkos
    Commented Jul 4, 2019 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.