You are here

function uc_catalog_form_alter in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_catalog/uc_catalog.module \uc_catalog_form_alter()

Add an image field to the catalog's taxonomy term form.

File

uc_catalog/uc_catalog.module, line 283
Übercart Catalog module.

Code

function uc_catalog_form_alter($form_id, &$form) {
  if ($form_id == 'taxonomy_form_term' && $form['vid']['#value'] == variable_get('uc_catalog_vid', 0)) {
    $form['#attributes'] = array(
      "enctype" => "multipart/form-data",
    );
    $form['name']['#weight'] = -1;
    $form['image']['#weight'] = 0;
    $form['image']['image'] = array(
      '#type' => 'file',
      '#title' => t('Image'),
      '#weight' => 0,
    );
    $image = uc_catalog_image_load($form['tid']['#value']);
    if ($image) {
      if (module_exists('imagecache')) {
        $image_display = theme('imagecache', 'uc_category', $image->filepath);
      }
      else {
        $image_display = theme('image', $image->filename, t('Term image'));
        $form['image']['image']['#description'] = t('The image will not be resized. Consider installing <a href="@url">Image cache</a>.', array(
          '@url' => url('http://drupal.org/project/imagecache'),
        ));
      }
      $form['image']['remove'] = array(
        '#type' => 'checkbox',
        '#title' => t('Remove category image: !image', array(
          '!image' => $image_display,
        )),
        '#weight' => 1,
      );
    }
    $form['description']['#description'] = t('A description of the term. Displayed to customers at the top of catalog pages.');
  }
}