domain_form_alter generates an error in our setup for anonymous users that want to add an entry to the guest book.

I could solve the problem by placing a

if (! user_is_anonymous())

around the foreach in line 1057 (file: domain.module). I have no idea if this is a good solution, but from what i see it works fine with the rest of the function.

Comments

agentrickard’s picture

Status: Active » Postponed (maintainer needs more info)

Can you please describe the actual error? We don't want to introduce exception-handling code if we do not have to, and there are cases where anonymous users can create content.

It is possible that this is an error with the another module as well, but you need to specify which module is being used, what path the error occurs on, and so forth.

mischan’s picture

sorry for not being specific...

i was getting an (red-box) error-message when adding an entry to the
guestbook, that basically says that the $user->domain_user field was
empty and thus not iterable (in the foreach loop at line 1057). So that _is_ the actual error and users can see it, which is my main concern.

As far as i can tell, this will always be the case, because there is
no domainuser property for the anonymous user (at least not in the
database table). It also makes sense to me, but probably the anonymous
user gets assigned a default value for the domainuser (to the default
domain) at some point, but this is where my knowledge about the domain
module ends. We do not get the error on our primary (default) domain, but it happens on all other domains.

The path is /node/add/guestbook

guestbook is a simple form, generated with the standard drupal content type tools.

mischan’s picture

probably should say: i get the error when entering the the guestbook form, i didn't enter text and submitted it.

agentrickard’s picture

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

I think this might be a configuration error. That loop only runs for users with the 'view domain publishing' permission. Do your anonymous users have that permission?

They shouldn't because it doesn't make any sense for them to.

Look at the function, the loop comes here, starting on line 1051:

    // If the user has limited permissions, show that form or obey the settings.
    else {
      if (user_access('view domain publishing')) {
        $action = variable_get('domain_options', 0);
        $user_domains = array();
        $default_options = array();
        foreach ($user->domain_user as $key => $value) {
          if (abs($value) > 0) {
            $user_domains[] = $value;
          }
        }
    

'View domain publishing' is a permission to let content editors see _some_ of the domain assignment options. Since anonymous users cannot be assigned to domains, they should never have this permission. So the foreach loop that you cite should never be triggered.

We should probably just wrap that in an !empty:

    else {
      if (user_access('view domain publishing') && !empty($user->domain_user)) {
        $action = variable_get('domain_options', 0);
        $user_domains = array();
        $default_options = array();
        foreach ($user->domain_user as $key => $value) {
          if (abs($value) > 0) {
            $user_domains[] = $value;
          }
        }

What happens if you try that?

agentrickard’s picture

agentrickard’s picture

Status: Needs review » Closed (duplicate)

ksenzee has a patch #313629: anonymous users can't request a domain for their content that should fix this problem. Moving to duplicate. Please test the other patch.

mischan’s picture

thanks for all your support. will try the patch asap.