You are here

function file_managed_file_pre_render in Drupal 7

#pre_render callback to hide display of the upload or remove controls.

Upload controls are hidden when a file is already uploaded. Remove controls are hidden when there is no file attached. Controls are hidden here instead of in file_managed_file_process(), because #access for these buttons depends on the managed_file element's #value. See the documentation of form_builder() for more detailed information about the relationship between #process, #value, and #access.

Because #access is set here, it affects display only and does not prevent JavaScript or other untrusted code from submitting the form as though access were enabled. The form processing functions for these elements should not assume that the buttons can't be "clicked" just because they are not displayed.

See also

file_managed_file_process()

form_builder()

1 string reference to 'file_managed_file_pre_render'
file_element_info in modules/file/file.module
Implements hook_element_info().

File

modules/file/file.module, line 756
Defines a "managed_file" Form API field and a "file" field for Field module.

Code

function file_managed_file_pre_render($element) {

  // If we already have a file, we don't want to show the upload controls.
  if (!empty($element['#value']['fid'])) {
    $element['upload']['#access'] = FALSE;
    $element['upload_button']['#access'] = FALSE;
  }
  else {
    $element['remove_button']['#access'] = FALSE;
  }
  return $element;
}