You are here

function _tac_fields_admin_for_field in Taxonomy Access Control 6

Renders admin table for each field, with links to configure each role.

@todo Return empty string if the field is not a controlled field?

Parameters

$field: The machine name of the content field.

Return value

String of HTML markup containing a header and table.

1 call to _tac_fields_admin_for_field()
theme_tac_fields_admin in tac_fields/tac_fields.admin.inc
Renders the main admin page (at admin/user/tac_fields).

File

tac_fields/tac_fields.admin.inc, line 74
Administrative interface for TAC Fields.

Code

function _tac_fields_admin_for_field($field) {
  $output = '';
  $output .= "<h2>" . t("Configuration for %field", array(
    '%field' => $field,
  )) . "</h2>" . t('To delete all access rules below and return this field to its default behavior, you can <a href="@path">release control of %field</a>.', array(
    '%field' => $field,
    '@path' => url("admin/user/tac_fields/delete/{$field}"),
  ));
  $roles = _taxonomy_access_user_roles();

  // Render role/permission overview:
  $header = array(
    t('Role'),
    array(
      'data' => '&nbsp;',
    ),
  );
  $rows = array();
  $result = db_query("SELECT rid FROM {term_field_access_defaults} WHERE vid=0 AND field='%s'", $field);
  $active = array();
  while ($role = db_fetch_array($result)) {
    $active[$role['rid']] = TRUE;
  }
  foreach ($roles as $rid => $name) {
    $ops = array();
    if (!empty($active[$rid])) {

      //only allow delete for "extra" roles
      if ($rid > 2) {
        $ops[] = l(t("disable"), "admin/user/tac_fields/delete/{$field}/{$rid}");
      }
      $ops[] = l(t("edit"), "admin/user/tac_fields/edit/{$field}/{$rid}");
    }
    else {
      $ops = array(
        l(t("enable"), "admin/user/tac_fields/edit/{$field}/{$rid}"),
      );
    }
    $rows[] = array(
      $name,
      array(
        'data' => implode(' | ', $ops),
        'align' => 'right',
      ),
    );
  }
  $output .= theme('table', $header, $rows);
  return $output;
}