I am getting the following error message:
warning: Invalid argument supplied for foreach() in /sites/all/modules/required_for_pub/required_for_pub.module on line 51.

Comments

pdumais42’s picture

I have the exact same error. Using version 6.x-1.x-dev

/**
 * Implementation of hook_form_alter().
 */
function required_for_pub_form_alter(&$form, &$form_state, $form_id) {
  // If node publishing is enabled, mark the checkbox regardless of the current status.
  if (array_search('status', variable_get('node_options_' . $form['#node']->type, array())) !== FALSE) {
    $fields = $form['#field_info'];
    foreach ($fields as $field) {   // <<<<<<<<<<<<<< line 51 
      // Make sure at least one field is set as required_for_pub
      if ($field['required_for_pub']) {
        $form['options']['status']['#default_value'] = TRUE;
        return;
      }
    }
  }
}
ryan88’s picture

Anyone maintaining this module?

vkareh’s picture

Status: Active » Fixed

Fixed in the new development snapshot.

Status: Fixed » Closed (fixed)

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

thaddeusmt’s picture

So, I thought I had the new Dev version, but at any rate I got this error too. Just wrap it in an IF statement:

<?php 
    if ($fields = $form['#field_info']) { // added the if statement to fix this issue
      foreach ($fields as $field) {
	  // Make sure at least one field is set as required_for_pub
	  if ($field['required_for_pub']) {
	    $form['options']['status']['#default_value'] = TRUE;
	    return;
	  }
      }
    } 
?>

instead of

ian_ep’s picture

Status: Closed (fixed) » Active

I'm still getting this error using the latest dev snapshot from Jul. 11.

vkareh’s picture

Status: Active » Fixed

Thanks for bringing that to my attention. I realized I was trying to check whether there were any fields, but I programmed it to do exactly the inverse. It's now fixed and I made a full release.

Status: Fixed » Closed (fixed)

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

  • Commit 662239e on 6.x-1.x, 7.x-1.x by vkareh:
    #638958: Verify that there are fields in the content type.
    
    
  • Commit 61d7007 on 6.x-1.x, 7.x-1.x by vkareh:
    #638958: Overlooked a coding error in form_alter.