Jump to content

Add user filter to inputtype page field selector


gebeer
 Share

Recommended Posts

Hi,

I'm trying to setup a page field with a custom selector.

Intention is to show only pages of the currently logged in user in the select drop down.

Here's what I tried in the field setup:

post-1920-0-24886600-1412587546_thumb.pn

I also tried

post-1920-0-73848400-1412588514_thumb.pn

But I guess this doesn't make a lot of sense because when the page is created and has not been saved yet, the $page->createdUser isn't there yet.

I always get an empty select

post-1920-0-17544100-1412587623_thumb.pn

It seems like the page field is not aware of the $user object.

Is there any way how I could filter the pages by created_users_id, maybe through a hook on that field?

Link to comment
Share on other sites

  • 5 months later...

Had some similar issue but it won't work and don't know why?

$mr = wire('user')->user_mr; //a integer field on the user template
$test = "4702";  //thats the value from the field user_mr
return $pages->find("has_parent=$test");  //$test word $mr not??

user_mr is an simple integer field on the $user template...

With the $test id it works and show all children of this parent...with $mr it shows blank?

regards mr-fan

Link to comment
Share on other sites

Maybe this could help you debugging.  

$mr = wire('user')->user_mr;

$p = new Page();
$p->template = "basic-page";
$p->parent = $pages->get("/");

$p->title = $mr; // See what value $mr has
// $p->title = $mr == "4702" ? "Is 4702" : "Is not 4702"; // alternative

$pa = new PageArray();
$pa->import($p);

return $pa;
  • Like 1
Link to comment
Share on other sites

Had some similar issue but it won't work and don't know why?

$mr = wire('user')->user_mr; //a integer field on the user template
$test = "4702";  //thats the value from the field user_mr
return $pages->find("has_parent=$test");  //$test word $mr not??

user_mr is an simple integer field on the $user template...

With the $test id it works and show all children of this parent...with $mr it shows blank?

regards mr-fan

$mr = wire('user')->user_mr;
return $pages->find("has_parent=$mr");

Your code works for me as is...maybe you have a typo somewhere?

  • Like 1
Link to comment
Share on other sites

Sorry for that...shame on me! Wrong field wrong place

thank you very much LostKobrakai for the debug option in the PageField Settings - this should be a PW recipe it's great for debugging this kind of setting!

it was the wrong field -> the $user gives me the logged in user - but i need not the user - just a setting of this kind of "profile" == "the $page" i'm are editing and in the user template i've just the connection to this profile but this doesn't work so i need something like this:

$mr = $page->MR_Kunde->id; //we are working on this profile template for the user and wanna check the reference for a pagefield
return $pages->find("template=Betrieb, has_parent=$mr");

anyway it works like a charm and the forum get a new important snippet to debug entries in the PHP Code selection of Pages for a Pagefield ;)

Thank you again.

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...