and new page with on_user_add event

Permalink
Good afternoon,

I'm trying to set it up so that new page is automatically added when a new user is added. From going the the forum and other documentation I understand that it can be done by utilizing the on_user_add event. This is what I've done so far:

1) Added the the following code to config/site.php file

<?php define('ENABLE_APPLICATION_EVENTS', true); ?>


2) Added "site_events.php" file to config/ directory and added the following code to it.
<?php
Events::extend('on_user_add', 'ApplicationUser', 'NewUserNewPage', 'models/application_user.php');
?>


Now I understand that I want to add code to /models/application_user.php to define what I want it to do. This is where I get fuzzy. I'm not sure what code I want to enter so it adds a page, selects the page type (handle: new_user), and selects the correct permissions (allow edit by that particular user and administrators).

Does anyone have some examples of code that would need to be entered?

Thanks!

 
emielmolenaar replied on at Permalink Reply
emielmolenaar
It would be something like this:

$parentPage = Page::getByPath("/sample");
$data = array(
        'name' => "sample2",
        'cHandle' => "sample2handle",
    'cDescription' => "Add page test."           
);
$pt = CollectionType::getByHandle("page_type_handle");
$newPage = $parentPage->add($pt,$data);


You always add a new page, beneath a parent page. Check outhttp://www.concrete5.org/documentation/developers/pages/overview... for more detailed information.