Skip to content

Instantly share code, notes, and snippets.

@anarchivist
Created December 24, 2009 17:39
Show Gist options
  • Select an option

  • Save anarchivist/263280 to your computer and use it in GitHub Desktop.

Select an option

Save anarchivist/263280 to your computer and use it in GitHub Desktop.
Autoassign default taxonomy terms in Drupal based on content type and CCK fields
<?php
/* This works similarly to the Taxonomy Defaults module [1] but has no UI.
This is for programmatic, backend stuff. It tests to see if somethings a
particular content type and then checks for the value of a given CCK field
to determine the appropriate term.
[1] http://drupal.org/project/taxonomy_defaults
*/
function custom_taxonomy_defaults_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
if ($op == 'presave') {
$taxonomy = $node->taxonomy;
switch ($node->type) {
case 'online_project_old':
$vid = '15';
$projtype = $node->field_external_resource_type[0]['value'];
switch ($projtype) {
case '1': # online exhibition
case '2': # special project
$taxonomy[$vid] = '902'; # special projects
break;
case '3': # index
$taxonomy[$vid] = '901'; # research tools
break;
case '4': # ebooks/digital collection
$taxonomy[$vid] = '895'; # collections
break;
}
break;
}
if (isset($taxonomy)) {
$node->taxonomy = $taxonomy;
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment