You are here

function _upload_element_add_file_validators in Upload element 6

This is used to set the default validators

We are in a catch-22 here. If we set it in hook_elements, the chances are that these will be overridden by any user defined values. If we set these in the #process callback, the options are not available to form_type_"hook"_value or theme functions.

As such, we dynamically add these here.

1 call to _upload_element_add_file_validators()
theme_upload_element_file_description in ./upload_element.module
This theming function can be used to assign different text to the description that is found under the file HTML element.

File

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

Code

function _upload_element_add_file_validators(&$element) {

  // Add the default validators.
  if ($element['#type'] == 'image_upload_element') {
    $element['#file_validators']['file_validate_is_image'] = array();
  }

  // Check user defined max size is not greater than form/post size.
  $max = file_upload_max_size();
  if (isset($element['#file_validators']['file_validate_size'])) {
    if ($element['#file_validators']['file_validate_size'][0] > $max) {
      $element['#file_validators']['file_validate_size'] = array(
        $max,
      );
    }
  }
  else {
    $element['#file_validators']['file_validate_size'] = array(
      $max,
    );
  }
}