You are here

function content_access_admin_settings_submit in Content Access 7

Same name and namespace in other branches
  1. 5 content_access.module \content_access_admin_settings_submit()
  2. 6 content_access.admin.inc \content_access_admin_settings_submit()

Submit handler for per content type settings form.

File

./content_access.admin.inc, line 163
Content access administration UI.

Code

function content_access_admin_settings_submit($form, &$form_state) {
  $roles_permissions = user_role_permissions(user_roles());
  $permissions = user_permission_get_modules();
  $type = $form_state['type'];

  // Remove disabled modules permissions, so they can't raise exception
  // in content_access_save_permissions()
  foreach ($roles_permissions as $rid => $role_permissions) {
    foreach ($role_permissions as $permission => $value) {
      if (!array_key_exists($permission, $permissions)) {
        unset($roles_permissions[$rid][$permission]);
      }
    }
  }
  foreach (array(
    'update',
    'update_own',
    'delete',
    'delete_own',
  ) as $op) {
    foreach ($form_state['values'][$op] as $rid => $value) {
      $permission = content_access_get_permission_by_op($op, $form_state['type']);
      if ($value) {
        $roles_permissions[$rid][$permission] = TRUE;
      }
      else {
        $roles_permissions[$rid][$permission] = FALSE;
      }
    }

    // Don't save the setting, so its default value (get permission) is applied
    // always.
    unset($form_state['values'][$op]);
  }
  content_access_save_permissions($roles_permissions);

  // Update content access settings
  $settings = content_access_get_settings('all', $type);
  foreach (content_access_available_settings() as $setting) {
    if (isset($form_state['values'][$setting])) {
      $settings[$setting] = is_array($form_state['values'][$setting]) ? array_keys(array_filter($form_state['values'][$setting])) : $form_state['values'][$setting];
    }
  }
  content_access_set_settings($settings, $type);

  // Mass update the nodes, but only if necessary.
  if (content_access_get_settings('per_node', $type) || content_access_get_settings('view', $type) != $form['per_role']['view']['#default_value'] || content_access_get_settings('view_own', $type) != $form['per_role']['view_own']['#default_value'] || content_access_get_settings('priority', $type) != $form['advanced']['priority']['#default_value'] || content_access_get_settings('per_node', $type) != $form['node']['per_node']['#default_value']) {

    // If per node has been disabled and we use the ACL integration, we have to remove possible ACLs now.
    if (!content_access_get_settings('per_node', $type) && $form['node']['per_node']['#default_value'] && module_exists('acl')) {
      _content_access_remove_acls($type);
    }
    if (content_access_mass_update(array(
      $type,
    ))) {
      drupal_set_message(t('Permissions have been successfully rebuilt for the content type @types.', array(
        '@types' => node_type_get_name($type),
      )));
    }
  }
  drupal_set_message(t('Your changes have been saved. You may have to !rebuild for your changes to take effect.', array(
    '!rebuild' => l(t('rebuild permissions'), 'admin/reports/status/rebuild'),
  )));
}