Is there any event when user copy the page?
Is there any event when user copy the page?
Hi, i'm working on a module, and i need run some kind of code when user copy the page in cms made simple... Is there any event when this action is runing?
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
- Location: Fernie British Columbia, Canada
Re: Is there any event when user copy the page?
Nope. Sorry, there is not.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Re: Is there any event when user copy the page?
What Calguy says is true but there's more than one way to skin a cat.
There are events you can compare, ie ContentEditPre and ContentEditPost. If the page has a content id of -1, it's a new page. Doesn't matter how/where it was created, whether by manually adding a new page or copying an another one.
Firstly, create an event in ContentEditPre that stores the page in a session var if it's active, and test for the content id. If it's -1, it's a new page.
OK, so we've made a temporary session var letting us know we have a new, active page.
Next compare that with the event ContentEditPost:
hth
psy
There are events you can compare, ie ContentEditPre and ContentEditPost. If the page has a content id of -1, it's a new page. Doesn't matter how/where it was created, whether by manually adding a new page or copying an another one.
Firstly, create an event in ContentEditPre that stores the page in a session var if it's active, and test for the content id. If it's -1, it's a new page.
Code: Select all
$contentobj = $params['content'];
if ($contentobj->Id() == -1){ // It's a new page
// do somthing;
}
// make sure the new page is Active
if ($contentobj->Active() == 1) {
$_SESSION['mynewpage_active'] = 1;
}
Next compare that with the event ContentEditPost:
Code: Select all
$content = $params['content'];
$contentops = ContentOperations::get_instance();
$content_id = $content->Id();
$contentobj = $contentops->LoadContentFromId($content_id);
if ($contentobj)
{
$hid = $contentobj->Hierarchy();
if (!$hid) {
// New pages are only partially saved. We need to set/get the hierarchy stuff
$contentops->SetHierarchyPosition($contentobj->Id());
$hid = $contentobj->Hierarchy();
}
$contentops->CreateFriendlyHierarchyPosition($hid);
// Ensure the newly created page is active
if (isset($_SESSION['mynewpage_active']) ) {
unset ($_SESSION['mynewpage_active']);
// do what you want with the new active page that has now been fully written to the db....
}
psy