From db059e8918fbc50f3e6b151d1d8332b3897d7ee7 Mon Sep 17 00:00:00 2001 From: Bogdanova Olga Date: Wed, 12 Jan 2022 13:41:59 +0300 Subject: [PATCH] Issues-652: tweaks for a group page when it's embedded --- .../controllers/class.vanillacontroller.php | 107 ++++++++++-------- vanilla/js/embed.js | 6 +- 2 files changed, 62 insertions(+), 51 deletions(-) diff --git a/vanilla/applications/vanilla/controllers/class.vanillacontroller.php b/vanilla/applications/vanilla/controllers/class.vanillacontroller.php index 1ffa42a..e700636 100644 --- a/vanilla/applications/vanilla/controllers/class.vanillacontroller.php +++ b/vanilla/applications/vanilla/controllers/class.vanillacontroller.php @@ -102,72 +102,79 @@ protected function buildBreadcrumbs($CategoryID) { $this->fireEvent('BeforeBuildBreadcrumbs'); // getIncomingValue('embed_type') == 'mfe' if(!$showFullBreadcrumbs) { + $temp = []; if(val('GroupID', $Category) > 0) { - $temp = []; + $GroupCategoryID = $this->data('Breadcrumbs.Options.GroupCategoryID'); foreach ($ancestors as $id => $ancestor) { - if ($ancestor['GroupID'] > 0) { - $temp[$ancestor['CategoryID']] = $ancestor; + if($GroupCategoryID == $ancestor['CategoryID']) {// root category for a group + array_push($temp, ['Name' => $ancestor['Name'], 'Url'=>'/group/'.$ancestor['GroupID']]); + } else if($ancestor['GroupID'] > 0){ + $temp[$ancestor['CategoryID']] = $ancestor; } } - return $temp; } - } + if(count($temp) == 1) { + return []; + } + return $temp; + } else { - if(val('GroupID', $Category) > 0) { - $challenge = $this->data('Challenge'); - $track = $challenge ? $challenge['Track']: false; - $temp = []; - $GroupCategoryID = $this->data('Breadcrumbs.Options.GroupCategoryID'); - foreach ($ancestors as $id => $ancestor) { - if($ancestor['GroupID'] > 0) { - if($GroupCategoryID == $ancestor['CategoryID']) {// root category for a group - array_push($temp, ['Name' => $ancestor['Name'], 'Url'=>'/group/'.$ancestor['GroupID']]); - } else { - $temp[$ancestor['CategoryID']] = $ancestor; - } - } else { - if($ancestor['UrlCode'] == self::CHALLENGE_FORUMS_URLCODE) { - array_push($temp, ['Name' => 'Challenge Forums', 'Url'=>'/groups/mine?filter=challenge']); - }else if($ancestor['UrlCode'] == 'groups') { - array_push($temp, ['Name' => 'Group Forums', 'Url'=>'/groups/mine?filter=regular']); + if (val('GroupID', $Category) > 0) { + $challenge = $this->data('Challenge'); + $track = $challenge ? $challenge['Track'] : false; + $temp = []; + $GroupCategoryID = $this->data('Breadcrumbs.Options.GroupCategoryID'); + foreach ($ancestors as $id => $ancestor) { + if ($ancestor['GroupID'] > 0) { + if ($GroupCategoryID == $ancestor['CategoryID']) {// root category for a group + array_push($temp, ['Name' => $ancestor['Name'], 'Url' => '/group/' . $ancestor['GroupID']]); + } else { + $temp[$ancestor['CategoryID']] = $ancestor; + } } else { - if($track) { - switch ($ancestor['UrlCode']) { - case 'development-forums': - case 'data-science-forums': - case 'design-forums': - array_push($temp, ['Name' => $track, 'Url'=>'/groups/mine?filter=challenge']); - break; - default: - $temp[$ancestor['CategoryID']] = $ancestor; + if ($ancestor['UrlCode'] == self::CHALLENGE_FORUMS_URLCODE) { + array_push($temp, ['Name' => 'Challenge Forums', 'Url' => '/groups/mine?filter=challenge']); + } else if ($ancestor['UrlCode'] == 'groups') { + array_push($temp, ['Name' => 'Group Forums', 'Url' => '/groups/mine?filter=regular']); + } else { + if ($track) { + switch ($ancestor['UrlCode']) { + case 'development-forums': + case 'data-science-forums': + case 'design-forums': + array_push($temp, ['Name' => $track, 'Url' => '/groups/mine?filter=challenge']); + break; + default: + $temp[$ancestor['CategoryID']] = $ancestor; + } } } } } - } - return $temp; - } else { - $urlCode = val('UrlCode', $Category); - if($urlCode == self::CHALLENGE_FORUMS_URLCODE) { - return $ancestors; - } - - // Check if ancestors contains 'challenges-forums' - foreach ($ancestors as $id => $ancestor) { - if($ancestor['UrlCode'] == self::CHALLENGE_FORUMS_URLCODE) { + return $temp; + } else { + $urlCode = val('UrlCode', $Category); + if ($urlCode == self::CHALLENGE_FORUMS_URLCODE) { return $ancestors; } - } - // FIX https://github.com/topcoder-platform/forums/issues/487 - // Go to a parent category at a home page - foreach ($ancestors as $id => $ancestor) { - if ($ancestor['ParentCategoryID'] == -1) { - $ancestors[$id]['Url'] = url('/categories/#Category_'.$parentCategoryID, true); + // Check if ancestors contains 'challenges-forums' + foreach ($ancestors as $id => $ancestor) { + if ($ancestor['UrlCode'] == self::CHALLENGE_FORUMS_URLCODE) { + return $ancestors; + } + } + + // FIX https://github.com/topcoder-platform/forums/issues/487 + // Go to a parent category at a home page + foreach ($ancestors as $id => $ancestor) { + if ($ancestor['ParentCategoryID'] == -1) { + $ancestors[$id]['Url'] = url('/categories/#Category_' . $parentCategoryID, true); + } } - } - return $ancestors; + return $ancestors; + } } } diff --git a/vanilla/js/embed.js b/vanilla/js/embed.js index 0a9ed28..eb7b891 100644 --- a/vanilla/js/embed.js +++ b/vanilla/js/embed.js @@ -262,9 +262,13 @@ window.vanilla.embed = function(host) { embed_type_result = '&embed_type=mfe'; } if (typeof (vanilla_category_id) != 'undefined') { + var default_page = '/group/'; + if(typeof(vanilla_embed_page) != 'undefined' && (vanilla_embed_page == 'group' || vanilla_embed_page == 'categories') ) { + default_page = '/' + vanilla_embed_page + '/'; + } result = '//' + host - + '/categories/' + encodeURIComponent(vanilla_category_id) + '/?' + + default_page + encodeURIComponent(vanilla_category_id) + '/?' + 'remote=' + encodeURIComponent(embedUrl) + '&locale='