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.
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.
Anyone?
I've never seen this post before or tried to use it, but it would appear that you need to change
to the class in which you placed the placePost and cleanPostParent functions. Probably in a Src folder or a controller somewhere.
$handler = new PageHandler();
to the class in which you placed the placePost and cleanPostParent functions. Probably in a Src folder or a controller somewhere.
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.
Anyone?
I've got this:
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?
$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?
SOLVED!
package controller.php:
src/PACKAGE_NAME/Page/Handler.php:
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();
Viewing 15 lines of 20 lines. View entire code block.
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)); } }