If this form element is empty, i think it will be removed, not display on user profile form.

Comments

areynolds’s picture

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

This form element should be removed if it's empty (it uses the user_relationships_ui_account_fieldset_remove_if_empty function shown below). However, running version 7.x-1.x-dev on D7.4, I'm still seeing the element. Checking it out.

Line 481

// Always create the fieldset in case other modules want to add
    // related settings through hook_form_alter(). If it's still empty after the
    // build process, the after build function will remove it.
    $form['user_relationships_ui_settings'] += array(
      '#type'   => 'fieldset',
      '#title'  => t('Relationships'),
      '#weight' => 5,
      '#collapsible' => TRUE,
      '#after_build' => array('user_relationships_ui_account_fieldset_remove_if_empty'),
    );

Line 529

function user_relationships_ui_account_fieldset_remove_if_empty($element) {
  if (count(element_children($element)) == 0) {
    $element['#access'] = FALSE;
  }
  return $element;
}
areynolds’s picture

Assigned: Unassigned » areynolds
Status: Active » Needs review
StatusFileSize
new0 bytes

Ok, the issue is that the $form['user_relationships_ui_settings'] element counts as a child element; therefore the count is 1 and not equal to zero. The function user_relationships_ui_account_fieldset_remove_if_empty needs to be changed to something like this:

function user_relationships_ui_account_fieldset_remove_if_empty($element) {
  if (count(element_children($element)) < 2) {
    $element['#access'] = FALSE;
  }
  return $element;
}

Seems to work; patch is attached.

berdir’s picture

Status: Needs review » Needs work

Patch is empty, can you re-roll?

areynolds’s picture

Sorry about that, must have been a late-night patch. This should do it.

areynolds’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, remove-ui-settings-form-if-empty-587646-4.patch, failed testing.

berdir’s picture

The patch removes the old patch, which doesn't exist, that's the reason why it fails.

areynolds’s picture

Third time's the charm!

areynolds’s picture

Status: Needs work » Needs review
berdir’s picture

Assigned: areynolds » berdir
Status: Needs review » Needs work

The fix is not correct, it hides the mailer setting, because that is controlled through #access.

I have a working version with tests but won't be able to upload it before the weekend.

berdir’s picture

Category: task » bug

Weird double post

berdir’s picture

Title: Remove $form['user_relationships_ui_settings']) if it's empty » Fix various user settings bugs and add tests
Status: Needs work » Needs review
StatusFileSize
new15.11 KB

Ok, attaching a new patch.

- The patch goes trough all child elements and checks their #access. It also comes with extensive tests for all the settings and also contains the patch from #1275138: User settings for email notifications are not saved and tests for that.

berdir’s picture

Status: Needs review » Fixed

Commited and pushed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.