You are here

function node_privacy_byrole_node_operations in node privacy byrole 5

Same name and namespace in other branches
  1. 6 node_privacy_byrole.module \node_privacy_byrole_node_operations()

File

./node_privacy_byrole.module, line 366

Code

function node_privacy_byrole_node_operations() {
  global $form_values;
  $operations = array();
  foreach (user_roles() as $rid => $role) {
    $grants = array();
    $revokes = array();
    foreach (array(
      'view',
      'edit',
      'delete',
    ) as $priv) {
      $grants['grant-' . $rid . '-' . $priv] = t('Grant !priv for !role', array(
        '!priv' => $priv,
        '!role' => $role,
      ));
      $revokes['revoke-' . $rid . '-' . $priv] = t('Revoke !priv for !role', array(
        '!priv' => $priv,
        '!role' => $role,
      ));
    }
    $operations[t('Access for role !role', array(
      '!role' => $role,
    ))] = array(
      'label' => $grants + $revokes,
    );
  }

  // If the form has been posted, we need to map the callback
  if ($form_values) {
    $operation_args = explode('-', $form_values['operation']);
    if ($operation_args[0] == 'grant' || $operation_args[0] == 'revoke') {
      if (user_access('administer content')) {
        $op = $operation_args[0] == 'grant' ? 1 : 0;
        $operations[$form_values['operation']] = array(
          'callback' => 'node_privacy_byrole_node_operations_update',
          'callback arguments' => array(
            $op,
            $operation_args[1],
            $operation_args[2],
          ),
        );
      }
      else {
        watchdog('security', t('Detected unauthorized attempt to alter content access permissions.'), WATCHDOG_WARNING);
        return;
      }
    }
  }
  return $operations;
}