Created
March 19, 2013 15:38
-
-
Save micahredding/5197132 to your computer and use it in GitHub Desktop.
How to upload a file in a block configure form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hook_block_configure($delta = '') { | |
$form['image'] = array( | |
'#title' => t('Image'), | |
'#type' => 'managed_file', | |
'#description' => t('The uploaded image will be displayed on this page using the image style choosen below.'), | |
'#upload_location' => 'public://header_blocks/', | |
); | |
} | |
function hook_block_save($delta, $edit) { | |
foreach($edit as $key => $updated_content ) { | |
if($key == 'image') { | |
if(isset($edit[$key]) && is_numeric($edit[$key]) && $edit[$key] > 0) { | |
$file = file_load($edit[$key]); | |
$file->status = FILE_STATUS_PERMANENT; | |
file_save($file); | |
file_usage_add($file, 'header_blocks', 'node', $nid); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$key = 'image';
if(isset($edit[$key]) && is_numeric($edit[$key]) && $edit[$key] > 0) {
$file = file_load($edit[$key]);
$file->status = FILE_STATUS_PERMANENT;
file_save($file);
file_usage_add($file, 'header_blocks', 'node', $nid);
}