You are here

function imceimage_process in Imce CCK Image 6.2

Same name and namespace in other branches
  1. 6 imceimage.module \imceimage_process()

process callback for the imceimage form element, as registered in hook_elements()

1 string reference to 'imceimage_process'
imceimage_elements in ./imceimage.module
Implements hook_elements()

File

./imceimage.module, line 591

Code

function imceimage_process($element, $edit, $form_state, $form) {
  $field = $form['#field_info'][$element['#field_name']];
  $delta = $element['#delta'];
  $field_id = $field['field_name'];

  // Workaround to have all the "visible" fields in a fieldset
  // and making possible to save them at the same time
  if (isset($element['#value']['imce_widget_container'])) {
    $element['#value'] = $element['#value']['imce_widget_container'];
  }
  $remove_href = check_plain("javascript:imceImage.remove('{$delta}-{$field_id}')");
  $remove_link = '<a class="imceimage-remove" href="' . $remove_href . '">' . t('Remove') . '</a>';
  $imce_url = url('imce');
  $select_href = check_plain("javascript:imceImage.open('{$imce_url}', '{$delta}-{$field_id}')");
  $select_link = '<a href="' . $select_href . '" class="imceimage-add">' . t('Select Image') . '</a>';
  $imceparams['url'] = "imceimagepath-{$delta}-{$field_id}";
  $imceparams['width'] = "imceimagewidth-{$delta}-{$field_id}";
  $imceparams['height'] = "imceimageheight-{$delta}-{$field_id}";
  $element['imce_widget_container'] = array(
    '#type' => 'fieldset',
    '#attributes' => array(
      'style' => 'display:none',
      'id' => "imceimagefieldset-{$delta}-{$field_id}",
    ),
  );
  if (!stripos(_imceimage_image_html($element['#value'], "imceimageimg-{$delta}-{$field_id}"), '1x1')) {
    unset($element['imce_widget_container']['#attributes']['style']);
  }
  $element['imce_add'] = array(
    '#type' => 'item',
    '#value' => $field['widget']['label'] . " [{$select_link}][{$remove_link}]",
    '#weight' => -1,
  );
  $element['imce_widget_container']['imceimage_path'] = array(
    '#type' => 'hidden',
    '#id' => $imceparams['url'],
    '#default_value' => $element['#value']['imceimage_path'],
  );
  $element['imce_widget_container']['imceimage_width'] = array(
    '#type' => 'hidden',
    '#id' => $imceparams['width'],
    '#default_value' => $element['#value']['imceimage_width'],
  );
  $element['imce_widget_container']['imceimage_height'] = array(
    '#type' => 'hidden',
    '#id' => $imceparams['height'],
    '#default_value' => $element['#value']['imceimage_height'],
  );
  $element['imce_widget_container']['imce_view'] = array(
    '#type' => 'item',
    '#id' => "imceimageimg-{$delta}-{$field_id}",
    '#value' => _imceimage_image_html(array(
      'imceimage_width' => 100,
      'imceimage_height' => 100,
    ) + $element['#value'], "imceimageimg-{$delta}-{$field_id}"),
  );
  $element['imce_widget_container']['imceimage_alt'] = array(
    '#type' => 'textfield',
    '#id' => "imceimagealt-{$delta}-{$field_id}",
    '#default_value' => isset($element['#value']['imceimage_alt']) ? check_plain($element['#value']['imceimage_alt']) : NULL,
    '#autocomplete_path' => $element['#autocomplete_path'],
    '#rows' => 1,
    '#attributes' => array(
      'class' => 'text',
    ),
    '#title' => t('Alternate Text'),
    '#description' => t('The alternate text (or ALT, or caption) for this image.'),
  );
  $element['imce_widget_container']['imceimage_title'] = array(
    '#type' => 'textfield',
    '#id' => "imceimagetitle-{$delta}-{$field_id}",
    '#default_value' => isset($element['#value']['imceimage_title']) ? check_plain($element['#value']['imceimage_title']) : NULL,
    '#autocomplete_path' => $element['#autocomplete_path'],
    '#rows' => 1,
    '#attributes' => array(
      'class' => 'text',
    ),
    '#title' => t('Title'),
    '#description' => t('The title text for this image.'),
  );
  return $element;
}