Skip to content

Instantly share code, notes, and snippets.

@dopsmain
Forked from amakeru/UniqueAlias
Created November 6, 2015 18:54
Show Gist options
  • Save dopsmain/3ab2fbf2c56a51e23be8 to your computer and use it in GitHub Desktop.
Save dopsmain/3ab2fbf2c56a51e23be8 to your computer and use it in GitHub Desktop.
MODX Plugin
<?php
// UniqueAlias
$eventName = $modx->event->name;
switch($eventName) {
case 'OnResourceDuplicate':
if($newResource->get('alias')) {
$alias = $newResource->get('alias');
}
else {
$alias = $newResource->cleanAlias($newResource->get('pagetitle'));
}
$alias .= '-'.$newResource->get('id');
$newResource->set('alias', $alias);
$newResource->save();
break;
case 'OnDocFormSave':
// If no custom alias, generation of unique alias from pagetitle
if(empty($_REQUEST['alias'])) {
$alias = $resource->cleanAlias($resource->get('pagetitle')).'-'.$resource->get('id');
$resource->set('alias', $alias);
$resource->save();
}
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment