You are here

function theme_nodeaccess_grants_form in Nodeaccess 7

Same name and namespace in other branches
  1. 5 nodeaccess.module \theme_nodeaccess_grants_form()
  2. 6.2 nodeaccess.module \theme_nodeaccess_grants_form()
  3. 6 nodeaccess.module \theme_nodeaccess_grants_form()

Theme function for nodeaccess_grants_form.

Parameters

array $vars:

Return value

string

File

./nodeaccess.module, line 512
Provide per node access control

Code

function theme_nodeaccess_grants_form($vars) {
  $output = '';
  $form = $vars['form'];
  $rows = array();
  $allowed_roles = variable_get('nodeaccess-roles', array());
  $allowed_grants = variable_get('nodeaccess-grants', array());

  // Retrieve role names for columns.
  $role_names = user_roles();
  $role_aliases = nodeaccess_get_role_aliases();

  // Replace names with aliases.
  foreach ($role_names as $rid => $name) {
    if (isset($role_aliases[$rid]['alias'])) {
      $role_names[$rid] = $role_aliases[$rid]['alias'];
    }
  }

  // Roles table.
  $roles = element_children($form['rid']);
  if (count($roles) && count($allowed_roles)) {
    $header = array();
    $header[] = t('Role');
    if ($allowed_grants['view']) {
      $header[] = t('View');
    }
    if ($allowed_grants['edit']) {
      $header[] = t('Edit');
    }
    if ($allowed_grants['delete']) {
      $header[] = t('Delete');
    }
    foreach ($roles as $key) {
      if (isset($allowed_roles[$key]) && $allowed_roles[$key]) {
        $row = array();
        $row[] = $role_names[$key] . drupal_render($form['rid'][$key]['name']);
        if ($allowed_grants['view']) {
          $row[] = drupal_render($form['rid'][$key]['grant_view']);
        }
        if ($allowed_grants['edit']) {
          $row[] = drupal_render($form['rid'][$key]['grant_update']);
        }
        if ($allowed_grants['delete']) {
          $row[] = drupal_render($form['rid'][$key]['grant_delete']);
        }
        $rows[] = $row;
      }
    }
    $output .= theme('table', array(
      'header' => $header,
      'rows' => $rows,
    ));
  }

  // Search form.
  $output .= '<p><div class="search-form">';
  $output .= '<strong>' . t('Enter names to search for users:') . '</strong>';
  $output .= '<div class="container-inline">';
  $output .= drupal_render($form['keys']);
  $output .= drupal_render($form['search']);
  $output .= '</div></div></p>';

  // Users table.
  unset($rows);
  $users = element_children($form['uid']);
  if (count($users) > 0) {
    $header = array();
    $rows = array();
    $header[] = t('User');
    $header[] = t('Keep?');
    if ($allowed_grants['view']) {
      $header[] = t('View');
    }
    if ($allowed_grants['edit']) {
      $header[] = t('Edit');
    }
    if ($allowed_grants['delete']) {
      $header[] = t('Delete');
    }
    foreach ($users as $key) {
      $row = array();
      $row[] = $form['uid'][$key]['name']['#value'];
      $row[] = drupal_render($form['uid'][$key]['keep']);
      if ($allowed_grants['view']) {
        $row[] = drupal_render($form['uid'][$key]['grant_view']);
      }
      if ($allowed_grants['edit']) {
        $row[] = drupal_render($form['uid'][$key]['grant_update']);
      }
      if ($allowed_grants['delete']) {
        $row[] = drupal_render($form['uid'][$key]['grant_delete']);
      }
      $rows[] = $row;
    }
    $output .= theme('table', array(
      'header' => $header,
      'rows' => $rows,
    ));
  }
  $output .= drupal_render_children($form);
  return $output;
}