Example #1
0
function tac_admin_submit($form, &$form_state)
{
    db_delete('tac_map')->execute();
    $vocabulary = $form_state['values']['vocabulary'];
    if ($vocabulary > 0 && $vocabulary != variable_get('tac_vocabulary')) {
        variable_set('tac_vocabulary', $vocabulary);
        node_access_needs_rebuild(TRUE);
        return;
    } elseif ($vocabulary <= 0) {
        variable_del('tac_vocabulary');
        node_access_needs_rebuild(TRUE);
        return;
    }
    $insert = db_insert('tac_map')->fields(array('rid', 'tid', 'grant_list', 'grant_create', 'grant_update', 'grant_delete'));
    foreach ($form_state['values']['edit'] as $rid => $terms) {
        foreach ($terms as $tid => $grants) {
            $insert->values(array($rid, $tid, $grants['list'], $grants['create'], $grants['update'], $grants['delete']));
        }
    }
    $insert->execute();
}
 /**
  * Stores permission settings for workflow states.
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     foreach ($form_state->getValues() as $sid => $access) {
         // @todo: not waterproof; can be done smarter, using elementchildren()..
         if (!WorkflowState::load($sid)) {
             continue;
         }
         foreach ($access['view'] as $rid => $checked) {
             $data[$rid] = array('grant_view' => !empty($checked) ? (bool) $checked : 0, 'grant_update' => !empty($access['update'][$rid]) ? (bool) $access['update'][$rid] : 0, 'grant_delete' => !empty($access['delete'][$rid]) ? (bool) $access['delete'][$rid] : 0);
         }
         workflow_access_insert_workflow_access_by_sid($sid, $data);
         // Update all nodes to reflect new settings.
         node_access_needs_rebuild(TRUE);
     }
     parent::submitForm($form, $form_state);
 }