You are here

function filefield_validate_file_widget_support in FileField 6.2

Check that a file is supported by at least one of the widgets that are enabled for the field instance in question.

Return value

An array. If the file is not allowed, it will contain an error message.

File

./filefield.widget.inc, line 339
FileField: Defines a CCK file field type.

Code

function filefield_validate_file_widget_support($file, $field, $field_widget, $supported_file_widgets) {
  $errors = array();

  // No widgets at all means the widget settings db entry does not exist,
  // so we fall back to "accept this file and use the generic edit widget".
  if (empty($field_widget['file_widgets'])) {
    return $errors;
  }

  // In the common case, we only accept a file if an enabled widget
  // wants to handle it.
  $edit_widget_info = filefield_widget_for_file($file, $field, $field_widget);
  if (empty($edit_widget_info)) {
    $errors[] = t('Uploaded files are restricted to the following categories: !widgets.', array(
      '!widgets' => implode(', ', $supported_file_widgets),
    ));
  }
  return $errors;
}