-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlib.php
158 lines (132 loc) · 6.45 KB
/
lib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Theme Boost Union Child - Library
*
* @package theme_boost_union_child
* @copyright 2023 Daniel Poggenpohl <[email protected]> and Alexander Bias <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// Constants which are use throughout this theme.
define('THEME_BOOST_UNION_CHILD_SETTING_INHERITANCE_INHERIT', 0);
define('THEME_BOOST_UNION_CHILD_SETTING_INHERITANCE_DUPLICATE', 1);
/**
* Returns the main SCSS content.
*
* @param \core\output\theme_config $theme The theme config object.
* @return string
*/
function theme_boost_union_child_get_main_scss_content($theme) {
global $CFG;
// Require the necessary libraries.
require_once($CFG->dirroot . '/theme/boost_union/lib.php');
// As a start, get the compiled main SCSS from Boost Union.
// This way, Boost Union Child will ship the same SCSS code as Boost Union itself.
$scss = theme_boost_union_get_main_scss_content(\core\output\theme_config::load('boost_union'));
// And add Boost Union Child's main SCSS file to the stack.
$scss .= file_get_contents($CFG->dirroot . '/theme/boost_union_child/scss/post.scss');
return $scss;
}
/**
* Get SCSS to prepend.
*
* @param \core\output\theme_config $theme The theme config object.
* @return string
*/
function theme_boost_union_child_get_pre_scss($theme) {
global $CFG;
// Require the necessary libraries.
require_once($CFG->dirroot . '/theme/boost_union/lib.php');
// As a start, initialize the Pre SCSS code with an empty string.
$scss = '';
// Then, if configured, get the compiled pre SCSS code from Boost Union.
// This should not be necessary as Moodle core calls the *_get_pre_scss() functions from all parent themes as well.
// However, as soon as Boost Union would use $theme->settings in this function, $theme would be this theme here and
// not Boost Union. The Boost Union developers are aware of this topic, but faults can always happen.
// If such a fault happens, the Boost Union Child administrator can switch the inheritance to 'Duplicate'.
// This way, we will add the pre SCSS code with the explicit use of the Boost Union configuration to the stack.
$inheritanceconfig = get_config('theme_boost_union_child', 'prescssinheritance');
if ($inheritanceconfig == THEME_BOOST_UNION_CHILD_SETTING_INHERITANCE_DUPLICATE) {
$scss .= theme_boost_union_get_pre_scss(\core\output\theme_config::load('boost_union'));
}
// And add Boost Union Child's pre SCSS file to the stack.
$scss .= file_get_contents($CFG->dirroot . '/theme/boost_union_child/scss/pre.scss');
/**********************************************************
* EXTENSION POINT:
* Compose and add additional pre-SCSS code here.
* It will be added on top of Boost Union's pre-SCSS code.
*********************************************************/
return $scss;
}
/**
* Inject additional SCSS.
*
* @param \core\output\theme_config $theme The theme config object.
* @return string
*/
function theme_boost_union_child_get_extra_scss($theme) {
global $CFG;
// Require the necessary libraries.
require_once($CFG->dirroot . '/theme/boost_union/lib.php');
// As a start, initialize the Extra SCSS code with an empty string.
$scss = '';
// Then, if configured, get the compiled extra SCSS code from Boost Union.
// This should not be necessary as Moodle core calls the *_get_extra_scss() functions from all parent themes as well.
// However, as soon as Boost Union would use $theme->settings in this function, $theme would be this theme here and
// not Boost Union. The Boost Union developers are aware of this topic, but faults can always happen.
// If such a fault happens, the Boost Union Child administrator can switch the inheritance to 'Duplicate'.
// This way, we will add the extra SCSS code with the explicit use of the Boost Union configuration to the stack.
$inheritanceconfig = get_config('theme_boost_union_child', 'extrascssinheritance');
if ($inheritanceconfig == THEME_BOOST_UNION_CHILD_SETTING_INHERITANCE_DUPLICATE) {
$scss .= theme_boost_union_get_extra_scss(\core\output\theme_config::load('boost_union'));
}
/**********************************************************
* EXTENSION POINT:
* Compose and add additional SCSS code here.
* It will be added on top of Boost Union's SCSS code.
*********************************************************/
return $scss;
}
/**
* Callback function for theme_boost_union to allow Boost Union Child to add cards to the Boost Union settings overview page.
* This function is expected to return an array of arrays containing values with the keys 'label', 'desc', 'btn' and 'url'.
*
* @return array
*/
function theme_boost_union_child_extend_busettingsoverview() {
$cards[] = [
'label' => get_string('pluginname', 'theme_boost_union_child'),
'desc' => get_string('settingsoverview_buc_desc', 'theme_boost_union_child'),
'btn' => 'primary',
'url' => new \core\url('/admin/settings.php', ['section' => 'theme_boost_union_child']),
];
return $cards;
}
/**
* Callback function which allows themes to alter the CSS URLs.
* We use this function to change the CSS URL to the flavour CSS URL if a flavour applies to the current page.
*
* @copyright 2024 Alexander Bias <[email protected]>
*
* @param mixed $urls The CSS URLs (passed as reference).
*/
function theme_boost_union_child_alter_css_urls(&$urls) {
global $CFG;
// Require Boost Union library.
require_once($CFG->dirroot.'/theme/boost_union/lib.php');
// Call Boost Union's theme_boost_union_alter_css_urls() function which implements the logic to change the CSS URL for flavours.
theme_boost_union_alter_css_urls($urls);
}