You are here

function media_element_pre_render in D7 Media 7.3

Same name and namespace in other branches
  1. 7.4 media.module \media_element_pre_render()
  2. 7.2 media.module \media_element_pre_render()

#pre_render callback to hide display of the browse/attach or remove controls.

Browse/attach controls are hidden when a file is already attached. Remove controls are hidden when there is no file attached. Controls are hidden here instead of in media_element_process(), because #access for these buttons depends on the media 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

media_element_process()

form_builder()

1 string reference to 'media_element_pre_render'
media_element_info in ./media.module
Implements hook_element_info().

File

./media.module, line 1092
Media API

Code

function media_element_pre_render($element) {

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