Jump to content

Set PHP-Selector for pagefield with predefined default value


Orkun
 Share

Recommended Posts

Hello Processwire Community

Lets say i have a pagefield called select_organiser. The select_organiser pagefield is assigned to the user template and to the location template. Every User can create a location where he can set a organiser with the select_organiser pagefield. The Superuser can also create locations and he can assign a organisation to a user.

No what i want is that the pagefield should check if the current user is a superuser, when yes he get a selection of all organiser pages. But when the current user is not a superuser he should get only a selection/select of the organiser that the Superuser has assigned to him.

for example:

organiser pages:

organiser-example-1

organiser-example-2

organiser-example-3

organiser-example-4

...

users:

test-user-1

test-user-2

...

Lets say I am the Superuser and i assign organiser-example-1 to the user test-user-1.

Use Case: Create Location as Superuser

I have a select with the selection: (organiser-example-1, organiser-example-2, organiser-example-3, organiser-example-4 ...)

Use Case: Create Location as test-user-1

I have a select only with the selection: (organiser-example-1).

This means I can only create Locations with the organiser: organsier-example-1.

I hope you understand what i want to say/ask. :)

Link to comment
Share on other sites

This should do the work:

if(wire('user')->isSuperuser()){
    return $pages->find("template=organiser");
}
else{
    return $pages->find("template=organiser, id=".wire('user')->select_organiser);
}
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...