Change subtheme globally

I am trying to repurpose the quick create button to change user subthemes.

I’ve copied and modified this file:
custom/themes/SuiteP/tpls/headerModuleList.tpl

line 672

        <div class="desktop-bar">
            <ul id="toolbar" class="toolbar">
                <li id="quickcreatetop" class="create dropdown nav navbar-nav quickcreatetop">
                    <button class="dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="false">
                      <!--startCustomCode-->
                      {$APP.LBL_CHANGE_VALUE_STREAM_BUTTON_LABEL}<span class="suitepicon suitepicon-action-caret"></span>
                    </a>
                  </button>

                    <ul class="dropdown-menu" >
                      <li><a class="dropdown-item" href="#" onclick= "setDawn()">{"Dawn" label='LBL_SUBTHEME_OPTIONS_DAWN'}</em></a></li>
                      <li><a class="dropdown-item" href="index.php?module=Users&action=EditView&record={$CURRENT_USER_ID}">{"Day" label='LBL_SUBTHEME_OPTIONS_DAY'}</a></li>
                      <li><a class="dropdown-item" href="index.php?module=Users&action=EditView&record={$CURRENT_USER_ID}">{"Dusk" label='LBL_SUBTHEME_OPTIONS_DUSK'}</a></li>
                      <li><a class="dropdown-item" href="index.php?module=Users&action=EditView&record={$CURRENT_USER_ID}">{"Night" label='LBL_SUBTHEME_OPTIONS_NIGHT'}</a></li>
                      <!--endCustomCode-->
                    </ul>
                </li>

I want the dropdown options to call a function to change the subtheme to dawn, day, dusk, or night on click.
I’m stuck here on how to write the function to setDawn() and change the user preference onlick to dawn subtheme. once I figure that out, then I can write setDay() and so forth.
any help to reference and change from the tpl file would be appreciated

here is the document to customizing the sub-theme

Thanks for the reply @vijay1992 . Not quite what I’m looking for, I know how to create/modify subtheme and css. I need to onclick change the subtheme from the “Quick Create” button in the header.

Make a copy of themes/SuiteP/themedef.php to custom/themes/SuiteP/themedef.php and set the default one there.

Thanks for the reply @BrozTechnologies . Not quite what I’m looking for, I know how to create/modify subtheme and css in custom directory. I need to onclick change the subtheme dynamically from the “Quick Create” button in the header.

Alright. I’ll recommend you to find the code that does just that from the user profile.

One thing to have into consideration is the fact that user might need to logout/login in order for the changes to be effective

I solved this. with .$post from headerModuleList.tpl to a custom entrypoint and custom php script

@BrozTechnologies you were right, I had to logout at after updating encoded user db of current user record identifying key value subtheme as Var. solved this with :
$current_user->reloadPreferences();

also added custom logos in top left corner of header to represent value streams and marking custom field in every module as related value stream.

<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

//echo 'Switch to ' .$_POST['value']. ' Value Stream';

switch ($_POST['value']) {
    case 'company1':
        $vs =  'C1';
        $subt = 'dawn';
        break;
    case 'Company2':
        $vs =  'C2';
        $subt = 'dusk';
        break;
    case 'Company3':
        $vs = 'C3';
        $subt = 'day';
        break;
    case 'Company4':
        $vs = 'C4';
        $subt = 'night';
        break;
};


global $current_user, $db;
  $current_user -> value_stream_c = $vs;
  $current_user -> save();

       $sql = "SELECT contents FROM user_preferences WHERE category='global' AND assigned_user_id= '$current_user->id'";
       $result = $db->query($sql);
       while ($row = $db->fetchByAssoc($result)) {
           $prefs = array();
           $newprefs = array();

           $prefs = unserialize(base64_decode($row['contents']));
           $subthemeValue = $prefs['subtheme'];
           $newsubtheme = $prefs['subtheme']= ($subt);
           $newprefs = $prefs;
        $newsubtheme2 = base64_encode(serialize($newprefs));
        $update = "UPDATE user_preferences SET contents = '{$newsubtheme2}' WHERE category='global' AND assigned_user_id= '$current_user->id'";
        $db->query($update);

        $sql2 = "SELECT contents FROM user_preferences WHERE category='global' AND assigned_user_id= '$current_user->id'";
        $result2 = $db->query($sql2);
  $current_user->reloadPreferences();

  unset($prefs);
  unset($newprefs);
  unset($newstr);
    exit;
}


 ?>
1 Like

Good work!!!

Thanks for sharing the solution :+1: :+1: