You are here

function field_tools_field_overview in Field tools 8

Same name and namespace in other branches
  1. 7 field_tools.admin.inc \field_tools_field_overview()

Page callback for the field overview list.

1 string reference to 'field_tools_field_overview'
D7field_tools_menu in ./field_tools.module
Implements hook_menu().

File

./field_tools.admin.inc, line 11
NOTICE: THIS FILE IS OBSOLETE. IT IS BEING KEPT UNTIL ALL FUNCTIONALITY IS PORTED TO DRUPAL 8.

Code

function field_tools_field_overview() {
  $output = '';
  $entity_info = entity_get_info();
  $field_types = field_info_field_types();
  $fields = field_info_fields();

  // Sort the fields, defaulting to field name.
  $query = drupal_get_query_parameters();
  $sort = isset($query['sort']) ? check_plain($query['sort']) : 'field_name';
  uasort($fields, function ($a, $b) use ($sort, $field_types) {
    switch ($sort) {
      case 'type':

        // Sort by the field type label.
        return strcmp($field_types[$a[$sort]]['label'], $field_types[$b[$sort]]['label']);
      default:
        return strcmp($a[$sort], $b[$sort]);
    }
  });
  $rows = array();
  foreach ($fields as $field_name => $field) {
    $row = array();

    // Column: field name.
    $row[] = l($field_name, 'admin/reports/fields/field/' . $field_name);

    // Column: field type.
    $row[] = $field_types[$field['type']]['label'];

    // Column: field instances.
    $row[] = field_tools_field_instances_list($field);

    // Column : operations.
    $items_ops = array();
    $items_ops[] = l('edit instances', "admin/reports/fields/field/{$field_name}/edit");
    $items_ops[] = l('delete instances', "admin/reports/fields/field/{$field_name}/delete");
    $row[] = theme('item_list', array(
      'items' => $items_ops,
    ));
    $rows[] = $row;
  }
  $header = array(
    l(t('Field name'), current_path(), array(
      'query' => array(
        'sort' => 'field_name',
      ),
    )),
    l(t('Type'), current_path(), array(
      'query' => array(
        'sort' => 'type',
      ),
    )),
    t('Instances'),
    t('Operations'),
  );
  $output .= theme('table', array(
    'rows' => $rows,
    'header' => $header,
  ));
  drupal_add_css(drupal_get_path('module', 'field_tools') . '/field_tools.css');
  return $output;
}