c.f. http://drupal.org/node/545700

When registering (user/register) the user is presented with the privacy icons but they do not take into account the default state and do no switch state when clicked (just fade in and out) and has no effect on the values (they are left at the default values)

Comments

hixster’s picture

subscribing

guillaumev’s picture

Hi,

I'm using the dev version as well and, at user registration, I do not see the privacy icons. I see the privacy icons only on a user profile, after the user registered. I have my fields set to "Enabled and hidden by default"...

NaX’s picture

Version: 6.x-1.x-dev » 6.x-1.1
Component: User interface » Code
Category: bug » feature
Status: Active » Needs review

I am using the Content Profile module with user registration and I need CCK Private Fields to work.

The attached patch hacks in support when the Content Profile User Registration module is enabled.

I am using version 6.x-1.1.

Because the user registration form could be built from multiple node types I also changed the _cck_private_fields_node_form_alter() function to support being called multiple times.

The one major problem was that the Content Profile module removes other form fields including CCK Private Fields hidden fields that it needs to work. So I have also implemented a GLOBAL variable that is used to make sure these hidden fields are carried over into the form.

The patch seems to be working form me, but I don’t know if my implementation is the best way to be doing things.

The one thing I would like to be able to do in a better way but could not workout how was the adding of the js_settings.

I hope somebody else finds this useful.

NaX’s picture

Patch did not attach, I don’t know why.

markus_petrux’s picture

Status: Needs review » Postponed (maintainer needs more info)

Re: "The one major problem was that the Content Profile module removes other form fields including CCK Private Fields hidden fields that it needs to work"

hmm... comparing module weights, I'm not sure about that. Could you please confirm?

- content_profile, weight: -1
- content_profile_registration, weight: 1
- cck_private_fields, weight: 10, so it should execute last.

NaX’s picture

@markus_petrux

The module weights don’t play a role, because content_profile_registration retrieves the node forms and then loops through all the fields removing everything that should not be displayed on the user registration form.

The problem I ran into was that I got it to display the privacy icons but content profile was stripping out all the hidden fields preventing any values to be saved when the user registers.

I have not full investigated if there is some sort of method of integrating with the content profile module. I did notice a module_invoke_all('content_profile_settings') but this was after I submitted the patch, and I can’t see how this hook would help solve our problem.

One thing I thought of but have not tried yet is to alter the content profile settings form to include an option for cck_private_fields and then hoping it will recognize it as fields that should not be removed.

I don’t know cck_private_fields well enough to maybe write some code that alters the user_register form after content_profile_registration and does what is needed. Currently cck_private_fields only alters the node forms and on the user_register form content_profile_registration is in control of the node forms.

Heres an extract

function content_profile_registration_add_profile_form($type, &$form, &$form_state) {
  // Initialize new node and add in its form.
  $node = array('uid' => 0, 'name' => '', 'type' => $type);
  // Get the original node form.
  $node_form = drupal_retrieve_form($type .'_node_form', $form_state, $node);
  drupal_prepare_form($type .'_node_form', $node_form, $form_state);

  $node_form += array('#field_info' => array());
  $form_add = array();

  // If non-CCK form elements are hidden, only copy over the CCK stuff
  if (in_array('other', content_profile_get_settings($type, 'registration_hide'))) {
    foreach ($node_form['#field_info'] as $field_name => $info) {
      // ..
    }
  }
}

REF: Line 22 and 106-181
http://drupalcode.org/viewvc/drupal/contributions/modules/content_profil...

NaX’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new20.91 KB

I have completely re-looked this issue and I think I have found a much better way of doing this. The only thing is that this patch requires you don’t tick "Other form elements" under "Hide form fields" on the content profile node settings page if are using the Content Profile registration module.

In this patch I have moved both the wrapper code and the adding of the JS into their own pre_render functions. What led me to this was that on the registration form when validation found an error the private fields were not being rendered at all.

One major change is the introduction of a form delta. So each time a CCK Private Fields form is called and rendered it gets a new form delta. EG: $form['#cck_private_fields_0'] and $form['#cck_private_fields_1'].

This impacted the JS code and the node api code. I was hoping to prevent impacting the JS code because my JS coding is not very strong, but I got it to work with the delta rather easily in the end.

The main problem that led me to use a form delta was that content_profile_registration uses array concatenation to merge the form arrays. I tried it by hacking in an array_merge_recursive() but that just caused more problems.

@markus_petrux
Even if you decided not to support the content_profile_registration module and don’t like the form delta aspect of this patch, I do think the #pre_render method is worth a consideration.