This one took me a while to find and narrow down, but mobile tools interferes with other modules, such as forum access due to $form['account']['roles']['#default_value'] <<

When you are editing a user, you see all the roles.. including "anonymous" when mobile tools is enabled. Apparently that is messing with forum access. See thread here:

http://drupal.org/node/774474#comment-2876962

Comments

salvis’s picture

The idea of this...

  case 'user_profile_form':
    unset($form['account']['roles']['#options']);
    $form['account']['roles']['#options'] = mobile_tools_user_roles();
    break;

... seems to be to remove some roles. If that's what you want to do, then do just that — don't replace $form['account']['roles']['#options'] but unset() the $form['account']['roles']['#options'][$rid]'s that you want to remove.

Otherwise you trample over data that may already have been massaged in some way, for example by the roleassign module.

Is there a reason why you used unset() if you were going to reassign $form['account']['roles']['#options'] anyway?

This doesn't explain why $form['account']['roles']['#default_value'] is trashed, but let's fix the obvious issue first, and maybe the other one will go away. I wonder whether you need to remove the $rids from the #default_values, too, though. FAPI may not like encountering an item in #default_values that doesn't correspond to any of the checkboxes.

@Yappyfox: What's your PHP version? Do you really use an old version of mobile_tools?

twom’s picture

Assigned: Unassigned » twom

Hi,

Thanks for pointing this out. The mobile role system is rather experimental. I'll fix the user roles settings so it does not interfere.

I'll keep you posted.

Twom

Yappyfox’s picture

PHP Ver 5.2.9 (I tried to goto 5.3, but that major trashed a drupal 5 site I had, so I had to roll back.)

Mobile tools was current with the modules web site mobile_tools-6.x-1.12, I had tried -dev, but it still had the same issue, and added some header problem, so currently I just have it disabled.

Yappyfox’s picture

Version: 6.x-1.9 » 6.x-1.12
twom’s picture

Status: Active » Needs review

I submitted a fix to the dev version. However, it is very unlikely that this has caused the error in other modules. This piece of codes just alters a form when editing a profile.

I hope someone can test this out! (wait till the new dev package is build)

salvis’s picture

The change looks good. It's definitely an improvement, but I agree that it's probably not the cause of the original problem.

You may have to add something like

if (($index = array_search($rid, $form['account']['roles']['#default_value']) !== FALSE) {
  unset($form['account']['roles']['#default_value'][$index]);
}

inside the loop to avoid having checkmarks for non-existing checkboxes. I can imagine that this might cause problems.

twom’s picture

Hi,

Thanks for the extra code. However, the purpose of the form alter is to make sure that for a specific user, the 'mobile' roles can not be checked. No user 'has' the mobile user roles. They are being assigned automatically when he visits the mobile site.

So 'normally' the case of checkmarks for not-existing checkboxes should not happen.

What do you think?

Tom

salvis’s picture

Ah, ok, that makes sense.

@Yappyfox: have you tried the -dev version yet?

Yappyfox’s picture

Status: Needs review » Closed (fixed)

Yes! everything plays nice in -DEV I appreciate both of your's help in resolving this issue. No more PHP Errors :>

twom’s picture

Cool. Happy to know things work fine now!

Thanks to salvis for fixing this!

salvis’s picture

You're welcome.

I've seen weird behavior of PHP in this area before — it's always a good idea to tread as lightly as possible when massaging existing arrays.