On my site I was trying to debug some errors I was getting and noticed the webform block was throwing some errors too. I'm not really a php coder though so, not sure what to do. These are the messages I am getting.

Notice: Undefined offset: 2 in /var/www/vhosts/mysite.com/httpdocs/sites/all/modules/webformblock/webformblock.module on line 15

and

Notice: Trying to get property of non-object in /var/www/vhosts/mysite.com/httpdocs/sites/all/modules/webformblock/webformblock.module on line 27

Are any of these big deals? I can't figure out what it means by undefined offset.

Becky

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lmeister’s picture

They are not really errors but a php notice usually suggests the code could be improved. I also got annoyed with these notices appearing in my logs so slightly changed the code.

Here is the altered function for 6.x-1.1 if you compare to the original you will see the slight differences. Nothing major just checking array keys actually exist before trying to use them. Hope that helps.

function webformblock_form_alter(&$form, $form_state, $form_id) {

  if ($form_id == 'webform_node_form') {
  
    $form['webform']['advanced']['addblock'] = array(
      '#type' => 'checkbox',
      '#return_value' => 1,
      '#default_value' => webformblock_nodestatus($form['nid']['#value']),
      '#title' => t('Generate a block'),
      '#description' => t('Allow this form to appear in its own block which can be positioned in any block region.'),
      '#weight' => -20,
    );
  } elseif (isset($form['#parameters'][2]) && $form['#parameters'][2]->webform['addblock'] == 1) {
    $node = $form['#parameters'][2];
    form_clean_id(null, true);
    $anchorname = form_clean_id(str_replace('/', '', strtolower( drupal_get_path_alias('node/' . $node->nid) ))); 
    $form['#action'] = url(drupal_get_path_alias($_GET['q']), array('fragment' => $anchorname)); 
  }
}
mikeytown2’s picture

FileSize
2.94 KB

also has a small whitespace fix

mikeytown2’s picture

Version: 6.x-1.1 » 6.x-1.x-dev
Status: Active » Needs review
noslokire’s picture

Looks good to me

azovsky’s picture

Version: 6.x-1.x-dev » 6.x-1.2

My solution of the problem for Webform Block 6.x-1.2:

azovsky’s picture

Sorry, the file was lost. Here it is:

Michelle’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

This worked for me to get rid of the errors.

fuzzy76’s picture

Rerolled against latest stable for makefile usage.

fuzzy76’s picture

FileSize
1.44 KB

That patch had 2 whitespace errors and still produced PHP warnings. Here's a new one (still rolled against 6.x-1.2 stable - does not apply to head).