Taxonomy Term Path
Last updated on
28 November 2024
If you want to save files attached to a node inside a special file structure you can use this snippet with the filefield_paths module.
If you add a taxonomy_field to a node and tag it with foo and bar, this snippet generates foo/bar/
"field_texturen" is a sample name here, replace with your fields name.
WORKING CODE
if(isset($data['node'])) {
$field_data = field_view_field('node', $data['node'], 'field_texturen');
foreach($field_data['#items'] as $key => $term_data) {
//save names as lowercase
$terms[] = strtolower($term_data['taxonomy_term']->name);
}
//implode
$path = implode('/', $terms);
}
if(!empty($path)) {
return $path . '/';
}
One may think this should work too, but it does not.
THIS ONLY WORKS ON NODE UPDATE.
//are we inside a node
if(arg(0) == 'node' && is_numeric(arg(1)) ) {
$field_data = field_view_field('node', node_load(arg(1)), 'field_texturen');
foreach($field_data['#items'] as $key => $term_data) {
//save names as lowercase
$terms[] = strtolower($term_data['taxonomy_term']->name);
}
//implode
$path = implode('/', $terms);
}
if(!empty($path)) {
return $path . '/';
}
Help improve this page
Page status: Not set
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion