Hey guys!!

I am working on a matrimonial website build using CCK/Views/Content Profile Module for basic functionality and other modules for various features.

Now my client wants that when a user is creating his/her profile he/she should be able to tick a checkbox for displaying the picture. Images should be hidden by default.

Is there any module for doing this, I found one module "Conditional Fields" would that work for achieving this?

Thanks in advance!

-Ravi

Comments

mdupont’s picture

You could write a custom module and leverage hook_user and the Forms API to customize the display.

Example (not tested, just for the structure):

/**
 * Implementation of hook_user().
 */

function custom_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case form:  // user edit form
      // adding a checkbox
      $form['switch_picture'] = array(
        '#type' => 'checkbox',
        '#title' => t('Display picture?'),
      );
      return $form;
      break;
    case view:  // user profile page
      // if unchecked, hide the picture
      if (!$account->content['switch_picture']) {
        unset($account->content['picture']);
      }
      break;
  }
}
ravisagar’s picture

I have pretty good knowledge of Drupal configuration but not php scripting. I guess this code will hide the picture for all roles. What if the User itself is viewing his/her content profile and Admin is viewing any user's profile? Would they be able to see the pictures. The image has to be hidden from non-admin uers only.

One more thing, I am using content profile and the images are basically imagefields. So in the above code I would replace the line

unset($account->content['picture']);

with

unset($account->content['field_picture']);

where "field_picture" is CCK's imagefield. I hope I am correct?