1.20.x file.admin.inc file_display_form($form, &$form_state, $file_type, $view_mode)

Form callback; presents file display settings for a given view mode.

File

modules/file/file.admin.inc, line 295
Admin page callbacks for the File module.

Code

function file_display_form($form, &$form_state, $file_type, $view_mode) {
  $form['#file_type'] = $file_type->type;
  $form['#view_mode'] = $view_mode;
  $form['#tree'] = TRUE;
  $form['#attached']['js'][] = backdrop_get_path('module', 'file') . '/js/file.admin.js';

  // Retrieve available formatters for this file type.
  $formatters = file_info_formatter_types();

  foreach ($formatters as $name => $formatter) {
    if (!empty($formatter['hidden'])) {
      unset($formatters[$name]);
    }
    if (isset($formatter['mime types'])) {
      if (file_match_mimetypes($formatter['mime types'], $file_type->mimetypes)) {
        continue;
      }
      unset($formatters[$name]);
    }
  }

  $display = file_display_load($file_type->type, $view_mode);

  // Formatter type.
  $form['display']['formatter'] = array(
    '#type' => 'radios',
    '#title' => t('Display type'),
    '#options' => array(),
    '#default_value' => config_get('file_display.' . $file_type->type, $view_mode . '.formatter'),
  );

  $formatters = array_reverse($formatters);

  foreach ($formatters as $name => $formatter) {
    $form['display']['formatter']['#options'][$name] = check_plain($formatter['label']);
    $form['display']['formatter'][$name]['#description'] = isset($formatter['description']) ? filter_xss($formatter['description']) : NULL;

    if (isset($formatter['settings callback']) && ($function = $formatter['settings callback']) && function_exists($function)) {

      $defaults = !empty($formatter['default settings']) ? $formatter['default settings'] : array();
      $settings = !empty($display['settings'][$name]) ? $display['settings'][$name] : array();
      $settings += $defaults;

      $settings_form = $function($form, $form_state, $settings, $name, $file_type->type, $view_mode);

      if (!empty($settings_form)) {
        $form['display']['settings'][$name] = array(
          '#type' => 'fieldset',
          '#title' => check_plain($formatter['label']) . ' ' . t('settings'),
          '#parents' => array('display', 'settings', $name),
          '#group' => 'display_settings',
          '#states' => array(
            'visible' => array(
              ':input[name="display[formatter]"]' => array('value' => $name),
            ),
          ),
        ) + $settings_form;
      }
    }
  }

  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );

  return $form;
}