-
Notifications
You must be signed in to change notification settings - Fork 1
/
start.php
80 lines (64 loc) · 2.08 KB
/
start.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
<?php
/**
* Forms API
*
* @author Ismayil Khayredinov <info@hypejunction.com>
* @copyright Copyright (c) 2015, Ismayil Khayredinov
*/
require_once __DIR__ . '/autoloader.php';
elgg_register_event_handler('init', 'system', 'forms_init');
/**
* Initialize the plugin
* @return void
*/
function forms_init() {
elgg_extend_view('css/elgg', 'elements/forms/field.css');
elgg_extend_view('css/admin', 'elements/forms/field.css');
}
if (!function_exists('elgg_view_input')) {
/**
* Renders a form field
*
* @param string $input_type Input type, used to generate an input view ("input/$input_type")
* @param array $vars Fields and input vars.
* Field vars contain both field and input params. 'label', 'help',
* and 'field_class' params will not be passed on to the input view.
* Others, including 'required' and 'id', will be available to the
* input view. Both 'label' and 'help' params accept HTML, and
* will be printed unescaped within their wrapper element.
* @return string
*/
function elgg_view_input($input_type, array $vars = array()) {
static $id_num;
if (!elgg_view_exists("input/$input_type")) {
return '';
}
if ($input_type == 'hidden') {
return elgg_view("input/$input_type", $vars);
}
$id = elgg_extract('id', $vars);
if (!$id) {
$id_num++;
$id = "elgg-field-$id_num";
$vars['id'] = $id;
}
$vars['input_type'] = $input_type;
$label = elgg_view('elements/forms/label', $vars);
unset($vars['label']);
$help = elgg_view('elements/forms/help', $vars);
unset($vars['help']);
$required = elgg_extract('required', $vars);
$field_class = (array) elgg_extract('field_class', $vars, array());
unset($vars['field_class']);
$input = elgg_view("elements/forms/input", $vars);
return elgg_view('elements/forms/field', array(
'label' => $label,
'help' => $help,
'required' => $required,
'id' => $id,
'input' => $input,
'class' => $field_class,
'input_type' => $input_type,
));
}
}