Jump to content

Right hook right after the PageListActions


arjen
 Share

Recommended Posts

I am struggling to show the $page->path in as a <li> right after all the other actions like new, edit, et cetera. The reason for this is that a client has to copy a lot of his urls and it sames him some time being able to see them.

I can get it to work as an action, but I'd would really like to just have an <li>. As an alternative a place after the closing <ul> is also great.

Thanks in advance!

This is what I have right now:

<?php
/**
* PageListPath 0.0.1 ProcessWire module
*
* @author Arjen
* @created 22/11/2012
*
* ProcessWire 2.x
* Copyright (C) 2010 by Ryan Cramer
* Licensed under GNU/GPL v2, see LICENSE.TXT
*
* http://www.processwire.com
* http://www.ryancramer.com
*
*/
class PageListPath extends WireData implements Module {
/**
* getModuleInfo is a module required by all modules to tell ProcessWire about them
*
* @return array
*
*/
public static function getModuleInfo() {
return array(
'title' => 'Page List Path',
'version' => 001,
'summary' => 'Adds the path to the page',
'autoload' => true
);
}
public function init() {
$this->addHookAfter("ProcessPageListRender::getPageActions", $this, 'hookPageListActions');
}
/**
* Hook into ProcessPageListRender
*
*/

public function hookPageListActions(HookEvent $event) {
$page = $event->arguments[0];
$actions = $event->return;
$actions[] = array(
'cn' => 'Copy',
'name' => 'Copy path',
'url' => "#"
);
$event->return = $actions;
}
}
Link to comment
Share on other sites

What about Setup => Templates => basic-page (or any other template you need) => Advanced tab => List of fields to display in the admin Page List => "title path"

Edit: and if "path" is too much information, you can use "name" also.

Link to comment
Share on other sites

Thanks to the both of you, but I need this to use javascript to copy the path to the clipboard. Since I don't want to interfere with the default PW actions I've modified a theme that aligns the path right. There also will be /very-interesting/long/urls/using-this-technique so the path will be shortened for viewing purposes.

Link to comment
Share on other sites

YOu could do it like this and add a jscript file and use the action to copy to clipboard or make a prompt:

PageListPath.js

$(function(){
   $('.PageListActionURL a').live('click', function(e){
       e.preventDefault();
       console.log($(this).attr('href'));
       copyToClipboard($(this).attr('href'));

   });
});

function copyToClipboard(text) {
 window.prompt("Copy to clipboard: Ctrl+C, Enter", text);
}

And the module code

<?php
/**
* PageListPath 0.0.1 ProcessWire module
*
* @author Arjen Blokzijl
* @created 22/11/2012
*
* ProcessWire 2.x
* Copyright (C) 2010 by Ryan Cramer
* Licensed under GNU/GPL v2, see LICENSE.TXT
*
* http://www.processwire.com
* http://www.ryancramer.com
*
*/
class PageListPath extends WireData implements Module {
/**
        * getModuleInfo is a module required by all modules to tell ProcessWire about them
        *
        * @return array
        *
        */
public static function getModuleInfo() {
       return array(
               'title' => 'Page List Path',
               'version' => 001,
               'summary' => 'Adds the path to the page',
               'autoload' => true
       );
}
public function init() {
       $this->addHookAfter("ProcessPageListRender::getPageActions", $this, 'hookPageListActions');
       $this->addHookAfter("ProcessPageList::execute", $this, 'addScripts');

}
public function addScripts($event){
       $this->config->scripts->add($this->config->urls->PageListPath . "PageListPath.js");
}
/**
        * Hook into ProcessPageListRender
        *
        */

public function hookPageListActions(HookEvent $event) {

       $page = $event->arguments[0];
       $actions = $event->return;
       $actions[] = array(
                'cn' => 'URL',
                'name' => 'url',
                'url' => "$page->url"
                );
       $event->return = $actions;
       }
}
  • Like 1
Link to comment
Share on other sites

And there my first real module:

https://github.com/arjenblokzijl/ProcessPagePathCopy

The origin

A client needed to copy a lot of handpicked pages. You can do it using "view" and rightclick, but I thaught a single click might be a bit easier. So I wrote (thanks to Soma) this little module which adds a "copy path" action. You can also select a prefix or select which template(s) the actions should be applied to.

The client can use command/ctrl + c, switch to his e-mail, do command/ctrl - v, switch back press enter to continue to the next. I need to implement a flash based solution to make the last step redundant. Hopefully that is done the next couple of days.

  • Like 4
Link to comment
Share on other sites

  • 2 weeks later...

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