function taxonomy_access_admin_form in Taxonomy Access Control 6
Same name and namespace in other branches
- 5.2 taxonomy_access_admin.inc \taxonomy_access_admin_form()
Form for managing grants by role.
Parameters
$rid: The role id.
2 string references to 'taxonomy_access_admin_form'
- taxonomy_access_admin in ./
taxonomy_access.admin.inc - Menu callback (for admin/user/taxonomy_access). Renders the TAC permissions administration form.
- taxonomy_access_menu in ./
taxonomy_access.module - Implements hook_menu().
File
- ./
taxonomy_access.admin.inc, line 169 - Administrative interface for taxonomy access control.
Code
function taxonomy_access_admin_form($form_state, $rid = NULL) {
// Fetch all default grants.
$result = db_query('SELECT * FROM {term_access_defaults} WHERE rid = %d', $rid);
while ($row = db_fetch_array($result)) {
$default_grants[$row['vid']] = $row;
}
// If we are adding a role, no global default is set yet, so insert it now.
if (empty($default_grants[0]) && isset($rid)) {
// Assemble a $row object for Schema API.
$row = new stdClass();
$row->vid = 0;
$row->rid = $rid;
// Insert the row with defaults for all grants.
drupal_write_record('term_access_defaults', $row);
}
// Fetch all grants.
$result = db_query('SELECT * FROM {term_access} WHERE rid = %d', $rid);
while ($row = db_fetch_array($result)) {
$grants[$row['tid']] = $row;
}
$form['instructions'] = array(
'#value' => _taxonomy_access_admin_instructions_html(),
'#weight' => '20',
);
$form['rid'] = array(
'#type' => 'value',
'#value' => $rid,
);
$form['grants'] = $form['selected_terms'] = $form['selected_defaults'] = array(
'#tree' => TRUE,
);
// Global default.
$global_defaults = empty($default_grants[0]) ? NULL : $default_grants[0];
$form['vocabs'][0]['#title'] = 'Global';
$form['grants'][0][0] = taxonomy_access_admin_build_row($global_defaults);
$form['selected_defaults'][0] = array(
'#type' => 'checkbox',
'#disabled' => TRUE,
'#title' => t('<em>default</em>'),
'#description' => t("can't be disabled without disabling TAC for this role"),
);
foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
$form['vocabs'][$vid]['#title'] = check_plain($vocabulary->name);
if (isset($default_grants[$vid])) {
$form['grants'][$vid][0] = taxonomy_access_admin_build_row($default_grants[$vid]);
$form['selected_defaults'][$vid] = array(
'#type' => 'checkbox',
'#title' => t('<em>default</em>'),
);
}
else {
$add_items[$vocabulary->name]["default {$vid}"] = t('*default*');
}
if ($tree = taxonomy_get_tree($vid)) {
foreach ($tree as $term) {
if (isset($grants[$term->tid])) {
$form['grants'][$vid][$term->tid] = taxonomy_access_admin_build_row($grants[$term->tid]);
$form['selected_terms'][$term->tid] = array(
'#type' => 'checkbox',
'#title' => str_repeat(' ', $term->depth) . check_plain($term->name),
);
}
else {
$add_items[$vocabulary->name]["term {$term->tid}"] = str_repeat('-', $term->depth) . check_plain($term->name);
}
}
}
}
// New grant row.
if (isset($add_items)) {
$form['new']['grants'] = taxonomy_access_admin_build_row();
$form['new']['#tree'] = TRUE;
$form['new']['item'] = array(
'#type' => 'select',
'#options' => $add_items,
);
$form['new']['recursive'] = array(
'#type' => 'checkbox',
'#title' => t('with children'),
'#description' => t('Add child terms recursively with these values.'),
);
$form['new']['add'] = array(
'#type' => 'submit',
'#value' => t('Add'),
);
}
$form['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete selected'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save all'),
);
return $form;
}