function attachment_links_save_alias in Attachment Links 7
Save the convenience alias.
2 calls to attachment_links_save_alias()
- attachment_links_node_insert in ./
attachment_links.module - Implements hook_node_insert().
- attachment_links_node_update in ./
attachment_links.module - Implements hook_node_update().
File
- ./
attachment_links.module, line 88
Code
function attachment_links_save_alias($node) {
$create_alias = variable_get('attachment_links_create_alias_' . $node->type, FALSE);
if ($create_alias) {
// Make sure that attachment links are enabled for a field on this node type.
$file_field_name = variable_get('attachment_links_selection_' . $node->type, 0);
if ($file_field_name) {
// Grab the files from the current node for the selected field.
$files = field_get_items('node', $node, $file_field_name);
if (!empty($files)) {
// Retreive the 'authorative' file.
$file = reset($files);
$file = file_load($file['fid']);
if (!empty($node->path['alias'])) {
$node_alias = $node->path['alias'];
$alias_parts = explode('/', $node_alias);
if (count($alias_parts) > 1) {
array_pop($alias_parts);
$node_alias = implode('/', $alias_parts);
}
$alias = $node_alias . '/' . $file->filename;
$source = 'node/' . $node->nid . '/attachment';
$new_alias = array(
'source' => $source,
'alias' => $alias,
'language' => $node->language,
);
path_save($new_alias);
return TRUE;
}
}
}
}
return FALSE;
}