As per the documentation at
http://rtfm.modx.com/display/revolution20/OnBeforeDocFormSave:
You should adjust your code as follows....
<?php
/* This event passes the following parameters, so you
* don't need the $modx->resource shortcut:
*
* $mode <---- 'new' or 'upd'
* $resource <---- not $modx->resource
* $id <--- Will be 0 for a new resource.
*/
// Get TVs that hold the first and lastname
$firstname = $resource->getTVValue('firstname');
$lastname = $resource->getTVValue('lastname');
// Get pagetitle
$pagetitle = $resource->get('pagetitle');
// Check if pagetitle is empty
if ($pagetitle == '') {
// Create full name
$name = $firstname." ".$lastname;
// Set full name as pagetitle
$resource->set('pagetitle', '$name');
// Save object
$resource->save();
}
For clarification, $modx->resource is not set in between certain events. I don't know where it goes away, but it doesn't come back until OnLoadWebDocument. Even then, some properties cannot be retrieved, so an xPDO Query will be necessary.
Documentation on System Events is in the RTFM. But it is located at a strange path: Developing in MODx -> Basic Development -> Plugins -> System Events. From there you have to scroll either the tree or the document depending on the Event. (The tree doesn't match the document)
[ed. note: fuzzicallogic last edited this post 14 years, 2 months ago.]