-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHelpers.php
More file actions
65 lines (50 loc) · 1.49 KB
/
Helpers.php
File metadata and controls
65 lines (50 loc) · 1.49 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
<?php
namespace OWC\PrefillGravityForms\Foundation\Helpers;
use OWC\PrefillGravityForms\Foundation\Plugin;
function app(): Plugin
{
return resolve('app');
}
function make($name, $container)
{
return \Yard\DigiD\Foundation\Plugin::getInstance()->getContainer()->set($name, $container);
}
function storage_path(string $path = ''): string
{
return \ABSPATH . '../../storage/' . $path;
}
function resolve($container, $arguments = [])
{
return \OWC\PrefillGravityForms\Foundation\Plugin::getInstance()->getContainer()->get($container, $arguments);
}
function config(string $setting, $default = '')
{
return resolve('config')->get($setting, $default);
}
function view(string $template, array $vars = []): string
{
$view = resolve(\OWC\PrefillGravityForms\Foundation\View::class);
if (! $view->exists($template)) {
return '';
}
return $view->render($template, $vars);
}
/**
* Get the current selected supplier on a per form basis.
* Returns label as default, use parameter $getKey to return the key from the config array.
*/
function get_supplier(array $form, bool $getKey = false): string
{
$allowed = config('suppliers', []);
$supplier = $form[sprintf('%s-form-setting-supplier', 'owc')] ?? '';
if (! is_array($allowed) || empty($allowed) || empty($supplier)) {
return '';
}
if (! in_array($supplier, array_keys($allowed))) {
return '';
}
if ($getKey) {
return $supplier;
}
return $allowed[$supplier] ?? '';
}