My log had several entries like this:

Invalid argument supplied for foreach() in /home/seasider/public_html/sites/all/modules/station/schedule/station_schedule.module on line 285.

These appear to be caused by a non-admin user editing a program.
He has the right to, because I set him as author of the node.
However, the node has no DJs set yet, because I've not got all the presenters set up with user accounts.

The problem is in the hook_nodeapi implementation:

        // validate the users
        foreach ($node->djs as $key => $dj) {
          if ($dj['username']) {
            $user = user_load(array('name' => $dj['username']));
            if (!$user->uid) {
              form_set_error("djs][$key][username", t('You need to specify a valid user name.'));
            }
            if (!isset($user->roles[$dj_role])) {
              form_set_error("djs][$key][username", t('%username is not a member of the %rolename role.',
                  array('%username' => $user->name, '%rolename' => $roles[$dj_role])));
            }
          }
        }

Looks like we need a test for $node->djs at the top of that case.

Comments

drewish’s picture

what about just casting to an array?

 foreach ((array) $node->djs as $key => $dj) {

would that do the trick?

joachim’s picture

Yup, that works.

drewish’s picture

Status: Active » Fixed

cool, committed that to DRUPAL-5.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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