Skip to content

Instantly share code, notes, and snippets.

@jackbravo
Created November 5, 2014 00:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackbravo/e59a518a928e0e3a23f1 to your computer and use it in GitHub Desktop.
Save jackbravo/e59a518a928e0e3a23f1 to your computer and use it in GitHub Desktop.
<?php
/**
* Alter Pathauto-generated aliases before saving.
*
* @param string $alias
* The automatic alias after token replacement and strings cleaned.
* @param array $context
* An associative array of additional options, with the following elements:
* - 'module': The module or entity type being aliased.
* - 'op': A string with the operation being performed on the object being
* aliased. Can be either 'insert', 'update', 'return', or 'bulkupdate'.
* - 'source': A string of the source path for the alias (e.g. 'node/1').
* This can be altered by reference.
* - 'data': An array of keyed objects to pass to token_replace().
* - 'type': The sub-type or bundle of the object being aliased.
* - 'language': A string of the language code for the alias (e.g. 'en').
* This can be altered by reference.
* - 'pattern': A string of the pattern used for aliasing the object.
*/
function ehs_section_pathauto_alias_alter(&$alias, array &$context) {
if ($context['module'] == 'taxonomy_term' && $context['type'] == 'section') {
if (isset($context['data']['term'])) {
$parent = array_pop(taxonomy_get_parents($context['data']['term']->tid));
}
if (empty($parent)) {
$alias = preg_replace('/^section\//', '', $alias);
}
else {
// if parent is 1,2,3 or 4 then its a service
if (array_search($parent->tid, array(1,2,3,4)) !== FALSE) {
$alias = preg_replace('/^section/', 'services', $alias);
}
else {
$alias = preg_replace('/^section/', 'programs', $alias);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment