-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionsAPI.php
More file actions
93 lines (79 loc) · 3.04 KB
/
FunctionsAPI.php
File metadata and controls
93 lines (79 loc) · 3.04 KB
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
<?php
namespace ProcessWire;
function component(string|array $component, array $params = [], array $attrs = [], string|null $cacheName = null, int|Page|string|null $cacheExpire = null): string
{
return wire('component')->render($component, $params, $attrs, $cacheName, $cacheExpire);
}
function renderComponentChildren(array $children, ?array $parent = null): string
{
return wire('component')->renderChildren($children, $parent);
}
function renderComponentChild(array $child, ?array $parent = null): string
{
return wire('component')->renderChild($child, $parent);
}
function loadComponent(string $name, array $params = [], array $attrs = []): ?array
{
return wire('component')->loadComponent($name, $params, $attrs);
}
function setComponentOptions(string|array $components, string $field, array $options = [])
{
if (is_array($components)) {
foreach ($components as $component) {
$key = "component.{$component}.options.{$field}";
$options = array_merge(setting($key) ?: [], $options);
setting($key, $options);
}
} else {
$key = "component.{$components}.options.{$field}";
$options = array_merge(setting($key) ?: [], $options);
setting($key, $options);
}
}
function getComponentOptions(string $component, string $field, array $options = [])
{
return array_merge($options, setting("component.{$component}.options.{$field}") ?: []);
}
function setComponentOption(string $component, string $field, array $option)
{
$options = getComponentOptions($component, $field);
$options += $option;
setComponentOptions($component, $field, $options);
}
function getComponentOption(string $component, string $field, array $option = [])
{
$options = getComponentOptions($component, $field);
$options += $option;
return $options;
}
function setComponentDefaults(string|array $components, array $defaults = [])
{
if (is_array($components)) {
foreach ($components as $component) {
$defaults = array_merge(setting("component.{$component}.defaults") ?: [], $defaults);
setting("component.{$component}.defaults", $defaults);
}
} else {
$defaults = array_merge(setting("component.{$components}.defaults") ?: [], $defaults);
setting("component.{$components}.defaults", $defaults);
}
}
function setComponentDefault(string $component, string $key, mixed $value)
{
$defaults = getComponentDefaults($component);
$defaults[$key] = $value;
setComponentDefaults($component, $defaults);
}
function getComponentDefaults(string $component, array $defaults = []): array
{
// get and merge defaults for given component
$defaults = array_merge(setting("component.{$component}.defaults") ?: [], $defaults);
// set merged defaults for given component
// setting("component.{$component}.defaults", $defaults);
return $defaults;
}
function getComponentDefault(string $component, string $key, mixed $default = null)
{
$defaults = getComponentDefaults($component);
return $defaults[$key] ?? $default;
}