You are here

function _filefield_extension_for_file in FileField 6.2

Common implementation of filefield_widget_for_file() and filefield_formatter_for_file().

2 calls to _filefield_extension_for_file()
filefield_formatter_for_file in ./filefield.module
Determine which formatter will be used for displaying the edit form for the given file.
filefield_widget_for_file in ./filefield.module
Determine which widget will be used for displaying the edit form for the given file.

File

./filefield.module, line 614

Code

function _filefield_extension_for_file($file_extension_info, $suitability_args) {
  $suitable_extension_info = array();
  foreach ($file_extension_info as $extension_name => $info) {
    if (!$info['enabled']) {
      continue;

      // the admin disabled this widget or formatter
    }
    $handles_file = $info['suitability callback'];

    // Either $handles_file is TRUE already or it's a function that
    // will return TRUE if the widget/formatter handles this file.
    if (is_string($handles_file)) {
      $handles_file = call_user_func_array($handles_file, $suitability_args);
    }
    if ($handles_file !== TRUE) {
      continue;

      // this widget/formatter is not interested in our file
    }
    $suitable_extension_info[] = $info;
  }

  // Return the most appropriate widget/formatter, if one was found.
  return empty($suitable_extension_info) ? NULL : reset($suitable_extension_info);
}