Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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 . '/';
}