Completed
Push — master ( ceb694...183c93 )
by Rudie
01:46
created

helpers.php ➔ getFormBuilderViewPath()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 1
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
use Kris\LaravelFormBuilder\Fields\FormField;
4
use Kris\LaravelFormBuilder\Form;
5
6
if(!function_exists('getFormBuilderViewPath'))
7
{
8
    function getFormBuilderViewPath($fileName)
9
    {
10
        $p = explode('.',$fileName);
11
        $c = count($p);
12
        if($c>2 || $p[$c-1]!='php')
13
            throw new Exception('You should use only *.php files with this function');
14
15
        $path = base_path('resources/views/vendor/laravel-form-builder/'.$fileName);
16
        return file_exists($path) ? $path : __DIR__.'/views/'.$fileName;
17
    }
18
}
19
20
if(!function_exists('errorBlockPath'))
21
{
22
23
    function errorBlockPath()
24
    {
25
        return getFormBuilderViewPath('errors.php');
26
    }
27
28
}
29
30
if(!function_exists('helpBlockPath'))
31
{
32
33
    function helpBlockPath()
34
    {
35
        return getFormBuilderViewPath('help_block.php');
36
    }
37
38
}
39
40
if (!function_exists('form')) {
41
42
    function form(Form $form, array $options = [])
43
    {
44
        return $form->renderForm($options);
45
    }
46
47
}
48
49
if (!function_exists('form_start')) {
50
51
    function form_start(Form $form, array $options = [])
52
    {
53
        return $form->renderForm($options, true, false, false);
54
    }
55
56
}
57
58
if (!function_exists('form_end')) {
59
60
    function form_end(Form $form, $showFields = true)
61
    {
62
        return $form->renderRest(true, $showFields);
63
    }
64
65
}
66
67
if (!function_exists('form_rest')) {
68
69
    function form_rest(Form $form)
70
    {
71
        return $form->renderRest(false);
72
    }
73
74
}
75
76
if (!function_exists('form_until')) {
77
78
    function form_until(Form $form, $field_name)
79
    {
80
        return $form->renderUntil($field_name, false);
81
    }
82
83
}
84
85
if (!function_exists('form_row')) {
86
87
    function form_row(FormField $formField, array $options = [])
88
    {
89
        return $formField->render($options);
90
    }
91
92
}
93
94
if (!function_exists('form_rows')) {
95
    function form_rows(Form $form, array $fields, array $options = [])
96
    {
97
        return implode(array_map(function($field) use ($form, $options) {
98
            return $form->has($field) ? $form->getField($field)->render($options) : '';
99
        }, $fields));
100
    }
101
}
102
103
if (!function_exists('form_label')) {
104
105
    function form_label(FormField $formField, array $options = [])
106
    {
107
        return $formField->render($options, true, false, false);
108
    }
109
110
}
111
112
if (!function_exists('form_widget')) {
113
114
    function form_widget(FormField $formField, array $options = [])
115
    {
116
        return $formField->render($options, false, true, false);
117
    }
118
119
}
120
121
if (!function_exists('form_errors')) {
122
123
    function form_errors(FormField $formField, array $options = [])
124
    {
125
        return $formField->render($options, false, false, true);
126
    }
127
128
}
129
130
if (!function_exists('form_fields')) {
131
132
    function form_fields(Form $form, array $options = [])
133
    {
134
        return $form->renderForm($options, false, true, false);
135
    }
136
137
}
138