function taxonomy_access_admin_form_submit in Taxonomy Access Control 6
Same name and namespace in other branches
- 5.2 taxonomy_access_admin.inc \taxonomy_access_admin_form_submit()
Submit handler for the administration form at admin/user/taxonomy_access.
File
- ./
taxonomy_access.admin.inc, line 368 - Administrative interface for taxonomy access control.
Code
function taxonomy_access_admin_form_submit($form, &$form_state) {
$values = $form_state['values'];
switch ($values['op']) {
case t('Delete selected'):
if (is_array($values['selected_terms'])) {
foreach ($values['selected_terms'] as $tid => $enabled) {
if ($enabled) {
$affected_nodes = _taxonomy_access_get_nodes_for_term($tid);
db_query('DELETE FROM {term_access} WHERE rid = %d AND tid = %d', $values['rid'], $tid);
_taxonomy_access_cache_affected_nodes($affected_nodes);
}
}
}
if (is_array($values['selected_defaults'])) {
foreach ($values['selected_defaults'] as $vid => $enabled) {
if ($enabled) {
$affected_nodes = _taxonomy_access_get_nodes_for_vocabulary($vid, $values['rid']);
db_query("DELETE FROM {term_access_defaults} WHERE rid = %d AND vid = %d", $values['rid'], $vid);
_taxonomy_access_cache_affected_nodes($affected_nodes);
}
}
}
// Update any affected nodes.
$affected_nodes = _taxonomy_access_cache_affected_nodes();
if (!empty($affected_nodes)) {
_taxonomy_access_node_access_update($affected_nodes);
}
break;
case t('Add'):
$new = $values['new'];
list($type, $id) = explode(' ', $new['item']);
if ($type == 'term') {
if ($new['recursive'] == 1) {
taxonomy_access_set_recursive_grants($id, $values['rid'], $new['grants']);
}
else {
taxonomy_access_set_term_grants($id, $values['rid'], $new['grants']);
}
}
elseif ($type == 'default') {
taxonomy_access_set_default_grants($id, $values['rid'], $new['grants']);
}
// Update any affected nodes.
$affected_nodes = _taxonomy_access_cache_affected_nodes();
if (!empty($affected_nodes)) {
_taxonomy_access_node_access_update($affected_nodes);
}
break;
case t('Save all'):
foreach ($values['grants'] as $vid => $rows) {
foreach ($rows as $tid => $grants) {
// Check the default values for this row.
$defaults = array();
foreach ($grants as $grant_name => $value) {
$defaults[$grant_name] = $form['grants'][$vid][$tid][$grant_name]['#default_value'];
}
// Proceed if the user changed the row (values differ from defaults).
if ($defaults != $grants) {
// If the grants for node access match the defaults, then we
// can skip updating node access records for this row.
$skip_nodes = TRUE;
foreach (array(
'view',
'update',
'delete',
) as $op) {
if ($defaults[$op] != $grants[$op]) {
$skip_nodes = FALSE;
}
}
if ($tid == 0) {
taxonomy_access_set_default_grants($vid, $values['rid'], $grants, $skip_nodes);
}
else {
taxonomy_access_set_term_grants($tid, $values['rid'], $grants, $skip_nodes);
}
}
}
}
// Update any affected nodes.
$affected_nodes = _taxonomy_access_cache_affected_nodes();
if (!empty($affected_nodes)) {
_taxonomy_access_node_access_update($affected_nodes);
}
drupal_goto('admin/user/taxonomy_access');
break;
}
}