You are here

function field_permissions_overview in Field Permissions 6

Same name and namespace in other branches
  1. 7 field_permissions.admin.inc \field_permissions_overview()

Menu callback; Field permissions overview.

1 string reference to 'field_permissions_overview'
_field_permissions_menu in includes/admin.inc
Implementation of hook_menu().

File

includes/admin.inc, line 129
Administrative interface for the Field Permissions module.

Code

function field_permissions_overview() {
  drupal_add_css(drupal_get_path('module', 'field_permissions') . '/css/field_permissions.admin.css');
  $headers = array(
    t('Field name'),
    t('Field type'),
    t('Used in'),
  );
  foreach (field_permissions_list() as $permission_type => $permission_info) {
    $headers[] = array(
      'data' => $permission_info['label'],
      'class' => 'field-permissions-header',
    );
  }

  // Load list of fields and types in the system.
  $content_fields = content_fields();
  uasort($content_fields, '_field_permissions_sort_fields');
  $field_types = _content_field_types();
  $destination = drupal_get_destination();
  $rows = array();
  foreach ($content_fields as $field_name => $field) {
    $row = array(
      $field['locked'] ? t('@field (Locked)', array(
        '@field' => $field['widget']['label'],
      )) : check_plain($field['widget']['label']),
      $field_types[$field['type']]['label'],
    );
    $types = array();
    $result = db_query("SELECT nt.name, nt.type FROM {" . content_instance_tablename() . "} nfi " . "LEFT JOIN {node_type} nt ON nt.type = nfi.type_name " . "WHERE nfi.field_name = '%s' " . "AND nfi.widget_active = 1 " . "ORDER BY nt.name ASC", $field_name);
    while ($type = db_fetch_array($result)) {
      $content_type = content_types($type['type']);
      if ($field['locked']) {
        $types[] = check_plain($type['name']);
      }
      else {
        $types[] = l($type['name'], 'admin/content/node-type/' . $content_type['url_str'] . '/fields/' . $field_name, array(
          'query' => $destination,
        ));
      }
    }
    $row[] = implode(', ', $types);
    $field_permissions = isset($field['field_permissions']) && is_array($field['field_permissions']) ? array_filter($field['field_permissions']) : array();
    foreach (array_keys(field_permissions_list()) as $permission_type) {
      if (!empty($field_permissions[$permission_type])) {
        $status = 'on';
        $title = t('Enabled');
      }
      else {
        $status = 'off';
        $title = t('Disabled');
      }
      $row[] = array(
        'data' => '<span class="field-permissions-status field-permissions-status-' . $status . '" title="' . check_plain($title) . '"></span>',
        'class' => 'field-permissions-cell',
      );
    }
    $rows[] = array(
      'data' => $row,
      'class' => $field['locked'] ? 'menu-disabled' : '',
    );
  }

  // Allow external modules alter the table headers and rows.
  foreach (module_implements('field_permissions_overview_alter') as $module) {
    $function = $module . '_field_permissions_overview_alter';
    $function($headers, $rows);
  }
  if (empty($rows)) {
    $rows[] = array(
      array(
        'data' => t('No fields have been defined for any content type yet.'),
        'colspan' => count($headers),
        'class' => 'field-permissions-cell',
      ),
    );
  }
  return theme('table', $headers, $rows);
}