Just in case someone is looking for a solution. I was able to use Brunos Plugin in Revo 2.5 with some minor adjustments. I defined a default value "alias" for the alias field via form customization and hide this field for creating new resources. This way, there are no longer error messages regarding existing or empty alias.
Attached the code I use for plugin running on event OnBeforeDocFormSave.
// specify allowed contexts
$allowed_ctx = array('MYCTX');
// make sure we're using the right event
if (!in_array($modx->event->name, array('OnBeforeDocFormSave'))) return;
if (!$resource) return;
// make sure this only runs on new resources in specified contexts
if ($mode != 'new') return;
$ctx_key = $resource->get('context_key');
if (!in_array($ctx_key, $allowed_ctx)) return;
// $alias = $resource->get('alias'); // don't needed
// $id = $resource->get('id'); // $id is always 0 for new resources so we don't use that.
$pagetitle = $resource->get('pagetitle');
// create alias for lookup from pagetitle
$alias = $resource->cleanAlias($pagetitle);
// look for resources in ctx with existing alias but only if id != 0 (new resource)
$c = $modx->newQuery('modResource', array('alias' => $alias, 'id:!=' => 0, 'context_key' => $ctx_key));
if ($collection = $modx->getCollection('modResource', $c)) {
foreach ($collection as $key => $object) {
$existing[] = $object->get('alias');
}
$c = $modx->newQuery('modResource', array('pagetitle' => $pagetitle, 'id:!=' => 0, 'context_key' => $ctx_key));
if ($collection = $modx->getCollection('modResource', $c)) {
foreach ($collection as $key => $object) {
$existing[] = $object->get('alias');
}
}
$loop = true;
$i = 0;
while ($loop) {
if ($i == 0) {
$suffix = '';
} else {
$suffix = $i < 10 ? '-0' . $i : '-' . $i;
}
//$suffix = "-1";
$newalias = $pagetitle . $suffix;
$newalias = $resource->cleanAlias($newalias);
$loop = in_array($newalias, $existing);
$i++;
}
$resource->set('alias', $newalias);
}
// if no conflicting resources found, set alias we created from pagetitle
else {
$resource->set('alias', $alias);
}
return null;