filefield_paths.admin.inc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * @file
  4. *
  5. * Administration functions for the File (Field) Paths module.
  6. */
  7. /**
  8. * @param $form
  9. * @param $form_state
  10. * @return mixed
  11. */
  12. function filefield_paths_settings_form($form, $form_state) {
  13. $form['filefield_paths_temp_location'] = array(
  14. '#title' => t('Temporary file location'),
  15. '#type' => 'textfield',
  16. '#default_value' => variable_get('filefield_paths_temp_location', 'public://filefield_paths'),
  17. '#description' => t('The location that unprocessed files will be uploaded priot to being processed by File (Field) Paths.<br />It is recommended that you use the temporary file system (temporary://) if your server configuration allows for that.'),
  18. '#element_validate' => array('filefield_paths_settings_form_temp_location_validate'),
  19. );
  20. return system_settings_form($form);
  21. }
  22. /**
  23. * Validation callback for 'Temporary file location' setting.
  24. *
  25. * @param $element
  26. * @param $form_state
  27. * @return bool
  28. */
  29. function filefield_paths_settings_form_temp_location_validate($element, $form_state) {
  30. $scheme = file_uri_scheme($element['#value']);
  31. if (!$scheme) {
  32. form_error($element, t('Invalid file location. You must include a file stream wrapper (e.g., public://).'));
  33. return FALSE;
  34. }
  35. if (!file_stream_wrapper_valid_scheme($scheme)) {
  36. form_error($element, t('Invalid file stream wrapper.'));
  37. return FALSE;
  38. }
  39. if ((!is_dir($element['#value']) || !is_writable($element['#value'])) && !file_prepare_directory($element['#value'], FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
  40. form_error($element, t('File location can not be created or is not writable.'));
  41. return FALSE;
  42. }
  43. }