I assume you mean when processing tags (you can already check in code to see if an object exists).
It would definitely be handy. I don't think it would slow down page-loads much since I suspect that there's already a test to see if the object was found and the System Event code would only execute when that test failed.
If you want to play around with it, you could try creating the Event and adding something like this at line 538 of the modParser class file (just above the return $element line):
if (!$element) {
$modx->invokeEvent('OnElementNotFound',
array(
'name' = $realname,
'class' = $class,
),
));
}
I think it could also be in an else() statement in the test just above there, which would be a little faster.
A plugin tied to the event could decide (maybe based on a System Setting) which classes to respond to.
There's code in MyComponent for creating new System Events:
$newEvents = array (
0 => array (
'name' => 'OnElementNotFound',
'service' => 1,
'groupname' => 'Whatever', // or ''
),
);
foreach($newEvents as $k => $fields) {
$event = $modx->getObject('modEvent', array('name' => $fields['name']));
if (!$event) {
$event = $modx->newObject('modEvent');
if ($event) {
$event->fromArray($fields, "", true, true);
$event->save();
}
}
}
[ed. note: BobRay last edited this post 13 years, 2 months ago.]