Hi,
I got this error on all my pages after I enabled panels to override some of my pages
Notice: Undefined index: nodes in sharebar_preprocess_region() (line 120 of /www/v/y/u35981/public_html/_sub/test/sites/all/modules/sharebar/sharebar.module).
Notice: Trying to get property of non-object in sharebar_preprocess_region() (line 120 of /www/v/y/u35981/public_html/_sub/test/sites/all/modules/sharebar/sharebar.module).

Comments

noslokire’s picture

Same here.

nmudgal’s picture

Status: Active » Postponed (maintainer needs more info)

Nope, I didn't get any such issue.
I downloaded both modules sharebar[7.x-1.x-dev] & panels[7.x-3.2] in fresh drupal 7 installation & tried creating mini panel, & panel node, but couldn't regenerate issue.
It would be nice if you can tell more information in terms of versions used, what exactly did you do? etc which can help me to reproduce it.

Thanks

noslokire’s picture

I'm not sure about the first person, but I am not creating a Panel node using the Panels module. I am using Panels to override the node template for a particular content type.

I am on the latest stable Panels/CTools versions like you are testing above.

ganagus’s picture

Status: Postponed (maintainer needs more info) » Active
StatusFileSize
new98.77 KB

Yes, I confirmed this issue too. I have the same configuration with @noslokire, using Panels to override node template. The error is the same: Notice: Undefined index: nodes in sharebar_preprocess_region() (line 120 of ...

Look at the attachment, there is no 'nodes' index in $variables['elements']['system_main'] when using Panels to override node template.

ganagus’s picture

I think the error comes from the code to obtain $node->type. The code assumes the node type can always be obtained from the $variables['elements']['system_main']['nodes'], but when using Panels to override node template, the variable is not available.

How about check it first, if available, we can take it from $variables. Otherwise, I think we can use node_load() function to get node type. Using node_load() does incur additional overhead, but it's the most intuitive source to obtain node type.

This is just my code suggestion, I'd be glad if we can discuss it here:

/**
 * Get type of a node, called from sharebar_preprocess_region()
 */
function _sharebar_get_node_type($variables) {
  $node_type = '';
  if ((arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '')) {
    if (array_key_exists('nodes', $variables['elements']['system_main'])) {
      $node_type = $variables['elements']['system_main']['nodes'][arg(1)]['#node']->type;
    } else {
      $node = node_load(arg(1));
      $node_type = $node->type;
    }
  }
  return $node_type;
}

/**
 * Preprocess variables for region.tpl.php
 */
function sharebar_preprocess_region(&$variables) {
  if ($variables['region'] == 'content') {
    if (arg(0) != 'admin') {            
      if ((arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '' && 
        variable_get('sharebar_bar_posts_' . _sharebar_get_node_type($variables) . '_enabled', TRUE)) 
        || (!(arg(0) == 'node' and is_numeric(arg(1))) and arg(1) != 'add' && arg(2) != 'edit' && arg(3) != 'edit' 
        && variable_get('sharebar_bar_pages_enabled', TRUE))) {
        // ...
nmudgal’s picture

ganagus,
Thanks, would you like to throw a patch for it?

acrollet’s picture

Title: error - using with panels » node type visibility settings not respected with panels
Status: Active » Needs review
StatusFileSize
new6.9 KB

I can confirm the bug, and that the code in #5 fixes the issue. I went ahead and rolled a patch, attaching here.

Status: Needs review » Needs work

The last submitted patch, sharebar-panels_compatibility-1617110-7.patch, failed testing.

nmudgal’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, sharebar-panels_compatibility-1617110-7.patch, failed testing.

flashwebcenter’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: +panels, +sharebar
StatusFileSize
new1.76 KB

Yes, I confirmed this issue too. I am using Panels to override node template. The error is the same: Notice: Undefined index: nodes in sharebar_preprocess_region() (line 120 of ..

Here is another version of the patch, I applied this patch and I tested several times. I don't see the error anymore.

Status: Needs review » Needs work

The last submitted patch, 11: sharebar-panels_compatibility-1617110-8.patch.patch, failed testing.

The last submitted patch, 11: sharebar-panels_compatibility-1617110-8.patch.patch, failed testing.

  • nmudgal committed 00b350c on 7.x-2.x authored by acrollet
    Issue #1617110 by loparr: Making a check for  when using Panels to...
  • nmudgal committed 5a1026e on 7.x-2.x
    Revert "Issue #1617110 by loparr: Making a check for  when using Panels...

  • nmudgal committed 926d2e2 on 7.x-1.x
    Issue #1617110 by loparr, ganagus, acrollet, flashwebcenter: node type...
nmudgal’s picture

Status: Needs work » Fixed

Applied patch with some changes. Let's hope it doesn't break unknowns. Thanks much guys (:

nmudgal’s picture

Category: Support request » Bug report

  • nmudgal committed 00b350c on 8.x-1.x authored by acrollet
    Issue #1617110 by loparr: Making a check for  when using Panels to...
  • nmudgal committed 5a1026e on 8.x-1.x
    Revert "Issue #1617110 by loparr: Making a check for  when using Panels...

Status: Fixed » Closed (fixed)

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