-
-
Save dopsmain/3ab2fbf2c56a51e23be8 to your computer and use it in GitHub Desktop.
MODX Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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