Jump to content

Add hook to FIeldTypePage output


Karl_T
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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.

  • 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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...