1416 |
ariadna |
1 |
<?php
|
|
|
2 |
defined('MOODLE_INTERNAL') || die();
|
|
|
3 |
|
|
|
4 |
// Create a new settings page for inherited settings
|
|
|
5 |
$page = new admin_settingpage('theme_universe_child_inherited', get_string('inheritedsettings', 'theme_universe_child'));
|
|
|
6 |
|
|
|
7 |
// Function to get parent theme settings
|
|
|
8 |
function theme_universe_child_get_parent_settings()
|
|
|
9 |
{
|
|
|
10 |
global $CFG;
|
|
|
11 |
|
|
|
12 |
$settings = [];
|
|
|
13 |
$parent_settings_dir = $CFG->dirroot . '/theme/universe/settings/';
|
|
|
14 |
|
|
|
15 |
if (is_dir($parent_settings_dir)) {
|
|
|
16 |
$files = scandir($parent_settings_dir);
|
|
|
17 |
foreach ($files as $file) {
|
|
|
18 |
if (pathinfo($file, PATHINFO_EXTENSION) === 'php') {
|
|
|
19 |
$settings[] = $file;
|
|
|
20 |
}
|
|
|
21 |
}
|
|
|
22 |
}
|
|
|
23 |
|
|
|
24 |
return $settings;
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
// Function to apply parent settings to child theme
|
|
|
28 |
function theme_universe_child_apply_parent_settings($settings)
|
|
|
29 |
{
|
|
|
30 |
global $CFG, $page;
|
|
|
31 |
|
|
|
32 |
foreach ($settings as $setting) {
|
|
|
33 |
$parent_setting = $CFG->dirroot . '/theme/universe/settings/' . $setting;
|
|
|
34 |
if (file_exists($parent_setting)) {
|
|
|
35 |
// Include the parent setting file
|
|
|
36 |
require_once($parent_setting);
|
|
|
37 |
|
|
|
38 |
// Modify the setting names to use child theme prefix
|
|
|
39 |
if (isset($setting)) {
|
|
|
40 |
$setting->name = str_replace('theme_universe/', 'theme_universe_child/', $setting->name);
|
|
|
41 |
}
|
|
|
42 |
}
|
|
|
43 |
}
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
// Get and apply parent settings
|
|
|
47 |
$parent_settings = theme_universe_child_get_parent_settings();
|
|
|
48 |
theme_universe_child_apply_parent_settings($parent_settings);
|
|
|
49 |
|
|
|
50 |
// Add the page to the settings
|
|
|
51 |
$settings->add($page);
|