When creating a new node, I get this error:

Invalid argument supplied for foreach()
/var/www/drupal/includes/form.inc
Line 1206

which is

    foreach ($form['#default_value'] as $key) {
      $value[$key] = 1;
    }

and is coming from domain.module: Line 1560

...
$form['domain']['domain_site'] = array(
        '#type' => 'checkbox',
        '#prefix' => t('<p><b>Publishing options:</b>'),
        '#suffix' => '</p>',
        '#title' => t('Send to all affiliates'),
        '#required' => FALSE,
        '#description' => t('Select if this content can be shown to all affiliates. This setting will override the options below, but you must still select a domain that "owns" this content.'),
        '#default_value' => (isset($form['#node']->nid)) ? $form['#node']->domain_site : variable_get('domain_node_'. $form['#node']->type, $behavior),
      );

$form['domain']['domains'] = array(
        '#type' => empty($format) ? 'checkboxes' : 'select',
        '#title' => t('Publish to'),
        '#options' => $options,
        '#required' => TRUE,
        '#description' => t('Select which affiliates can access this content.'),
        '#default_value' => (isset($form['#node']->nid)) ? $form['#node']->domains : $default,
      );
...

The problem is that #default_value is NULL because (isset($form['#node']->nid)) should be (isset($form['#node']->nid) && $form['#node']->nid > 0) for both $form['domain']['domain_site']['#default_value'] and $form['domain']['domains']['#default_value']

CommentFileSizeAuthor
#5 721352-isset.patch2.77 KBagentrickard
#2 Picture 1.png47.73 KBagentrickard

Comments

fizk’s picture

In general, I think that the checkbox logic needs to be put into one place and hidden behind a function.

yonas # find domain | xargs grep 'Cannot pass zero in checkboxes'
domain/domain_content/domain_content.module:        // Cannot pass zero in checkboxes, so these are converted from -1.
domain/domain_content/domain_content.module:    // Cannot pass zero in checkboxes.
domain/domain_content/domain_content.admin.inc:      // Cannot pass zero in checkboxes, so these are converted from -1.
domain/domain.module:    // Cannot pass zero in checkboxes.
domain/domain.module:      // Cannot pass zero in checkboxes.

In other words, that should only show up once. I've hit problems with checkboxes a few times already while using other domain modules.

agentrickard’s picture

Status: Active » Postponed (maintainer needs more info)
StatusFileSize
new47.73 KB

Patches welcome. The 'cannot pass zero in checkboxes' is a core limitation that we have to work around, and the new form style (which allows separate formats) hasn't been consolidated. That should be spun off as a separate issue. The problem there is reconciling the form names and a few other minor discrepancies among each usage.

I am curious what modules or settings you have, because I can't replicate the error in #1. When I create a new node, $form['#node']->nid is not set (see attached). Even when set to NULL on preview, I don't get this error.

Looking at the code, it looks like #default_value should in fact be:

isset($form['#node']->domain_site) ? $form['#node']->domain_site : variable_get('domain_node_'. $form['#node']->type, $behavior),

And the same below.

fizk’s picture

I was creating a new Support ticket. The module has been giving me so many problems right out of the box, I just disabled it.

I didn't get this problem before installing Support, and I'm pretty sure it wouldn't have happened when creating other types of nodes.

fizk’s picture

agentrickard’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new2.77 KB

Interesting. I think the approach I describe in #2 is still probably best. Here's a quick patch.

agentrickard’s picture

Status: Needs review » Fixed

Committed!

Status: Fixed » Closed (fixed)

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