Hi All,
I am having a problem developing a Module that depends on Pathauto and uses several of its hooks. I implement hook_pathauto in order to add extra settings in the Pathauto configuration screen and it works great. For the replacement patterns, I use the standard node tokens. The following is the code:
function printwebpathauto_pathauto( $operation )
{
if( $operation == 'settings' )
{
// Initialize New Object.
$Settings = new stdClass( );
$Settings->bulkname = t( 'Bulk Generate Printer Friendly Web Aliases.' );
$Settings->bulkdescr = t( 'Generates printer friendly Web aliases for URLs that do not already have aliases.' );
$Settings->groupheader = t( 'Printer Friendly Web Settings' );
$Settings->module = 'printwebpathauto';
$Settings->patterndescr = t( 'Pattern for Default printer friendly Web URLs' );
$Settings->patternitems = new stdClass( );
$Settings->placeholders = new stdClass( );
$Settings->token_type = 'node'; // Use Standard Node Tokens.
// Get All Possible Token Place Holders Patterns.
$patterns = token_get_list( 'node' ); // Get Standard Node Tokens.
$PlaceHolders = $Settings->placeholders;
foreach( $patterns as $patternType => $pattern )
{
if( $patternType != 'global' )
{
foreach( $pattern as $patternName => $patternDescription )
{
$patternName = '[' . $patternName . ']';
$PlaceHolders->$patternName = $patternDescription;
}
}
}
$nodeTypes = node_get_types( 'names' );
$PatternItems = $Settings->patternitems;
foreach( $nodeTypes as $nodeType => $nodeName )
{
$PatternItems->$nodeType = t(
'Pattern for @NodeName printer friendly Web URLs' ,
array(
'@NodeName' => ucwords( $nodeName )
)
);
}
// Return.
return $Settings;
}
}
I also implement hook_nodeapi in order to create a new alias, based on the above, when a new node is created. The following is the code:
function printwebpathauto_nodeapi( &$Node , $operation , $teaser , $page )
{
if( $operation == 'insert' )
{
// Get Token Place Holders Patterns.
$placeholders = pathauto_get_placeholders( 'node' , $Node );
// Define URL To Generate Alias For.
$url = 'print/' . $Node->nid;
// Generate Alias.
pathauto_create_alias(
'printwebpathauto' ,
'insert' ,
$placeholders ,
$url ,
$Node->nid ,
$Node->type ,
$Node->language
);
}
}
Here is the problem: Taxonomy related tags, such as [vocab] and [termpath], and their -raw alternatives are not being replaced at all! Most of this code is based on the standard example code found in Pathauto itself yet it is not working at all! How can I fix it? Any help would be appreciated greatly.
So if I define a pattern like so: blog/print/[termpath-raw]/[title-raw] --> The result for a content with a title of 'Test' would be --> blog/print/Test. The [termpath-raw] is completley ignored, even though the content is part of a vocabulary.
Thanks in advance,
Comments
*BUMP* Anyone?
*BUMP*
Anyone?
I think your object syntax might be the issue
I actually became interested in using pathauto this way based on your example code.
I'm not sure about how you went about your setup with the Objects and stuff, and that's the part that seems the most likely to have a hidden failure, but I based my work on the file: sites/all/modules/pathauto/pathauto_node.inc, and just used array's until the end, with a typecast to object.
My usage is obviously different from yours, but I think there maybe be something you could pick up from my example?
I have a module that is handling contact-us forms for a site with 2 different types of nodes (products) that users might want to contact us about. So I restrict to those two nodes.
I managed to get it to work by first of all defining a menu entry, and getting the basic form loading with the un-pretty url like this:
"/mail-us/{$node->nid}"
Which our client doesn't want because that tempts some people (not very bright ones I gather) to ask about other #'s that may or may not be properties ... so we needed a better solution.
We opted for /mail-us/# to be the real processing menu url, but using url aliases to hide it from the user so the user could ask for say "/aboutPrinters/Canon-Fx3" or "/aboutLaptops/Dell-4025" (the actual site has nothing to do with either Laptops or Printers, and I just made up the Canon Fx3 and Dell 4025 :] ... but I think the parallel holds).
So these are slightly edited versions of the functions in our module:
I hope this helps you and maybe some others out there.
Jeff
Sorry for the late reply but
Sorry for the late reply but I sort of gave up hope that anyone would actually reply. I kind of believed that using an Object might be the problem at first as well so I literally copied and pasted the code for the default content node provided by Pathauto and just made the appropiate changes specific to my module. To my dismay it still did not work!
The code for the default content node provided by Pathauto uses an Array that is typecasted to an Object when the function returns so it seems your suggestion about not using an Object did not work for me. I am going crazy here and starting to give up all hope.
Is your module generating correct URLS when using taxonomy terms? I see very little differences from your code and mine in regards to creating an alias when a node is created so I am just curious if I am the one having this problem or perhaps this is a problem with Pathauto that we don't know about.
Thanks a lot for your support. If you have any other suggestions, I would surely appreciate it.
Thanks in advance,
Auto-Pathing
I've been using my module in a production environment since I last posted it. :0
Sorry I wasn't of more help for you.
Jeff