<?php
/* keep this from running in the Manager */
if ($modx->context->get('key') == 'mgr') {
return;
}
/* save the new alias based on pagename */
$resource->set('alias', '');
$resource->save();
<?php
/* keep this from running in the Manager */
if ($modx->context->get('key') == 'mgr') {
return;
}
/* (optional) Don't execute for existing resources --
Remove the following line to let users modify
existing parents in NewsPublisher
if (!($mode == modSystemEvent::MODE_NEW)) return; */
/* get parent ID from TV */
$parentId = $resource->getTVValue('index_category');
/* save the parent id in the resource's parent field */
$resource->set('parent', $parentId);
$resource->save();
This question has been answered by sottwell. See the first response.
$myPluginTemplate = $modx->getOption('myplugin.template', $scriptProperties, '1');
if($resource->get('template') != $myPluginTemplate) return;if($mode == 'upd') return;
if ($mode == modSystemEvent::MODE_UPD) {
}
if ($mode == modSystemEvent::MODE_NEW) {
}$modx->invokeEvent('OnBeforeDocFormSave',array(
'mode' => modSystemEvent::MODE_NEW,
...class modSystemEvent {
/**
* @var string For new creations of objects in model events
*/
const MODE_NEW = 'new';
/**
* @var string For updating objects in model events
*/
const MODE_UPD = 'upd';