It would be nice to move the user privacy settings section to a separate Privacy tab at /user/%uid/edit/privacy so that it can be linked from other pages.

Comments

gilgabar’s picture

This seems like a matter of personal preference. I personally hate putting settings on multiple pages. I find that it makes it much easier for end users to find things if all their settings are in one place. It is possible to link to the user/%uid/edit page too.

That said I don't see why you shouldn't also be able to put it on a separate page. I would suggest an optional submodule that implements the privacy tab and removes it from the edit page via a form_alter. I'd be happy to include it with this module if you want to put it together.

qmhao99’s picture

I'll be happy to if I can figure out how. I am not proficient in Drupal programming yet...

vishun’s picture

<?php

/*
 *  Note: this should probably be re-done using the 
 *  privacypu module settings page to specify how to 
 *  display the privacy settings on the user account
 */

/**
 * Implementation of hook_menu()
 */
function privacypu_profile_menu() {
  $items['user/%/privacy'] = array(
      'page callback' => 'privacypu_profile_page',
      'page arguments' => array(1),
      'access arguments' => array('edit own privacypu settings'),
      'type' => MENU_LOCAL_TASK,
  );    
  return $items;
}

/**
 * Implementation of hook_perm()
 */
function privacypu_profile_perm() {
  return array(
    'edit own privacypu settings',
  );
}

/**
 * Implements hook_form_FORM_ID_alter().
 *
 * Removes the privacy settings form elements to the user account settings form.
 */
function privacypu_profile_form_user_profile_form_alter(&$form, &$form_state) {
  unset($form['privacypu']);
}

/**
 * Privacy Per User account area FAPI implementation
 */
function privacypu_profile_page_form($form_state, $uid) {

  // Set the form item that the submit handler is expecting
  $form['#uid'] = $uid;

  $privacy_types = privacypu_types_load();
  $settings = privacypu_settings_load($form['#uid']);
  $options = privacypu_states_options();

  $form['privacypu'] = array(
    '#type' => 'fieldset',
    '#title' => 'Privacy',
    '#weight' => 10,
    '#collapsible' => TRUE,
  );

  foreach ($privacy_types as $privacy_type) {
    if (!$privacy_type->disabled) {
      $form['privacypu'][$privacy_type->name] = array(
        '#type' => 'select',
        '#title' => $privacy_type->title,
        '#options' => $options,
        '#default_value' => $settings[$privacy_type->name]['state'],
        '#weight' => $privacy_type->weight ? $privacy_type->weight : 0,
      );
    }
  }

  $form['#submit'][] = 'privacypu_user_profile_form_submit';
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Save',
    '#weight' => 11,
  );
  return $form;
}

function privacypu_profile_page($uid) {
  return drupal_get_form('privacypu_profile_page_form', $uid);
}
?>
codesidekick’s picture

In addition to vishuns post above if you'd like the privacy settings to appear in a user edit tab instead of on the profile page change hook menu to

/**
 * Implementation of hook_menu()
 */
function privacypu_profile_menu() {
  $items['user/%/edit/privacy'] = array(
      'page callback' => 'privacypu_profile_page',
      'page arguments' => array(1),
      'access arguments' => array('edit own privacypu settings'),
      'title' => 'Privacy settings',
      'type' => MENU_LOCAL_TASK,
  );    
  return $items;
}

and add this hook to your module to define the tab for the privacy settings as a profile category (which will make sure that the tab appears with other profile edit tabs)

/**
 * Implements hook_user().
 */
function privacypu_profile_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case 'categories':
      $categories = array();
      $categories[] = array(
        'name' => 'privacy',
        'title' => 'User privacy',
        'weight' => 4,
      );

      return $categories;
  }
}
druvision’s picture

The above code is a great idea for a module, but the code needs migration to Drupal 7 and also the D7 version of the privacybu module has another module with the same name so let's rename it or better merge it into the core.

druvision’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

Let's make it a D7 feature request.