Karl_T Posted October 14, 2016 Posted October 14, 2016 I have a template that contains a select option field using fieldtype Page. I want to hide some options by some logics. How can I add hook to make the change? I tried every hookable method of FieldTypePage but no luck. Thanks.
Robin S Posted October 15, 2016 Posted October 15, 2016 Can you incorporate the logic into "Custom PHP code to find selectable pages"?
Karl_T Posted October 15, 2016 Author Posted October 15, 2016 7 hours ago, Robin S said: Can you incorporate the logic into "Custom PHP code to find selectable pages"? Thanks for your reply. I have also used PaegEditPerUser module which offers a $user->editable_pages array in the code below. I have tried using the Custom PHP like this: $p = new PageArray(); $editable_pages = $user->editable_pages; $branches = $pages->find("template=branch"); foreach($branches as $branch){ foreach ($editable_pages as $edit) { if($branch->id == $edit->id){ $p->add($branch); } } } return $p; I tested and this gives correct output in normal template. However, it gives "Error: Class 'PageArray' not found" when I try to enter edit. Then, I tried to remove the PageArray and change the code to: $p = []; $editable_pages = $user->editable_pages; $branches = $pages->find("template=branch"); foreach($branches as $branch){ foreach ($editable_pages as $edit) { if($branch->id == $edit->id){ $p=$branch; } } } return $p; This gives no error, but also no output. I suspect that the Custom PHP is not able to read the $user object so as the PageArray.
horst Posted October 15, 2016 Posted October 15, 2016 Which PW version do you use? (namespaced or not) or simply try this: $p = new Processwire\PageArray(); // added namespace $editable_pages = wire("user")->editable_pages; // use wire() $branches = wire("pages")->find("template=branch"); // use wire() foreach($branches as $branch){ foreach ($editable_pages as $edit) { if($branch->id == $edit->id){ $p->add($branch); } } } return $p; please play around with and without added namespace, but let in the wire() calls. 1
Karl_T Posted October 15, 2016 Author Posted October 15, 2016 I am using Dev 3.0.33. It works after adding namespace to wire(). Thanks a lot! 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now