By chance found this setting when working with custom fields.

This setting gets added to all fields, regardless of bundle.

Comments

alexweber’s picture

This appears to be done intentionally in profile2.module, lines 800-806.

function profile2_form_field_ui_field_edit_form_alter(&$form, &$form_state) {
  if ($form['instance']['entity_type']['#value'] == 'profile2') {
    $form['field']['settings']['profile2_private'] = array(
      '#type' => 'checkbox',
      '#title' => t('Make the content of this field private.'),
      '#default_value' => !empty($form['#field']['settings']['profile2_private']),
      '#description' => t('If checked, the content of this field is only shown to the profile owner and administrators.'),
    );
  }
  else {
    // Add the value to the form so it isn't lost.
    $form['field']['settings']['profile2_private'] = array(
      '#type' => 'value',
      '#value' => !empty($form['#field']['settings']['profile2_private']),
    );
  }
}
alexweber’s picture

For the record, the same happens with "user_register_form".

Is there a good reason why this approach was taken?

chrisschaub’s picture

Priority: Normal » Major

And they don't get deleted when profile2 is uninstalled. And that causes some nasty bugs related to missing entity class controller errors. Can you recommend a safe way to remove this from my blob data?

joachim’s picture

> Is there a good reason why this approach was taken?

I can't think of a good reason why we'd need to save this value on fields that aren't even on profile entities. AFAIK profile2 doesn't do anything with those fields at all.

alexweber’s picture

@joachim I figured... patch time then :)

joachim’s picture

Oh wait I get it.

$form['field']['settings']['profile2_private']

The setting is on the field.
If the field has one instance on a profile, and one instance on a node type, and you edit and save the node instance, this ensures the value is saved.

I'm not sure how best to handle this. We could check the field to see if it has any instances on profiles, and if so, set a form value. But that still leaves the problem of data being left in the blob when the module is removed.

I think this is this is the best short term fix; longer term the profile2_private property should maybe live on the instance rather than the field?

joachim’s picture

> We could check the field to see if it has any instances on profiles, and if so, set a form value

Even simpler, check if the field has a profile2_private property, and if so, set the form value to preserve it.

But that won't help everyone whose field data is already contaminated...

alexweber’s picture

> But that won't help everyone whose field data is already contaminated...

Nope, but at least we can stop further contamination... :)

Taxoman’s picture

Plus add a comment in the code as per #6?

Bagz’s picture

Issue summary: View changes

For those looking for a way to clean up the field configuration left behind after a profile2 uninstall:

  $result = db_query('SELECT id, data FROM field_config');
  foreach($result as $record) {
    $data = unserialize($record->data);
    if (isset($data['settings']['profile2_private'])) {
      unset($data['settings']['profile2_private']);
      db_update('field_config')
        ->fields(array('data' => serialize($data)))
        ->condition('id', $record->id)
        ->execute();
    }
  }