You are here

function simple_access_group_grant_form in Simple Access 8.3

Same name and namespace in other branches
  1. 6.2 simple_access.module \simple_access_group_grant_form()
  2. 7.2 simple_access.module \simple_access_group_grant_form()

Configure grant group permissions.

File

./simple_access.module, line 619
Builds simple access definition for content access.

Code

function simple_access_group_grant_form($context) {
  $form = [];
  $display = variable_get('simple_access_display', [
    'view' => 1,
    'update' => 0,
    'delete' => 0,
  ]);
  $form['sa_group_permissions'] = [
    '#tree' => TRUE,
    '#theme' => 'simple_access_form',
    '#attached' => [
      'css' => [
        drupal_get_path('module', 'simple_access') . '/simple_access.css',
      ],
    ],
  ];
  $groups = simple_access_group_select();

  // To prevent a php notice.
  if (!isset($context['sa_group_permissions'])) {
    $context['sa_group_permissions'] = [];
  }
  foreach ($groups as $gid => $group) {
    $priv = $group['access'] || user_access('administer nodes');
    $form['sa_group_permissions'][$gid] = [
      '#access' => $priv,
    ];
    $form['sa_group_permissions'][$gid]['name'] = [
      '#markup' => $group['name'],
    ];
    $form['sa_group_permissions'][$gid]['sa_view'] = [
      '#type' => 'checkbox',
      '#default_value' => isset($context['sa_group_permissions'][$gid]['sa_view']) ? $context['sa_group_permissions'][$gid]['sa_view'] : 0,
      '#access' => $priv && $display['view'],
    ];
    $form['sa_group_permissions'][$gid]['sa_update'] = [
      '#type' => 'checkbox',
      '#default_value' => isset($context['sa_group_permissions'][$gid]['sa_update']) ? $context['sa_group_permissions'][$gid]['sa_update'] : 0,
      '#access' => $priv && $display['update'],
    ];
    $form['sa_group_permissions'][$gid]['sa_delete'] = [
      '#type' => 'checkbox',
      '#default_value' => isset($context['sa_group_permissions'][$gid]['sa_delete']) ? $context['sa_group_permissions'][$gid]['sa_delete'] : 0,
      '#access' => $priv && $display['delete'],
    ];
  }
  return $form;
}