I am aware that within 'Site building -> URL aliases -> Automated alias settings -> Node paths' you can create a path pattern for your content type.

Can you do this programmatically?

Comments

msathesh’s picture

Why do you want to do that programatically when you can do the same thing in the user interface?

danieltnbaker’s picture

It will be initiated from a custom module install on many sites, many times a day. It will reduce overhead changing the same setting with the same values for every site if I can do it programmatically.

Any ideas?

msathesh’s picture

I hope you write a module to interact with the table called 'variable' with column 'name' and it's values like 'pathauto_node_*_pattern'. Where * represents node type, for example, for page node type it's stored in 'pathauto_node_page_pattern'. Hope it helps.

danieltnbaker’s picture

Thanks msathesh, worked like a treat. I created my content types and then used variable_set to apply my autopath patterns.

Again, thank you

msathesh’s picture

glad that I could help.. thanks @daniel

eddie_c’s picture

Here's some code I'm using with msathesh's solution. I've put my content type names and path aliases in an array which I then loop through, setting up each alias in the variable table. Thanks msathesh.


    //Array of content types and aliases we want to update in the form content_type_machine_name => alias
    $node_aliases = array (
	   'policy' => 'policy/[title-raw]',
	   'working_paper' => 'workingpaper/[title-raw]',
	   'presentation' => 'presentation/[title-raw]',
	   'rapid_response' => 'rapidresponse/[title-raw]'
	  );
    
    //Loop through each item in the array and create a variable for it.
    foreach($node_aliases as $type => $alias) {
	$varname = 'pathauto_node_'.$type.'_pattern';
	variable_set($varname, $alias);
	$types[] = $type;
    }

ain’s picture

Hey thanks for the discussion guys, helped me to find an answer to my own Stackoverflow question: How to change Automated alias settings on module install?