@@ -29,11 +29,12 @@ class CategoriesController extends VanillaController {
2929 public $ Category ;
3030
3131 /** @var bool Value indicating if the category-following filter should be displayed when rendering a view */
32- public $ enableFollowingFilter = true ; // false;
32+ public $ enableFollowingFilter = false ;
3333
3434 const SORT_LAST_POST = 'new ' ;
3535 const SORT_OLDEST_POST = 'old ' ;
3636
37+ const ROOT_CATEGORY = ['Name ' => 'Roundtables ' , 'Url ' =>'/ ' ];
3738 /**
3839 * @var \Closure $categoriesCompatibilityCallback A backwards-compatible callback to get `$this->data('Categories')`.
3940 */
@@ -264,15 +265,23 @@ private function getOptions($category) {
264265 public function index ($ categoryIdentifier = '' , $ page = '0 ' ) {
265266 // Figure out which category layout to choose (Defined on "Homepage" settings page).
266267 $ layout = c ('Vanilla.Categories.Layout ' );
267- $ followed = Gdn::request ()->get ('followed ' , null );
268- $ saveFollowing = $ followed !== null && Gdn::request ()->get ('save ' ) && Gdn::session ()->validateTransientKey (Gdn::request ()->get ('TransientKey ' , '' ));
269- if ($ saveFollowing ) {
270- $ followed = Gdn::request ()->get ('followed ' );
271- Gdn::session ()->setPreference ('FollowedCategories ' , $ followed );
268+
269+ if ($ this ->CategoryModel ->followingEnabled ()) {
270+ $ followed = Gdn::request ()->get ('followed ' , null );
271+ $ saveFollowing = $ followed !== null && Gdn::request ()->get ('save ' ) && Gdn::session ()->validateTransientKey (Gdn::request ()->get ('TransientKey ' , '' ));
272+ if ($ saveFollowing ) {
273+ $ followed = Gdn::request ()->get ('followed ' );
274+ Gdn::session ()->setPreference ('FollowedCategories ' , $ followed );
275+ }
276+
277+ $ followed = Gdn::session ()->getPreference ('FollowedCategories ' , false );
278+ $ this ->enableFollowingFilter = true ;
279+ } else {
280+ $ this ->enableFollowingFilter = $ followed = false ;
272281 }
273282
274- $ followed = Gdn::session ()->getPreference ('FollowedCategories ' , false );
275283 $ this ->setData ('Followed ' , $ followed );
284+ $ this ->setData ('EnableFollowingFilter ' , $ this ->enableFollowingFilter );
276285
277286 $ sort = Gdn::request ()->get ('sort ' , null );
278287 $ saveSorting = $ sort !== null && Gdn::request ()->get ('save ' ) && Gdn::session ()->validateTransientKey (Gdn::request ()->get ('TransientKey ' , '' ));
@@ -283,13 +292,11 @@ public function index($categoryIdentifier = '', $page = '0') {
283292 $ this ->setData ('CategorySort ' , $ sort );
284293
285294 if ($ categoryIdentifier == '' ) {
286- $ this ->enableFollowingFilter = true ;
287295 $ this ->fireEvent ('EnableFollowingFilter ' , [
288296 'CategoryIdentifier ' => $ categoryIdentifier ,
289297 'EnableFollowingFilter ' => &$ this ->enableFollowingFilter
290298 ]);
291- $ this ->setData ('EnableFollowingFilter ' , $ this ->enableFollowingFilter );
292- switch ($ layout ) {
299+ switch ($ layout ) {
293300 case 'mixed ' :
294301 $ this ->View = 'discussions ' ;
295302 $ this ->discussions ();
@@ -316,17 +323,26 @@ public function index($categoryIdentifier = '', $page = '0') {
316323
317324 Gdn_Theme::section ($ category ->CssClass );
318325
319- // The view filter is shown always if category type != 'discussions'
320- $ this ->enableFollowingFilter = strtolower ( val ('DisplayAs ' , $ category , '' )) != 'discussions ' ;
321- $ this ->fireEvent ('EnableFollowingFilter ' , [
322- 'CategoryIdentifier ' => $ categoryIdentifier ,
323- 'EnableFollowingFilter ' => &$ this ->enableFollowingFilter
324- ]);
326+ if ($ this ->CategoryModel ->followingEnabled ()) {
327+ // The view filter is shown always if category type != 'discussions'
328+ $ this ->enableFollowingFilter = strtolower (val ('DisplayAs ' , $ category , '' )) != 'discussions ' ;
329+ $ this ->fireEvent ('EnableFollowingFilter ' , [
330+ 'CategoryIdentifier ' => $ categoryIdentifier ,
331+ 'EnableFollowingFilter ' => &$ this ->enableFollowingFilter
332+ ]);
333+ }
325334
326335 // Load the breadcrumbs.
327- $ this ->setData ('Breadcrumbs ' , CategoryModel::getAncestors (val ('CategoryID ' , $ category )));
336+
337+ $ ancestors = CategoryModel::getAncestors (val ('CategoryID ' , $ category ));
338+ array_unshift ( $ ancestors , self ::ROOT_CATEGORY );
339+ $ this ->setData ('Breadcrumbs ' , $ ancestors );
340+
328341
329342 $ this ->setData ('Category ' , $ category , true );
343+ // Set CategoryID
344+ $ categoryID = val ('CategoryID ' , $ category );
345+ $ this ->setData ('CategoryID ' , $ categoryID , true );
330346 $ this ->setData ('EnableFollowingFilter ' , $ this ->enableFollowingFilter );
331347
332348 $ this ->title (htmlspecialchars (val ('Name ' , $ category , '' )));
@@ -392,14 +408,10 @@ public function index($categoryIdentifier = '', $page = '0') {
392408 $ this ->Head ->addRss (categoryUrl ($ category ) . '/feed.rss ' , $ this ->Head ->title ());
393409 }
394410
395- // Set CategoryID
396- $ categoryID = val ('CategoryID ' , $ category );
397- $ this ->setData ('CategoryID ' , $ categoryID , true );
398-
399411 // Add modules
400412 $ this ->addModule ('NewDiscussionModule ' );
401413 $ this ->addModule ('DiscussionFilterModule ' );
402- $ this ->addModule ('CategoriesModule ' );
414+ // $this->addModule('CategoriesModule');
403415 $ this ->addModule ('BookmarkedModule ' );
404416 $ this ->addModule ('TagModule ' );
405417
@@ -528,7 +540,7 @@ public function all($Category = '', $displayAs = '') {
528540 if ($ Title ) {
529541 $ this ->title ($ Title , '' );
530542 } else {
531- $ this ->title (t ('All Categories ' ));
543+ $ this ->title (t ('Roundtables ' ));
532544 }
533545 }
534546 Gdn_Theme::section ('CategoryList ' );
@@ -537,7 +549,10 @@ public function all($Category = '', $displayAs = '') {
537549 $ this ->description (c ('Garden.Description ' , null ));
538550 }
539551
540- $ this ->setData ('Breadcrumbs ' , CategoryModel::getAncestors (val ('CategoryID ' , $ this ->data ('Category ' ))));
552+ $ ancestors = CategoryModel::getAncestors (val ('CategoryID ' , $ this ->data ('Category ' )));
553+ array_unshift ( $ ancestors , self ::ROOT_CATEGORY );
554+ $ this ->setData ('Breadcrumbs ' , $ ancestors );
555+
541556
542557 // Set the category follow toggle before we load category data so that it affects the category query appropriately.
543558 $ CategoryFollowToggleModule = new CategoryFollowToggleModule ($ this );
@@ -623,9 +638,12 @@ public function all($Category = '', $displayAs = '') {
623638 $ this ->setData ('CategoryTree ' , $ categoryTree );
624639
625640 // Add modules
626- $ this ->addModule ('NewDiscussionModule ' );
641+ if ($ Category ) {
642+ $ this ->addModule ('NewDiscussionModule ' );
643+ }
627644 $ this ->addModule ('DiscussionFilterModule ' );
628645 $ this ->addModule ('BookmarkedModule ' );
646+ // $this->addModule('CategoriesModule');
629647 $ this ->addModule ($ CategoryFollowToggleModule );
630648 $ this ->addModule ('TagModule ' );
631649
@@ -661,7 +679,7 @@ public function discussions($Category = '') {
661679 if ($ Title ) {
662680 $ this ->title ($ Title , '' );
663681 } else {
664- $ this ->title (t ('All Categories ' ));
682+ $ this ->title (t ('Roundtables ' ));
665683 }
666684 }
667685
@@ -717,7 +735,7 @@ public function discussions($Category = '') {
717735 // Add modules
718736 $ this ->addModule ('NewDiscussionModule ' );
719737 $ this ->addModule ('DiscussionFilterModule ' );
720- $ this ->addModule ('CategoriesModule ' );
738+ // $this->addModule('CategoriesModule');
721739 $ this ->addModule ('BookmarkedModule ' );
722740 $ this ->addModule ($ CategoryFollowToggleModule );
723741
0 commit comments