I wrote the following module to upload a background image. My problem is, that my submit function is not called, though the pic is uploaded and showed in the block until the next cleanup is coming.The managed file table shows status 0...what should be 1 as far as i know.
Here is the Code of my Module: Whats the mistake?
function backgroundimage_block_info() {
// This example comes from node.module.
$blocks['backgroundimage'] = array(
'info' => t('Background Image'),
);
return $blocks;
}
function backgroundimage_block_view($delta = '') {
$fid_now=variable_get('backgroundimage');
dpm($fid_now);
$file_obj = file_load($fid_now);
$bg_img_url = file_create_url($file_obj->uri);
// This example is adapted from node.module.
$block = array();
switch ($delta) {
case 'backgroundimage':
$block['subject'] ="imagebackgroundblock";
$block['content'] ="<div class='background-image'><img src='".$bg_img_url."'></div>";
break;
}
return $block;
}
function backgroundimage_admin() {
$form = array();
$form['backgroundimage'] = array(
'#type' => 'managed_file',
'#name' => 'backgroundimage_image',
'#title' => t('upload image, huh!'),
'#default_value' => variable_get('backgroundimage', ''),
'#description' => t("Here you can upload an image to the background!"),
'#required' => TRUE,
'#upload_location' => 'public://backgroundimage/'
);
return system_settings_form($form);
}
function backgroundimage_form_submit($form, $form_state) {
dpm("yeah"); // is not being called!
$form['backgroundimage']['#file']->status = FILE_STATUS_PERMANENT;
file_save($form['backgroundimage']['#file']);
}
function backgroundimage_menu() {
$items = array();
$items['admin/settings/backgroundimage'] = array(
'title' => 'Settings Background Image',
'description' => 'Image upload',
'page callback' => 'drupal_get_form',
'page arguments' => array('backgroundimage_admin'),
'access arguments' => array('administer backgroundimage settings'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
?>
Thanks a lot!