You are here

function file_entity_list_types_page in File Entity (fieldable files) 7.3

Same name and namespace in other branches
  1. 7 file_entity.admin.inc \file_entity_list_types_page()
  2. 7.2 file_entity.admin.inc \file_entity_list_types_page()

Displays the file type admin overview page.

1 string reference to 'file_entity_list_types_page'
file_entity_menu in ./file_entity.module
Implements hook_menu().

File

./file_entity.admin.inc, line 570

Code

function file_entity_list_types_page() {
  $file_entity_info = entity_get_info('file');

  // Newer versions of Drupal core require the "administer fields" permission
  // to access the Field UI.
  $field_ui = module_exists('field_ui') && (user_access('administer fields') || !function_exists('field_ui_admin_access'));
  $colspan = $field_ui ? 5 : 3;
  $header = array(
    array(
      'data' => t('Name'),
    ),
    array(
      'data' => t('Operations'),
      'colspan' => $colspan,
    ),
    array(
      'data' => t('Status'),
    ),
  );
  $rows = array();
  $weight = 0;
  $types = file_type_load_all(TRUE);
  $count = count($types);
  foreach ($types as $type) {
    $weight++;
    $row = array(
      array(
        'data' => theme('file_entity_file_type_overview', array(
          'label' => $type->label,
          'description' => $type->description,
        )),
      ),
    );
    $path = isset($file_entity_info['bundles'][$type->type]['admin']['real path']) ? $file_entity_info['bundles'][$type->type]['admin']['real path'] : NULL;
    if (empty($type->disabled) && isset($path)) {
      $row[] = array(
        'data' => l(t('edit file type'), $path . '/edit'),
      );
      if ($field_ui) {
        $row[] = array(
          'data' => l(t('manage fields'), $path . '/fields'),
        );
        $row[] = array(
          'data' => l(t('manage display'), $path . '/display'),
        );
      }
      $row[] = array(
        'data' => l(t('manage file display'), $path . '/file-display'),
      );
    }
    else {
      $row += array_fill(1, $colspan - 1, '');
    }
    $admin_path = 'admin/structure/file-types/manage/' . $type->type;
    switch ($type->ctools_type) {

      // Configuration is in code.
      case 'Default':
      case t('Default'):
        if (!empty($type->disabled)) {
          $row[] = l(t('enable'), $admin_path . '/enable');
        }
        else {
          $row[] = l(t('disable'), $admin_path . '/disable');
        }
        break;

      // Configuration is in DB.
      case 'Normal':
      case t('Normal'):
        if (!empty($type->disabled)) {
          $status = l(t('enable'), $admin_path . '/enable');
        }
        else {
          $status = l(t('disable'), $admin_path . '/disable');
        }
        $row[] = $status . ' | ' . l(t('delete'), $admin_path . '/delete');
        break;

      // Configuration is in code, but overridden in DB.
      case 'Overridden':
      case t('Overridden'):
        if (!empty($type->disabled)) {
          $row[] = l(t('enable'), $admin_path . '/enable');
        }
        else {
          $row[] = l(t('disable'), $admin_path . '/disable') . ' | ' . l(t('revert'), $admin_path . '/revert');
        }
        break;
    }
    if (!empty($type->disabled)) {
      $row[] = t('Disabled');
      $rows[$weight + $count] = array(
        'data' => $row,
        'class' => array(
          'ctools-export-ui-disabled',
        ),
      );
    }
    else {
      $row[] = $type->ctools_type;
      $rows[$weight] = array(
        'data' => $row,
      );
    }
  }

  // Move disabled items to the bottom.
  ksort($rows);
  $build['file_type_table'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => t('No file types available.'),
    '#attached' => array(
      'css' => array(
        drupal_get_path('module', 'ctools') . '/css/export-ui-list.css',
      ),
    ),
  );
  return $build;
}