function path_file_update in File Entity (fieldable files) 7.3
Same name and namespace in other branches
- 7.2 file_entity.module \path_file_update()
Implements hook_file_update() on behalf of path.module.
File
- ./
file_entity.module, line 2536 - Extends Drupal file entities to be fieldable and viewable.
Code
function path_file_update($file) {
if (isset($file->path)) {
$path = $file->path;
$path['alias'] = trim($path['alias']);
// Delete old alias if user erased it.
if (!empty($path['fid']) && empty($path['alias'])) {
path_delete($path['fid']);
}
// Only save a non-empty alias.
if (!empty($path['alias'])) {
// Ensure fields for programmatic executions.
$path['source'] = 'file/' . $file->fid;
// Core does not provide a way to store the file language but contrib
// modules can do it so we need to take this into account.
$langcode = entity_language('file', $file);
$path['language'] = !empty($langcode) ? $langcode : LANGUAGE_NONE;
path_save($path);
}
}
}