Completed
Pull Request — master (#262)
by Rudie
07:30
created

helpers.php ➔ form_rows()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 7
rs 9.4285
1
<?php
2
3
use Kris\LaravelFormBuilder\Fields\FormField;
4
use Kris\LaravelFormBuilder\Form;
5
6
if (!function_exists('form')) {
7
8
    function form(Form $form, array $options = [])
9
    {
10
        return $form->renderForm($options);
11
    }
12
13
}
14
15
if (!function_exists('form_start')) {
16
17
    function form_start(Form $form, array $options = [])
18
    {
19
        return $form->renderForm($options, true, false, false);
20
    }
21
22
}
23
24
if (!function_exists('form_end')) {
25
26
    function form_end(Form $form, $showFields = true)
27
    {
28
        return $form->renderRest(true, $showFields);
29
    }
30
31
}
32
33
if (!function_exists('form_rest')) {
34
35
    function form_rest(Form $form)
36
    {
37
        return $form->renderRest(false);
38
    }
39
40
}
41
42
if (!function_exists('form_until')) {
43
44
    function form_until(Form $form, $field_name)
45
    {
46
        return $form->renderUntil($field_name, false);
47
    }
48
49
}
50
51
if (!function_exists('form_row')) {
52
53
    function form_row(FormField $formField, array $options = [])
54
    {
55
        return $formField->render($options);
56
    }
57
58
}
59
60
if (!function_exists('form_rows')) {
61
    function form_rows($form, array $fields, array $options = [])
62
    {
63
        // $form can be a Kris\LaravelFormBuilder\Form or a Kris\LaravelFormBuilder\Fields\ChildFormType
64
        return implode(array_map(function($field) use ($form, $options) {
65
            return $form->has($field) ? $form->getField($field)->render($options) : '';
66
        }, $fields));
67
    }
68
}
69
70
if (!function_exists('form_label')) {
71
72
    function form_label(FormField $formField, array $options = [])
73
    {
74
        return $formField->render($options, true, false, false);
75
    }
76
77
}
78
79
if (!function_exists('form_widget')) {
80
81
    function form_widget(FormField $formField, array $options = [])
82
    {
83
        return $formField->render($options, false, true, false);
84
    }
85
86
}
87
88
if (!function_exists('form_errors')) {
89
90
    function form_errors(FormField $formField, array $options = [])
91
    {
92
        return $formField->render($options, false, false, true);
93
    }
94
95
}
96