1 file.admin.inc file_list_types_page()

Displays the file type admin overview page.

File

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

Code

function file_list_types_page() {
  $file_entity_info = entity_get_info('file');
  $types = file_type_get_types();
  $names = file_type_get_names();
  $field_ui = module_exists('field_ui') && user_access('administer fields');
  $header = array(t('Name'), t('Description'), t('Storage state'), t('Operations'));
  $rows_enabled = array();
  $rows_disabled = array();
  $weight = 0;

  // Sort the list of content types by name instead of machine name.
  natcasesort($names);

  foreach ($names as $key => $type) {
    $links = array();
    $type = $types[$key];
    $weight++;
    $row = array(
      array(
        'data' => theme('label_machine_name__file', array(
          'label' => $type->name,
          'machine_name' => $type->type,
        )),
      ),
      filter_xss_admin($type->description),
    );


    if ($type->storage === FILE_TYPE_STORAGE_OVERRIDE) {
      $storage_state = t('Overridden');
    }
    elseif ($type->storage === FILE_TYPE_STORAGE_DEFAULT) {
      $storage_state = t('Default (module-provided)');
    }
    else {
      $storage_state = t('Custom');
    }
    $row[] = $storage_state;


    $path = isset($file_entity_info['bundles'][$type->type]['admin']['real path']) ? $file_entity_info['bundles'][$type->type]['admin']['real path'] : NULL;

    $links['configure'] = array(
      'title' => t('Configure'),
      'href' => $path,
      'weight' => 0,
    );

    if ($field_ui) {
      $links['fields'] = array(
        'title' => t('Manage fields'),
        'href' => $path . '/fields',
        'weight' => 5,
      );
      $links['display'] = array(
        'title' => t('Manage display'),
        'href' => $path . '/display',
        'weight' => 10,
      );
    }
    $links['file-display'] = array(
      'title' => t('Manage file display'),
      'href' => $path . '/file-display',
      'weight' => 11,
    );

    if ($type->disabled) {
      $links['enable'] = array(
        'title' => t('Enable'),
        'href' => $path . '/enable',
        'query' => array('token' => backdrop_get_token($type->type)),
        'weight' => -10,
      );
    }
    else {
      $links['disable'] = array(
        'title' => t('Disable'),
        'href' => $path . '/disable',
        'query' => array('token' => backdrop_get_token($type->type)),
        'weight' => 20,
      );
    }

    if ($type->storage == FILE_TYPE_STORAGE_OVERRIDE) {
      $links['revert'] = array(
        'title' => t('Revert'),
        'href' => $path . '/revert',
        'weight' => 15,
      );
    }
    elseif ($type->storage == FILE_TYPE_STORAGE_NORMAL) {
      $links['delete'] = array(
        'title' => t('Delete'),
        'href' => $path . '/delete',
        'weight' => 25,
      );
    }

    backdrop_sort($links);
    $row[] = array(
      'data' => array(
        '#type' => 'operations',
        '#links' => $links,
      ),
    );

    if ($type->disabled) {
      $rows_disabled[] = array(
        'data' => $row,
        'class' => array('disabled'),
      );
    }
    else {
      $rows_enabled[] = array(
        'data' => $row,
        'class' => array('enabled'),
      );
    }
  }

  $rows = array_merge($rows_enabled, $rows_disabled);

  $build['file_table'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => t('No file types available. <a href="@link">Add file type</a>.', array('@link' => url('admin/structure/types/add'))),
  );

  return $build;
}