Fixed Top-Level category cannot be accessed if not displayed in node list

Kirby

Well-known member
Affected version
2.2.8 PL 1
When adding a category node, it is possible to set this category to not show up in the node list:
1647608412310.png
This doesn't seem to be exactly true:
If the category is a top level category and option Create pages for categories is not enabled (=Default), the category can't be accessed at all as the generated URL is just a link to forums index with an anchor.

So when such a node is used as a navigation menu entry the link is "broken", eg. just goes to forums index without showing the category content.

Could this be changed so the category does get its own page in this case?
 
Last edited:

XF Bug Bot

XenForo bug fixer bot
Staff member
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.9).

Change log:
Always allow top-level categories which are not displayed in the node list to be accessed at their dedicated URL
There may be a delay before changes are rolled out to the XenForo Community.
 

Kirby

Well-known member
Could the patch for this issue be provided?

That would be great as I need to setup a new installation that is affected by this Bug.
 

Jeremy P

XenForo developer
Staff member
Diff:
diff --git a/src/XF/Pub/Route/Category.php b/src/XF/Pub/Route/Category.php
index ab2827b293..feb261295d 100644
--- a/src/XF/Pub/Route/Category.php
+++ b/src/XF/Pub/Route/Category.php
@@ -13,7 +13,7 @@ public static function build(&$prefix, array &$route, &$action, &$data, array &$
 			return null;
 		}
 
-		if ($data && !empty($data['node_id']) && empty($data['depth']) && !\XF::options()->categoryOwnPage)
+		if ($data && !empty($data['node_id']) && empty($data['depth']) && !empty($data['display_in_list']) && !\XF::options()->categoryOwnPage)
 		{
 			$route = (\XF::options()->forumsDefaultPage == 'forums' ? 'forums' : 'forums/list'
 

Kirby

Well-known member
Anwesome :)

Unfortunately this now seems to cause another issue:
The category page is marked as noindex, so \XF\Entity\Category::isSearchEngineIndexable() might need an adjustment as well
 

Kirby

Well-known member
The patch seems to cause an undesired side-effect:

When viewing a thread, the breadcrumb link to a visible top-level category is no longer an anchor to forums index but to the category page that also does not redirect to forums index.

I think this happens because $data is not always a Node entity, it might also be a Category entity in which case empty($data['display_in_list']) is always true (as this field does only exist in the Node entity)

This does not happen with the original code.
 

Jeremy P

XenForo developer
Staff member
Here is a revised patch to normalize the data:

Diff:
diff --git a/src/XF/Pub/Route/Category.php b/src/XF/Pub/Route/Category.php 
index ab2827b293..0eb6df5afc 100644 
--- a/src/XF/Pub/Route/Category.php 
+++ b/src/XF/Pub/Route/Category.php 
@@ -13,7 +13,29 @@ class Category 
             return null; 
         } 
  
-        if ($data && !empty($data['node_id']) && empty($data['depth']) && !\XF::options()->categoryOwnPage) 
+        if ($data instanceof \XF\Entity\Node) 
+        { 
+            $node = $data; 
+        } 
+        else if ($data instanceof \XF\Entity\Category) 
+        { 
+            $node = $data->Node; 
+        } 
+        else if (is_array($data) && !empty($data['node_id'])) 
+        { 
+            $node = $data; 
+        } 
+        else 
+        { 
+            $node = null; 
+        } 
+ 
+        if (!$node) 
+        { 
+            return null; 
+        } 
+ 
+        if (empty($node['depth']) && !empty($node['display_in_list']) && !\XF::options()->categoryOwnPage) 
         { 
             $route = (\XF::options()->forumsDefaultPage == 'forums' ? 'forums' : 'forums/list');

This doesn't quite fix breadcrumbs as that requires pushing the display_in_list value into node breadcrumb data, but it will at least redirect to the right place when the URL is canonicalized. A more comprehensive fix for that is in v2.2.9.
 
Top