You are here

function uc_option_image_form in Ubercart Option Images 7

Add a form element to allow the admin to insert a default image which applies to all options, unless an option is overridden.

Parameters

&$form:

&$form_state:

$type: 'attribute' or 'option'

2 calls to uc_option_image_form()
uc_option_image_form_uc_attribute_form_alter in ./uc_option_image.module
Implements hook_form_uc_attribute_form_alter()
uc_option_image_form_uc_attribute_option_form_alter in ./uc_option_image.module

File

./uc_option_image.module, line 266
Allow store administrators to add images to attribute options.

Code

function uc_option_image_form(&$form, &$form_state, $type) {
  $aid = isset($form['aid']) ? $form['aid']['#value'] : NULL;
  $oid = isset($form['oid']) ? $form['oid']['#value'] : NULL;
  $object = uc_option_image_objects($type, array(
    'aid' => $aid,
    'oid' => $oid,
  ));
  $values = uc_option_image_values($type, array(
    'aid' => $aid,
    'oid' => $oid,
  ));
  $form['option_image'] = array(
    '#type' => 'fieldset',
    '#title' => t("Image"),
    '#collapsible' => TRUE,
    'uc_option_image_type' => array(
      '#type' => 'hidden',
      '#value' => $type,
    ),
    'uc_option_image_aid' => array(
      '#type' => 'hidden',
      '#value' => $aid,
    ),
    'uc_option_image_oid' => array(
      '#type' => 'hidden',
      '#value' => $oid,
    ),
    'uc_option_image_fid' => uc_option_image_file_form($type, $object, $values),
    uc_option_image_display_form($type, $object, $values),
  );
  if ($type != 'uc_attribute' && !empty($values['fid']) && $values['fid']['is_default']) {
    $file = file_load($values['fid']['value']);
    $form['option_image']['uc_option_image_fid']['#description'] .= "&nbsp;<strong>Currently using default image '" . $file->filename . "'</strong>";
  }
  $form['#submit'][] = 'uc_option_image_form_submit';
}