Jump to content

Custom page admin actions


transpix
 Share

Recommended Posts

Hi

Is it possible to create a plugin that will add extra actions to the page actions (edit | view | move)?

I would like to add some extra actions like 'delete' and 'archive'.

If so, please point me in the right direction.

Many thanks!

Link to comment
Share on other sites

You'll want to make a module that looks into ProcessPageListRender::getPageActions. The best existing example of this is the ProcessPageClone module, included with the core modules in 2.2. I suggest taking a look at this module. Here's a description of how it works with regard to adding an action to PageList. I've pulled out and pasted in the functions here that are applicable:

<?php

/**
* Called when the API and $page loaded are ready
*
* We use this to determine whether we should add a hook or not.
* If we're in ProcessPageList, we add the hook.
*      
*/
public function ready() {
   $process = wire('page')->process;
   if($process == 'ProcessPageList') {
       $this->addHookAfter("ProcessPageListRender::getPageActions", $this, 'hookPageListActions');
   }
}

/**
* Hook into ProcessPageListRender::getPageActions to return a 'copy' action when appropriate
*
*/
public function hookPageListActions(HookEvent $event) {
   $page = $event->arguments[0];
   $actions = $event->return;
   $actions[] = array(
       'cn' => 'Copy',
       'name' => 'Copy',
       'url' => $this->config->urls->admin . "page/clone/?id={$page->id}"
       );
   $event->return = $actions;
}


What the above is doing is hooking into the function that figures out what actions to show for each page in the PageList, and then appending an action to it. The array should contain the following:

  • cn - the class name that will be added to the html for this action. It will be appended to ProcessPageListAction, like 'ProcessPageListActionCopy'.
  • name - the text label/name you want it to have in the navigation
  • url - the URL it should link to when clicked on
Link to comment
Share on other sites

But this isn't a file system, at least not by default. :) Deleting stuff on a web site should always be done with care. When you delete something, you are potentially affecting other resources linking to it (whether on-site or off-site). When you delete something, you are potentially sacrificing pagerank. Just because something is out of date doesn't mean it should be deleted. If there are still links to it anywhere offsite, your entire site is the beneficiary. Deleting has consequences online and is a much more complex issue than it looks on the surface. So while I don't disagree that a quick delete link would be handy in some situations, I think it's also one of those things that goes against best practices in most website situations. I tell my clients, never delete anything unless absolutely necessary. Don't delete, just stop linking to it. :)

But I know there are still times (like development, etc). So when you need to do quick deletes: click to open the trash. Then click 'move' for the page you want to delete, and drag it into the trash. If we ever have a 'delete' page action built into the core, it'll likely only appear if the trash is open.

Link to comment
Share on other sites

But I know there are still times (like development, etc). So when you need to do quick deletes: click to open the trash. Then click 'move' for the page you want to delete, and drag it into the trash. If we ever have a 'delete' page action built into the core, it'll likely only appear if the trash is open.

I guess that would be great. And in ProcessWire deleting is, like you said, not deleting but moving a page to trash. So the quick link doesn't have to be called "delete" but "move to trash".

/ Nico

Link to comment
Share on other sites

I kind of like this approach because if you've got the trash open, then accidents are unlikely because it's basically saying that you are here to delete stuff. Also, non-superusers don't have access to trash, so no worries about clients absentmindedly deleting stuff they shouldn't.

Link to comment
Share on other sites

I kind of like this approach because if you've got the trash open, then accidents are unlikely because it's basically saying that you are here to delete stuff. Also, non-superusers don't have access to trash, so no worries about clients absentmindedly deleting stuff they shouldn't.

Working on a module.

Link to comment
Share on other sites

Thanks for all the detail!

When I initially said 'delete' I did have in mind 'move to trash' as in the action on the delete tab of a page.

Nico - nice one with the module....I will install that later and I can use that as a basis for my 'archive' action!

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