From 75fdcd168e74c5d59330281b28a691533c9ffd5e Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Mon, 9 Oct 2017 10:59:46 +0100 Subject: [PATCH] Added support for custom channel contexts (#9114) refs #5091 - This simple change allows custom contexts to use existing channel logic - E.g. if we want to create a custom tag-based channel, it can pass "tag" as the context, and get all the same metadata logic --- core/server/controllers/frontend/context.js | 6 +++++- .../unit/controllers/frontend/context_spec.js | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/core/server/controllers/frontend/context.js b/core/server/controllers/frontend/context.js index 276cf3e939..83496d415c 100644 --- a/core/server/controllers/frontend/context.js +++ b/core/server/controllers/frontend/context.js @@ -54,7 +54,11 @@ function setResponseContext(req, res, data) { // Each page can only have at most one of these if (res.locals.channel) { - res.locals.context.push(res.locals.channel.name); + if (res.locals.channel.context) { + res.locals.context = res.locals.context.concat(res.locals.channel.context); + } else { + res.locals.context.push(res.locals.channel.name); + } } else if (privatePattern.test(res.locals.relativeUrl)) { res.locals.context.push('private'); } else if (subscribePattern.test(res.locals.relativeUrl) && labs.isSet('subscribers') === true) { diff --git a/core/test/unit/controllers/frontend/context_spec.js b/core/test/unit/controllers/frontend/context_spec.js index fc4ae5951c..533aac2eca 100644 --- a/core/test/unit/controllers/frontend/context_spec.js +++ b/core/test/unit/controllers/frontend/context_spec.js @@ -273,6 +273,23 @@ describe('Contexts', function () { res.locals.context[0].should.eql('featured'); }); + it('will use a custom context for a custom channel', function () { + var channel = _.clone(featuredChannel); + channel.context = ['custom-context', 'test']; + + // Setup test + setupContext('/featured/', channel); + + // Execute test + setResponseContext(req, res, data); + + // Check context + should.exist(res.locals.context); + res.locals.context.should.be.an.Array().with.lengthOf(2); + res.locals.context[0].should.eql('custom-context'); + res.locals.context[1].should.eql('test'); + }); + it('will not identify /page/2/ as paged without page param', function () { // Setup test setupContext('/featured/page/2/', featuredChannel);