Cold_Class
Cold_Class

Reputation: 3484

How to show different views depending on the fe_usergroup in Typo3 6.2 Extbase extension efficiently?

Right now I'm getting the currently logged-in user's usergroup(s) in my action-controller like this:

$roles = $GLOBALS['TSFE']->fe_user->groupData['title'];

I pass this information to my view and then do stuff like this:

<f:if condition="{0:role} == {0:'management'}">
...

I'm not sure if this is a good way...I think not - so I thought of this:
For example in: listAction():
Depending on the usergroup different properties should be shown.
I thought about working with sections there by naming them after a usergroup and doing something like this:

<f:for each="{appointments}" as="appointment">
 <f:render section="{0:role} arguments="{appointment:appointment}"/>
...

But I wonder if there's a better way...?
And how I could test my views the best way - my idea: If a have a test-user who belongs to all usergroups it would be nice to be able to switch my views while in the frontend to see if all the views work without having to log in with a different test user for a different usergroup everytime. The way I'm doing it it's not possible.

So my questions:

  1. Is my approach best practice or how could I make this even simpler and automated?
  2. Is there an easy way to test the views like I described with a test-user who belongs to all usergroups?

I searched around in the Typo3 Basics but couldn't find a solution or best practice to my problems.

Upvotes: 0

Views: 219

Answers (1)

Jigal van Hemert
Jigal van Hemert

Reputation: 722

You want to connect rights to see certain fields to groups. As people can be in more than one group the fields that a person can see can vary a lot. If you make sections / partials for each group you have to repeat a lot of fields in the templates. A more flexible way would be to first collect the fields that a user can see based on the various groups they are a member of. You could set in the settings of your extension which fields are visible for each group. In the controller you can combine the fields for all the groups of the user and finally pass the array of fields to the view. The view can simply iterate over the list and render each visible field.

Upvotes: 1

Related Questions