You are here

function theme_taxonomy_access_admin_form in Taxonomy Access Control 5.2

Same name and namespace in other branches
  1. 6 taxonomy_access.admin.inc \theme_taxonomy_access_admin_form()

Renders the permission matrix user form for choosen user role.

File

./taxonomy_access_admin.inc, line 203
Administrative interface for taxonomy access control.

Code

function theme_taxonomy_access_admin_form($form) {
  $roles = _taxonomy_access_user_roles();
  $header = array(
    array(
      'data' => t('Category'),
      'colspan' => 3,
    ),
    array(
      'data' => t('View'),
      'colspan' => 4,
    ),
    array(
      'data' => t('Update'),
      'colspan' => 4,
    ),
    array(
      'data' => t('Delete'),
      'colspan' => 4,
    ),
    array(
      'data' => t('Create'),
    ),
    array(
      'data' => t('List'),
    ),
  );
  $sub_header = array(
    '&nbsp;<strong>' . t('A') . '</strong>',
    '&nbsp;<strong>' . t('I') . '</strong>',
    '&nbsp;<strong>' . t('D') . '</strong>',
    '&nbsp;',
  );
  $sub_header = array_merge(array(
    '&nbsp;',
  ), $sub_header, $sub_header, $sub_header);
  $sub_header = array_pad($sub_header, 15, '&nbsp;');
  $node_grant_types = array(
    'view',
    'update',
    'delete',
  );
  $radios = array(
    '1' => t('Allow'),
    '0' => t('Ignore'),
    '2' => t('Deny'),
  );
  drupal_set_title(t('Grants for %role', array(
    '%role' => $roles[$form['rid']['#value']],
  )));
  $rows = array();
  foreach (array_keys($form['vocabs']) as $vid) {
    if (is_numeric($vid) and isset($form['grants'][$vid])) {
      $row = $sub_header;
      $row[0] = array(
        'data' => '<h3>' . check_plain($form['vocabs'][$vid]['#title']) . '</h3>',
        'colspan' => 3,
      );
      $rows[] = $row;
      foreach (array_keys($form['grants'][$vid]) as $tid) {
        if (is_numeric($tid)) {
          $select_key = $tid ? 'selected_terms' : 'selected_defaults';
          $select_id = $tid ? $tid : $vid;
          $row = array(
            array(
              'data' => drupal_render($form[$select_key][$select_id]),
              'colspan' => 3,
            ),
          );
          foreach ($node_grant_types as $grant) {
            foreach (array_keys($radios) as $key) {

              // I need this hack to display radio buttons horizontally (instead of standard form 'radios')
              $row[] = array(
                'data' => drupal_render($form['grants'][$vid][$tid][$grant][$key]),
              );
            }
            $row[] = '&nbsp;';
          }
          foreach (array(
            'create',
            'list',
          ) as $grant) {
            $row[] = array(
              'data' => drupal_render($form['grants'][$vid][$tid][$grant]),
            );
          }
          $rows[] = $row;
        }
      }
    }
  }
  if (isset($form['new'])) {
    $row = array(
      array(
        'data' => drupal_render($form['new']['item']),
        'colspan' => 2,
      ),
      drupal_render($form['new']['add']),
    );
    foreach ($node_grant_types as $grant) {
      foreach (array_keys($radios) as $key) {

        // I need this hack to display radio buttons horizontally (instead of standard form 'radios')
        $row[] = array(
          'data' => drupal_render($form['new']['grants'][$grant][$key]),
        );
      }
      $row[] = '&nbsp;';
    }
    foreach (array(
      'create',
      'list',
    ) as $grant) {
      $row[] = array(
        'data' => drupal_render($form['new']['grants'][$grant]),
      );
    }
    $rows[] = $row;
    $row = array();
  }
  $output .= theme('table', $header, $rows);
  $output .= drupal_render($form);
  return $output;
}