Jump to content

Recommended Posts

Posted

Good day everybody,

I am developing a backend page for a customer using ProcessPageList as the basis.

I do not want the customer to see anything but product pages, but ProcessPageList always lists all pages starting from Home (id=0)

I want to hide certain pages from the backend user but I don't want to mess with different templates and permissions.

Example site structure:

[ Home ]

---- Site settings

---- Products

---- Misc. Writings

How can I set ProcessPageList up such that it builds a page tree starting from "Products" as parent?

Thanks for any hints, guys.

Posted
$p = $this->modules->get('InputfieldPageListSelect');
$p->attr('name', 'products');//example name value for selected page
//$p->set('parent_id', $parentId);//here we set the parent whose children will be selectable OR
$p->set('parent_id', 12345);//here we set the parent whose children will be selectable
$p->set('startLabel', $this->_('Product Blah Blah'));

You can even change the 'more' and 'cancel' labels...

Posted

Thanks kongondo, but how do I add "edit", "view", "new", "move", "copy" tags? I played around with InputfieldPageListSelect but that's not exactly what's needed. 

ProcessPageList tweaks? Please?

Posted

Sorry, my bad. I misunderstood...Try this instead,,

$p = $this->modules->get('ProcessPageList');
$p->set('id',2480); // the parent page
return $p->execute();
					
  • Like 3
Posted

kongondo, thank you, man! It worked like a charm! Wow, another great advance in my project. Can't thank you enough! And it was not too much of a puzzle, as it seems to me now :)

One small note for those who would like to use this trick in a ProcessPageEdit-based module: if you construct your own form for ProcessPageEdit, then put the rendered ProcessPageList in an InputfieldMarkup (and append it to an InputfieldWrapper field if you want to):

$form = $this->modules->get('InputfieldForm'); // prep the form

$wrapper = new InputfieldWrapper; // a wrapper
$wrapper->attr('value', 'List of available articles');

$p = $this->modules->get('ProcessPageList'); // kongondo's code goes here
$p->set('id', 9999); // setting the parent page

$pageTree = new InputfieldMarkup; // the placeholder
$pageTree->value = $p->execute(); // fill the InputfieldMarkup form field...

$wrapper->add($pageTree); // put inside the wrapper...

$form->append($wrapper); // append the wrapper

Because Process<something> modules do not append directly to forms, you know ;)

post-956-0-36008400-1399582883_thumb.png

  • Like 5
  • 3 months later...
Posted

Hello again,

I need your help 'cause I am really stuck.

I am developing a module where I would have a PageList. With kongondo's help I managed to tweak some of PageList aspects. However, I am not moving anywhere with Page Actions.

My task is to build a custom list of page actions instead of the default "edit", "view", "new" etc. I added an "after" hook to ProcessPageListRender:

wire()->addHookAfter('ProcessPageListRender::getPageActions', function($event) { // inside a class             
            $actions[] = array (
                'cn' => 'Custom actions',
                'name' => 'Custome name',
                'url' => "/custom/path"
            );
            $event->return = $actions;
        }
);

Then the ProcessPageList gets executed like this:

 
public function ___execute () {

        $lister = wire('modules')->get("ProcessPageList");
        $lister->id = 99999;
        return $lister->execute();
}
 
But it does not seem to work. 
 
___getPageActions  is a hookable method but I cannot figure out how to put a hook to modify the returned list of page actions.
 
 
A little help, guys? Please?
Posted

Thanks. Was already browsing Nico's code. Fruitless so far  :mellow:

Is that because you are wanting to replace, rather than add to the list of action buttons? If so, try:

$event->replace = true;

If not, can you explain a little better what is and isn't working?

Posted

Thanks, adrian. I'll better just show the code of my module. I am attaching a hook which shouild modify the URL of the page action "Edit":

public function init () {
    parent::init();

    wire()->addHookAfter("ProcessPageListRender::getPageActions", function($event) { // anonymous function
                $custom_actions = $event->return;

                $custom_actions[0]['url'] = '/my/path';

                $event->replace = true;

                $event->return = $custom_actions;
            }
    );
}
public function ___execute () {

    parent::___execute();

    $page_lister = wire('modules')->get("ProcessPageList");

    return $page_lister->execute();
}

Cannot really tell why but the list of page actions is not modified. 

Posted

This works for me. This replaces all the existing buttons and adds a new one called "custom". Is that what you are looking for?

public function init () {
    parent::init();
     
    wire()->addHookAfter("ProcessPageListRender::getPageActions", function($event) { // anonymous function

        $event->replace = true;

        $new_action = array(
           'cn' => 'custom',
           'name' => 'Custom',
           'url' => '/my/path'
        );

        $event->return = $new_action;

   });
}
  • Like 2
Posted

Hello adrian,

I am sorry to say but this code does not work on my environment. Here is what I have in my module:

 
public function init () {
    parent::init();

    wire()->addHookAfter("ProcessPageListRender::getPageActions", function($event) { // anonymous function
                $event->replace = true;

                $new_action = array (
                    'cn' => 'custom',
                    'name' => 'Custom',
                    'url' => '/my/path'
                );

                $event->return = $new_action;
            });
}

public function ___execute () {
    return wire('modules')->get("ProcessPageList")->execute();
}

The list of page actions that I receive in the output is not changed. I tried different browsers, did a reset & flushed cache.

I sense that the "ProcessPageListRender::getPageActions" hook is somehow not working for me. If so, what could be the reason?

Posted

Thanks, adrian, really appreciate your help. 

Yes, it started to work and I saw the 'custom' page action. The problem is, it now affects all instances of ProcessPageList, including /processwire/page/edit 

Thanks, though. I will see what I can do.

Posted
Yes, it started to work and I saw the 'custom' page action. The problem is, it now affects all instances of ProcessPageList, including /processwire/page/edit 

Yep - I obviously didn't worry about that issue at the moment - just wanted to get you going with changing the actions. Hopefully you can figure it out from here, but if not, post all your code so we can take a proper look.

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
  • Recently Browsing   0 members

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