Elgg  Version master
CssCompiler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Assets;
4 
6 use Elgg\Includer;
8 
14 class CssCompiler {
15 
21  public function __construct(protected EventsService $events) {
22  }
23 
32  public function getCssVars(array $compiler_options = [], bool $load_config_vars = true): array {
33  $default_vars = array_merge($this->getCoreVars(), $this->getPluginVars());
34  $custom_vars = (array) elgg_extract('vars', $compiler_options, []);
35  $vars = array_merge($default_vars, $custom_vars);
36 
37  $results = (array) $this->events->triggerResults('vars:compiler', 'css', $compiler_options, $vars);
38 
39  if (!$load_config_vars) {
40  return $results;
41  }
42 
43  return array_merge($results, (array) elgg_get_config('custom_theme_vars', []));
44  }
45 
51  protected function getCoreVars(): array {
52  $file = Paths::elgg() . 'engine/theme.php';
53  return Includer::includeFile($file);
54  }
55 
61  protected function getPluginVars(): array {
62  $return = [];
63 
64  $plugins = elgg_get_plugins('active');
65  foreach ($plugins as $plugin) {
66  $plugin_vars = $plugin->getStaticConfig('theme', []);
67  if (empty($plugin_vars)) {
68  continue;
69  }
70 
71  $return = array_merge($return, $plugin_vars);
72  }
73 
74  return $return;
75  }
76 }
$vars
Definition: theme.php:3
Gives access to CSS variables in the system.
Definition: CssCompiler.php:14
getCssVars(array $compiler_options=[], bool $load_config_vars=true)
Fetches a combined set of CSS variables and their value.
Definition: CssCompiler.php:32
getPluginVars()
Plugin theme variables.
Definition: CssCompiler.php:61
__construct(protected EventsService $events)
Constructor.
Definition: CssCompiler.php:21
getCoreVars()
Default Elgg theme variables.
Definition: CssCompiler.php:51
Events service.
Allow executing scripts without $this context or local vars.
Definition: Includer.php:10
static includeFile($file)
Include a file with as little context as possible.
Definition: Includer.php:18
Find Elgg and project paths.
Definition: Paths.php:8
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
elgg()
Bootstrapping and helper procedural code available for use in Elgg core and plugins.
Definition: elgglib.php:12
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:246
elgg_get_plugins(string $status='active')
Returns an ordered list of plugins.
Definition: plugins.php:39
$plugin
$results
Definition: content.php:22