Concrete5.7.5.2 - How to change new page name (add date)?

Permalink
When I add a new page I enter a page URL. It's ok for some number of pages. But if I need to add tens or hundreds of pages like blog posts or my own types based on topics, it's very difficult if possible at all to remember what page name I have already used.

Does anyone know what I need to change, which controller, to automatically add a page date of issue to the page URL slug?

I tried to put the code from that site:

http://andrewembler.com/2015/05/auto-generate-page-locations-based-...

into an on_start() function of a application/controllers/page_type/mypagetype.php, but it gives me an error saying it can't find the PageHandler(). (mypagetype is, say, my page type handle I need to add)

Seems something's missing in the code above. Could you please help?

Thank you.

linuxoid
View Replies: View Best Answer
linuxoid replied on at Permalink Reply
linuxoid
Anyone?
hutman replied on at Permalink Reply
hutman
I've never seen this post before or tried to use it, but it would appear that you need to change

$handler = new PageHandler();


to the class in which you placed the placePost and cleanPostParent functions. Probably in a Src folder or a controller somewhere.
linuxoid replied on at Permalink Reply
linuxoid
Could anyone please tell me what (which controller/tool/block) I should override to be able to automatically add a page creation date or whatever to the page URL when adding a new page? Thank you.
linuxoid replied on at Permalink Reply
linuxoid
Anyone?
linuxoid replied on at Permalink Reply
linuxoid
I've got this:
$date = date('d-m-Y');
$handle = $page->getCollectionHandle();
if (!$handle) {
$handle = $page->getCollectionID();
}
$parentPage = \Page::getByPath('/pages');
$pageType = \PageType::getByHandle('post');
$template = \PageTemplate::getByHandle('full');
$parentPage->add($pageType, array(
       'cName' => $page->getCollectionName(),
       'cHandle' => $handle . '-' . $date
       ), $template);

but it creates 2 pages: one without the date appended AND one with the date appended. Where's the 2nd page coming from? What am I doing wrong?
linuxoid replied on at Permalink Best Answer Reply
linuxoid
SOLVED!

package controller.php:
use PACKAGE_NAME\Page\Handler as PageHandler;
    class Controller extends Package {
       protected $pkgAutoloaderMapCoreExtensions = true;
       protected $pkgAutoloaderRegistries = array('src/PACKAGE_NAME' => '\PACKAGE_NAME'); //change PACKAGE_NAME
       public function on_start()
       {
          $handler = new PageHandler();
          \Events::addListener('on_page_type_publish', function($event) use ($handler) {
              $page = $event->getPageObject();
              if ($page->getPageTypeHandle() == 'PAGE_TYPE') { //change PAGE_TYPE
             $handler->placePost($page);
              }
          });
          \Events::addListener('on_page_version_approve', function($event) use ($handler) {
              $page = $event->getPageObject();

src/PACKAGE_NAME/Page/Handler.php:
<?php  
    namespace PACKAGE_NAME\Page;
    use Concrete\Core\Page\Page;
    class Handler {
        public function placePost(Page $page) {
            $date = date('d-m-Y');
            $handle = $page->getCollectionHandle();
            if (!$handle) {
                $handle = $page->getCollectionID();
            }
            $handle = $handle . '-' . $date;
            $page->update(array('cHandle' => $handle));        
        }
    }