Skip to content

Commit 2b50cd4

Browse files
committed
Issues-415: custom breadcrumbs for challenge discussions
1 parent da80ac1 commit 2b50cd4

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

vanilla/applications/vanilla/controllers/class.categoriescontroller.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class CategoriesController extends VanillaController {
3434
const SORT_LAST_POST = 'new';
3535
const SORT_OLDEST_POST = 'old';
3636

37-
const ROOT_CATEGORY = ['Name' => 'Roundtables', 'Url'=>'/'];
3837
/**
3938
* @var \Closure $categoriesCompatibilityCallback A backwards-compatible callback to get `$this->data('Categories')`.
4039
*/
@@ -335,11 +334,7 @@ public function index($categoryIdentifier = '', $page = '0') {
335334
}
336335

337336
// Load the breadcrumbs.
338-
339-
$ancestors = CategoryModel::getAncestors(val('CategoryID', $category));
340-
array_unshift ( $ancestors , self::ROOT_CATEGORY);
341-
$this->setData('Breadcrumbs', $ancestors);
342-
337+
$this->setData('Breadcrumbs', $this->buildBreadcrumbs(val('CategoryID', $category)));
343338

344339
$this->setData('Category', $category, true);
345340
// Set CategoryID
@@ -553,10 +548,7 @@ public function all($Category = '', $displayAs = '') {
553548
$this->description(c('Garden.Description', null));
554549
}
555550

556-
$ancestors = CategoryModel::getAncestors(val('CategoryID', $this->data('Category')));
557-
array_unshift ( $ancestors , self::ROOT_CATEGORY);
558-
$this->setData('Breadcrumbs', $ancestors);
559-
551+
$this->setData('Breadcrumbs', $this->buildBreadcrumbs(val('CategoryID', $this->data('Category'))));
560552

561553
// Set the category follow toggle before we load category data so that it affects the category query appropriately.
562554
$CategoryFollowToggleModule = new CategoryFollowToggleModule($this);

vanilla/applications/vanilla/controllers/class.discussioncontroller.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ public function index($DiscussionID = '', $DiscussionStub = '', $Page = '') {
125125
Gdn_Theme::section($CategoryCssClass);
126126
}
127127

128-
$ancestors = CategoryModel::getAncestors($this->CategoryID);
129-
array_unshift ( $ancestors , CategoriesController::ROOT_CATEGORY);
130-
$this->setData('Breadcrumbs', $ancestors);
128+
$this->setData('Breadcrumbs', $this->buildBreadcrumbs($this->CategoryID));
131129

132130
// Setup
133131
$this->title($this->Discussion->Name);

vanilla/applications/vanilla/controllers/class.postcontroller.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ public function discussion($categoryUrlCode = '') {
409409
$this->fireEvent('BeforeDiscussionRender');
410410

411411
if ($this->CategoryID) {
412-
$breadcrumbs = CategoryModel::getAncestors($this->CategoryID);
412+
$breadcrumbs = $this->buildBreadcrumbs($this->CategoryID);
413413
} else {
414414
$breadcrumbs = [];
415415
}
@@ -419,7 +419,6 @@ public function discussion($categoryUrlCode = '') {
419419
'Url' => val('AddUrl', val($this->data('Type'), DiscussionModel::discussionTypes()), '/post/discussion')
420420
];
421421

422-
array_unshift ( $breadcrumbs , CategoriesController::ROOT_CATEGORY);
423422
$this->setData('Breadcrumbs', $breadcrumbs);
424423

425424
// FIX: Hide Announce options

vanilla/applications/vanilla/controllers/class.vanillacontroller.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
*/
1414
class VanillaController extends Gdn_Controller {
1515

16+
const ROOT_CATEGORY = ['Name' => 'Roundtables', 'Url'=>'/'];
17+
1618
/**
1719
* Include JS, CSS, and modules used by all methods.
1820
*
@@ -70,6 +72,29 @@ protected function checkPageRange(int $offset, int $totalCount) {
7072
}
7173
}
7274

75+
protected function buildBreadcrumbs($CategoryID) {
76+
$Category = CategoryModel::categories($CategoryID);
77+
$ancestors = CategoryModel::getAncestors($CategoryID);
78+
if(val('GroupID', $Category) > 0) {
79+
$temp = [];
80+
foreach ($ancestors as $id => $ancestor) {
81+
if($ancestor['GroupID'] > 0) {
82+
$temp[$ancestor['CategoryID']] = $ancestor;
83+
} else {
84+
if($ancestor['UrlCode'] == 'challenges-forums') {
85+
array_push($temp, ['Name' => 'Challenge Discussions', 'Url'=>'/groups/mine?filter=challenge']);
86+
}else if($ancestor['UrlCode'] == 'groups') {
87+
array_push($temp, ['Name' => 'Group Discussions', 'Url'=>'/groups/mine?filter=regular']);
88+
}
89+
}
90+
}
91+
return $temp;
92+
} else {
93+
array_unshift($ancestors, self::ROOT_CATEGORY);
94+
return $ancestors;
95+
}
96+
}
97+
7398
protected function log($message, $context = [], $level = Logger::DEBUG) {
7499
// if(c('Debug')) {
75100
Logger::log($level, sprintf('%s : %s',get_class($this), $message), $context);

0 commit comments

Comments
 (0)