From 8cab50874c65e7acbf921c3f0fe902768b43cf11 Mon Sep 17 00:00:00 2001 From: Clare Ming Date: Wed, 7 Apr 2021 09:56:41 -0600 Subject: [PATCH] Add config for language in header for logged in/out users Register updated requirement for language in header for logged in and logged out users in Vector's ServiceWiring file. Make VectorLanguageInHeader backwards compatible to handle boolean values when registering LanguageInHeader feature. Update VectorLanguageInHeader variable to array in config to handle different logged states. Bug: T277588 Change-Id: I37a3a01e83f051cf0679769c8b9b5b41f00d6d72 --- includes/ServiceWiring.php | 25 +++++++++++++++++++------ skin.json | 7 +++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index 8cded60..f686793 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -69,12 +69,25 @@ return [ // Feature: Languages in sidebar // ================================ - $featureManager->registerRequirement( - new DynamicConfigRequirement( - $services->getMainConfig(), - Constants::CONFIG_KEY_LANGUAGE_IN_HEADER, - Constants::REQUIREMENT_LANGUAGE_IN_HEADER - ) + $config = $services->getMainConfig(); + $languageInHeaderConfig = $config->get( Constants::CONFIG_KEY_LANGUAGE_IN_HEADER ); + + // Backwards compatibility with config variables that have been set in production. + if ( is_bool( $languageInHeaderConfig ) ) { + $languageInHeaderConfig = [ + 'logged_in' => $languageInHeaderConfig, + 'logged_out' => $languageInHeaderConfig, + ]; + } else { + $languageInHeaderConfig = [ + 'logged_in' => $languageInHeaderConfig['logged_in'] ?? false, + 'logged_out' => $languageInHeaderConfig['logged_out'] ?? false, + ]; + } + + $featureManager->registerSimpleRequirement( + Constants::REQUIREMENT_LANGUAGE_IN_HEADER, + $languageInHeaderConfig[ $context->getUser()->isRegistered() ? 'logged_in' : 'logged_out' ] ); $featureManager->registerFeature( diff --git a/skin.json b/skin.json index 58d790c..043be0f 100644 --- a/skin.json +++ b/skin.json @@ -271,8 +271,11 @@ "value": false }, "VectorLanguageInHeader": { - "value": false, - "description": "@var boolean Moves the language links from the sidebar into a menu beside the page title. Also moves the indicators to the line below, next to the tagline (siteSub)." + "value": { + "logged_in": false, + "logged_out": false + }, + "description": "@var array Moves the language links from the sidebar into a menu beside the page title. Also moves the indicators to the line below, next to the tagline (siteSub)." }, "VectorDisableSidebarPersistence": { "value": false,