You are here

function _upload_element_action_field in Upload element 6

Private function to generate the options that go with the upload element

Parameters

array $element Parent upload element:

Return value

array $children Child elements

1 call to _upload_element_action_field()
theme_upload_element in ./upload_element.module
Theme function to format the edit form.

File

./upload_element.module, line 347
A module that provides two new elements to the FAPI for file handling.

Code

function _upload_element_action_field($element) {
  $children = array();
  if (is_object($element['#value'])) {
    $name = $element['#name'];
    $key = $name . '_action';
    $children[$key] = array(
      '#type' => 'checkbox',
      '#id' => form_clean_id("edit-{$key}"),
      '#name' => "{$name}[{$key}]",
      '#value' => 0,
      '#weight' => -10,
    );

    // TODO: While this is working, there may be two logical bugs
    // the negate each other.
    if (upload_element_equals($element['#value'], $element['#default_value'])) {
      if (isset($element['#value']->submit_action) && $element['#value']->submit_action == UPLOAD_ELEMENT_DELETE) {
        $children[$key]['#return_value'] = 'restore';
        $children[$key]['#title'] = t('Restore original');
      }
      else {
        $children[$key]['#return_value'] = 'delete';
        $children[$key]['#title'] = t('Delete original');
        $children[$key]['#value'] = isset($element['#value']->submit_action) ? $element['#value']->submit_action == UPLOAD_ELEMENT_DELETE ? 'delete' : 0 : 0;
      }
    }
    else {
      $children[$key]['#return_value'] = 'revert';
      $children[$key]['#title'] = is_object($element['#default_value']) ? t('Discard replacment') : t('Discard upload');
    }
  }
  return drupal_render($children);
}