You are here

function ad_image_node_form in Advertisement 6

Same name and namespace in other branches
  1. 5.2 image/ad_image.module \ad_image_node_form()
  2. 5 image/ad_image.module \ad_image_node_form()
  3. 6.3 image/ad_image.module \ad_image_node_form()
  4. 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
Implementation of hook_adapi().

File

image/ad_image.module, line 430
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 (isset($node->files)) {
    $files = $node->files;
  }
  else {
    if (!isset($node->vid)) {
      $node->vid = '';
    }
    $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' => isset($node->url) ? $node->url : '',
    '#description' => t('Enter the complete URL where you want people to be redirected when they click on this advertisement.  The URL must be valid and begin with http:// or https://, for example %url, unless you !disable.  If you do not enter a URL, the advertisement will not be clickable.', array(
      '%url' => t('http://www.sample.org/'),
      '!disable' => l(t('disable URL validation'), 'admin/content/ad/configure', array(
        'fragment' => 'edit-ad-validate-url-wrapper',
      )),
    )),
  );
  $form['ad_image']['tooltip'] = array(
    '#type' => 'textfield',
    '#title' => t('Mouseover'),
    '#required' => FALSE,
    '#default_value' => isset($node->tooltip) ? $node->tooltip : '',
    '#description' => t('Optionally enter text to appear when a mouse pointer hovers over the ad image.'),
  );
  return $form;
}