| Drupal | PHP Cross Reference | Content Management Systems |
1 <?php 2 3 /** 4 * @file 5 * Provides File module pages for testing purposes. 6 */ 7 8 /** 9 * Implements hook_menu(). 10 */ 11 function file_module_test_menu() { 12 $items = array(); 13 14 $items['file/test'] = array( 15 'title' => 'Managed file test', 16 'page callback' => 'drupal_get_form', 17 'page arguments' => array('file_module_test_form'), 18 'access arguments' => array('access content'), 19 ); 20 21 return $items; 22 } 23 24 /** 25 * Form constructor for testing a 'managed_file' element. 26 * 27 * @see file_module_test_form_submit() 28 * @ingroup forms 29 */ 30 function file_module_test_form($form, &$form_state, $tree = TRUE, $extended = FALSE, $default_fid = NULL) { 31 $form['#tree'] = (bool) $tree; 32 33 $form['nested']['file'] = array( 34 '#type' => 'managed_file', 35 '#title' => t('Managed file'), 36 '#upload_location' => 'public://test', 37 '#progress_message' => t('Please wait...'), 38 '#extended' => (bool) $extended, 39 '#size' => 13, 40 ); 41 if ($default_fid) { 42 $form['nested']['file']['#default_value'] = $extended ? array('fid' => $default_fid) : $default_fid; 43 } 44 45 $form['textfield'] = array( 46 '#type' => 'textfield', 47 '#title' => t('Type a value and ensure it stays'), 48 ); 49 50 $form['submit'] = array( 51 '#type' => 'submit', 52 '#value' => t('Save'), 53 ); 54 55 return $form; 56 } 57 58 /** 59 * Form submission handler for file_module_test_form(). 60 */ 61 function file_module_test_form_submit($form, &$form_state) { 62 if ($form['#tree']) { 63 $fid = $form['nested']['file']['#extended'] ? $form_state['values']['nested']['file']['fid'] : $form_state['values']['nested']['file']; 64 } 65 else { 66 $fid = $form['nested']['file']['#extended'] ? $form_state['values']['file']['fid'] : $form_state['values']['file']; 67 } 68 drupal_set_message(t('The file id is %fid.', array('%fid' => $fid))); 69 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
title