function ad_image_node_form in Advertisement 5
Same name and namespace in other branches
- 5.2 image/ad_image.module \ad_image_node_form()
- 6.3 image/ad_image.module \ad_image_node_form()
- 6 image/ad_image.module \ad_image_node_form()
- 6.2 image/ad_image.module \ad_image_node_form()
Adapi helper function for displaying a node form.
1 call to ad_image_node_form()
- ad_image_adapi in image/
ad_image.module - Adapi implementation.
File
- image/
ad_image.module, line 354 - Enhances the ad module to support banner ads.
Code
function ad_image_node_form(&$node) {
$form = array();
ad_image_adapi('check_install', $node);
$form['ad_image'] = array(
'#type' => 'fieldset',
'#title' => t('Image'),
'#collapsible' => TRUE,
);
if (is_array($node->files)) {
$files = $node->files;
}
else {
$files = module_invoke('upload', 'load', $node);
}
$num = sizeof($files);
$path = NULL;
$active = 0;
if ($num) {
foreach ($files as $file) {
if ($file->list && file_exists($file->filepath)) {
$path .= '<img src="' . file_create_url($file->filepath) . '" alt="' . check_plain($file->filename) . '" /> ';
$image = ad_image_validate_size($file, $node->nid);
if ($image === FALSE) {
$path .= t('(invalid image)') . '<br />';
}
else {
if (!$active++) {
$path .= t('(active)') . '<br />';
}
else {
$path .= t('(inactive)') . '<br />';
}
}
}
else {
if (!file_exists($file->filepath)) {
drupal_set_message(t('Unable to locate image %image.', array(
'%image' => "{$file->filepath}",
)));
$path .= t('Unable to locate the uploaded image.');
}
}
}
}
if ($path == NULL) {
$path = t('No images have been uploaded. Please upload an image via the <em>File attachments</em> form section below.<br />');
// Only set error if node has been previewed or submitted.
if (isset($_POST['edit'])) {
form_set_error('upload', t('It is required that you upload an image for your image advertisement.'));
}
}
$path .= t('<br />Only the first uploaded image that has <em>List</em> checked in the <em>File attachments</em> form section below will be displayed as an advertisement. The image that will be displayed is marked as <em>active</em> above.');
$form['ad_image']['image'] = array(
'#type' => 'markup',
'#value' => $path,
'#prefix' => '<div class="container-inline">',
'#suffix' => '</div>',
);
$form['ad_image']['url'] = array(
'#type' => 'textfield',
'#title' => t('Destination URL'),
'#required' => FALSE,
'#default_value' => $node->url,
'#description' => t('Enter the complete URL if you want people to be redirected when they click on this advertisement. The URL must begin with http:// or https://. For example, %url. If you do not enter a URL, the advertisement will not be clickable.', array(
'%url' => t('http://www.sample.org/'),
)),
);
$form['ad_image']['tooltip'] = array(
'#type' => 'textfield',
'#title' => t('Mouseover'),
'#required' => FALSE,
'#default_value' => $node->tooltip,
'#description' => t('Optionally enter text to appear when a mouse pointer hovers over the ad image.'),
);
return $form;
}