Im quite new to drupal 7. But my approach is learning by doing. This have worked fine until now....
My problem is, that I in a custom module, with a form submit, save a node with all the filled fields, including images. (Code below)
My problem is that i want to add a, a href to the images i save, so when opening the node the images will link to the link i have saved.
Is this even possible?
My node_save with pictures is like this:
$who = $user->uid;
$test = 'term_id' . $who;
$test1 = 'sales_id' . $who;
variable_set($test, $base_url . '/Sales/' . $form_state['values']['sales_id_terms']);
variable_set($test1, $base_url . '/Sales/' . $form_state['values']['sales_id_comp']);
$term_id = $form_state['values']['sales_id_terms'];
$file_temp_top = file_load($user->top_banner);
$file_temp_bund = file_load($user->bund_banner);
$file_temp_power = file_load(110);
//$file_temp_top = file_save_data($file_temp_top, 'public://firm_images/', FILE_EXISTS_REPLACE);
$node1 = new stdClass(); // Create a new node object
$node1->type = 'product_link'; // Content type
$node1->language = LANGUAGE_NONE; // Or e.g. 'en' if locale is enabled
$node1 = node_submit($node1);
node_object_prepare($node1); //Set some default values
$node1->status = 1; // (1 or 0): published or unpublished
$node1->promote = 0; // (1 or 0): promoted to front page or not
$node1->sticky = 0; // (1 or 0): sticky at top of lists or not
$node1->comment = 1; // 2 = comments open, 1 = comments closed, 0 = comments hidden
$node1->title = $form_state['values']['sales_name'] . '_1';
$node1->field_betingelser['und'][0]['value'] = $terms;
$node1->field_top_banner['und'][0] = array(
'fid' => $file_temp_top->fid,
'filename' => $file_temp_top->filename,
'filemime' => $file_temp_top->filemime,
'uri' => $file_temp_top->uri,
'status' => 1,
'display' => 1,
);
$node1->field_bund_banner['und'][0] = array(
'fid' => $file_temp_bund->fid,
'filename' => $file_temp_bund->filename,
'filemime' => $file_temp_bund->filemime,
'uid' => 1,
'uri' => $file_temp_bund->uri,
'status' => 1,
'display' => 1,
);
$node1->field_powerd_by['und'][0] = array(
'fid' => $file_temp_power->fid,
'filename' => $file_temp_power->filename,
'filemime' => $file_temp_power->filemime,
'uid' => 1,
'uri' => $file_temp_power->uri,
'status' => 1,
'display' => 1,
'href' => $GLOBALS['root_url'] . '/new-products/',
);
$node1->field_terms_id['und'][0]['value'] = $form_state['values']['kon_id_terms'];
// Add author of the node
$node1->uid = $user->uid;
// Set created date
$node1->date = 'complaint_post_date';
$node1->created = strtotime('complaint_post_date');
$new_path = 'sales/' . $node1->field_terms_id['und'][0]['value'];
$node1->path = array('alias' => $new_path);
// Save the node
node_save($node1);