You are here

function block_access_form_alter in Block Access 7

Same name and namespace in other branches
  1. 6.2 block_access.module \block_access_form_alter()
  2. 6 block_access.module \block_access_form_alter()

File

./block_access.module, line 469

Code

function block_access_form_alter(&$form, &$form_state, $form_id) {

  // Only alter the form we're interested in
  if ($form_id == BLOCK_ACCESS_FORM_ADMIN) {

    // loop over all values, ignoring those that are not block arrays
    foreach ($form['blocks'] as $key => $block) {

      // it's a block array if it has the info attribute (assumption)
      if (is_array($block) && isset($block['info'])) {
        block_access_check_perms($form, $key, $block);
      }
    }

    // override the submit button to run perm validation before block.admin
    $form['#submit'][] = 'block_access_admin_display_submit';
  }
  elseif ($form_id == BLOCK_ACCESS_FORM_CONFIG || $form_id == BLOCK_ACCESS_FORM_ADD) {
    $role_options = user_roles();
    $module = $form['module']['#value'];
    $delta = $form['delta']['#value'];

    // Add fieldset for each permission if they have permission to change permissions
    if (user_access('administer permissions')) {
      block_access_fieldset($form, $role_options, 'view', $module, $delta);
      block_access_fieldset($form, $role_options, 'move', $module, $delta);
      block_access_fieldset($form, $role_options, 'enable', $module, $delta);
      block_access_fieldset($form, $role_options, 'disable', $module, $delta);
      block_access_fieldset($form, $role_options, 'delete', $module, $delta);
      block_access_fieldset($form, $role_options, 'config', $module, $delta);
      block_access_fieldset($form, $role_options, 'config_lang', $module, $delta);
      block_access_fieldset($form, $role_options, 'config_title', $module, $delta);
      block_access_fieldset($form, $role_options, 'config_desc', $module, $delta);
      block_access_fieldset($form, $role_options, 'config_body', $module, $delta);
      block_access_fieldset($form, $role_options, 'config_region', $module, $delta);
      block_access_fieldset($form, $role_options, 'config_page_visibility', $module, $delta);
      block_access_fieldset($form, $role_options, 'config_type_visibility', $module, $delta);
      block_access_fieldset($form, $role_options, 'config_role_visibility', $module, $delta);
      block_access_fieldset($form, $role_options, 'config_user_visibility', $module, $delta);
    }
    $form['#submit'][] = 'block_access_config_submit';
    $form['submit']['#weight'] = 99;
    block_access_check_config_form($form);
  }
}