moodle-an-hochschulen / moodle-theme_boost_union

Theme Boost Union is an enhanced child theme of Boost which is intended, on the one hand, to make Boost simply more configurable and, on the other hand, to provide helpful additional features for the daily Moodle operation of admins, teachers and students.
GNU General Public License v3.0
61 stars 54 forks source link

FR: Child Theming: Union's extra SCSS could already replicate Boost's extra SCSS rules if a theme with Boost Union as its ancestor is the current theme #718

Open danowar2k opened 2 days ago

danowar2k commented 2 days ago

Is your feature request related to a problem? Please describe. In our child theme we currently need to do this:

/**
 * Get SCSS to append.
 * @return string
 */
function theme_boost_union_feu_base_get_extra_scss():string {
    // Boost's extra SCSS function is called automatically before this,
    // but is only given the current theme's config.
    // Boost Union Feu Base doesn't replicate Boost's settings so that call leads to incomplete SCSS
    // Boost Union has Boost's extra SCSS relevant settings replicated,
    // so we load Boost Union's config and then get Boost's correct extra SCSS
    $unionConfig = theme_config::load('boost_union');
    $boostExtraScss = theme_boost_get_extra_scss($unionConfig);
    // Even though boost_union's config has already been called and produced the correct extra SCSS,
    // that is now "before" the currently produced Boost SCSS, so we need to again create the Union extra SCSS
    // to avoid that Union's SCSS is overwritten by Boost's SCSS rules
    $boostUnionExtraScss = theme_boost_union_get_extra_scss($unionConfig);
    return $boostExtraScss.$boostUnionExtraScss;
}

Basically, Moodle runs each theme's extra SCSS function in the ancestry with the $theme object of the current theme. When your theme doesn't replicate Boost's settings backgroundimage, loginbackgroundimage and scss, that extra SCSS generated by Boost's function is incomplete. Boost Union replicates those settings, so we run Boost's extra SCSS function again with Union's config to get the correct SCSS. But then we have to run Union's extra SCSS function again to have a correct order for the SCSS rules.

Describe the solution you'd like Union could already run Boost's extra SCSS function at the start of its own extra SCSS function with the Union config as the parameter to generate the correct SCSS. This way we wouldn't even need our own extra SCSS function anymore.

Of course, this should only be necessary if Union isn't the current theme.

Describe alternatives you've considered Reproducing the settings still doesn't make sense to me...

danowar2k commented 2 days ago

Proposed solution:

function theme_boost_union_get_extra_scss($theme) {
    global $CFG;

    // Require the necessary libraries.
    require_once($CFG->dirroot . '/course/lib.php');

    // Initialize extra SCSS.
    $content = '';

    // Fetch Boost's extra SCSS if the current theme is not Union itself (can only be a child theme then)
    if ($theme->name !== 'boost_union') {
        $union_config = theme_config::load('boost_union');
        $content .= theme_boost_get_extra_scss($union_config);
    }
    // You might think that this extra SCSS function is only called for the activated theme.
danowar2k commented 2 days ago

Hmmm, maybe this issue will be resolved by my proposed change, too? https://github.com/moodle-an-hochschulen/moodle-theme_boost_union_child/issues/5