When I make a custom view of the forums that tries to override the /forum/% I get this error:

Notice: Trying to get property of non-object in forum_menu_local_tasks_alter() (line 170 of /home/quickstart/websites/example.dev/modules/forum/forum.module).

To recreate: drush a d7 site with ctools and views. Create a forum or two. Put a few posts in the forums.

Import the attached view. Go to the forums, drill into a forum. You'll get the error.

I'm a noob so maybe the view is built wrong. It's a node view, with arguments, Taxonomy ID, filtered on the forum vocabulary. The page is set to a url of forum/%.

The failing line is:

    $tid = (isset($router_item['page_arguments'][0]) ? $router_item['page_arguments'][0]->tid : 0);

"page_arguments" is empty on the Views version but is there on the default version.

Is this a views or forums problem? Where do I look next?

CommentFileSizeAuthor
view_export_2.txt10.13 KBDeweyOxberger

Comments

DeweyOxberger’s picture

Tracing into it a bit more shows if the view comes from the normal forum view then $router_item['page_arguments'][0] points to an object. If the view is coming from my custom view it points to an array that contains:

[0] = 'detailed_forum_view';
[1] = 'detail_forum_view';
[2] = '12';

This can't be the answer but I just hacked the code to watch for the two possibilities and handle them both. So forum.module line 168 looks like:

  // Add action link to 'node/add/forum' on 'forum' sub-pages.
  if ($root_path == 'forum' || $root_path == 'forum/%') {
    //$tid = (isset($router_item['page_arguments'][0]) ? $router_item['page_arguments'][0]->tid : 0);
    $tid = 0;  //  !!! <- new lines 
    if (isset($router_item['page_arguments'][0])) {  // !!!
      if (isset($router_item['page_arguments'][0]->tid)) {  // !!!
        // normal request  // !!!
        $tid = $router_item['page_arguments'][0]->tid;  // !!!
      } elseif (isset($router_item['page_arguments'][2])) {  // !!!
        // request coming from a View // !!!
        $tid = $router_item['page_arguments'][2];  // !!!
      }
    }

Seems to work but it smells. Was views supposed to be making that object?

DeweyOxberger’s picture

Side note - it appears this issue is happening in Advanced Forum's D7 version but I've created it here with just Core, ctools, and Views (no AF needed).

mukesh.agarwal17’s picture

I think the view is not created in the right manner.. what is it that you are trying to achieve over here with your view? lets say we have a forum page forum/[tid] that will be handled by the forum module.. now if you need a view to display more info or something like that.. you need to create a separate url structure like 'forum/%/detail' which will use tid as the argument.. does this make sense? you cannot register more than one page of the same structure.. in your case 'forum/%' is already handled by forum module.. you'll need another url structure.. in case you need to show something on the same page of the forum, you dont need to add a page display, you can go ahead with a block and then you need to change the block visibility settings to make it appear on forum/% pages..

Makes sense?

DeweyOxberger’s picture

you cannot register more than one page of the same structure.. in your case 'forum/%' is already handled by forum module..

Are you sure? I thought Views allowed you to override module views. Views comes with a replacement for /taxonomy/term/% as an example so I assumed I could replace /forum/%.

Tracing through the code it seems to work (except the array didn't get the correct values in it). With the hacked code in place it seem to work.

Basically I need /forum/% to display four more columns of taxonomy terms that I've added to a forum. I want to replace the normal forum view with my own.

michelle’s picture

I don't have an answer to your problem but, if you want a work around, you can use Page Manager in CTools with AF to replace the /fourm/% pages with whatever you like.

Michelle

Version: 7.0 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.