Skip to content

Commit 3831a1b

Browse files
Initital repository
0 parents  commit 3831a1b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+8040
-0
lines changed

composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "botble/form-builder",
3+
"description": "Laravel form builder - symfony like",
4+
"extra": {
5+
"laravel": {
6+
"providers": [
7+
"Kris\\LaravelFormBuilder\\FormBuilderServiceProvider"
8+
],
9+
"aliases": {
10+
"FormBuilder": "Kris\\LaravelFormBuilder\\Facades\\FormBuilder"
11+
}
12+
}
13+
},
14+
"autoload": {
15+
"psr-4": {
16+
"Kris\\LaravelFormBuilder\\": "src/"
17+
},
18+
"files": [
19+
"helpers/helpers.php"
20+
]
21+
}
22+
}

config/config.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
use Kris\LaravelFormBuilder\Form;
4+
use Kris\LaravelFormBuilder\FormBuilder;
5+
use Kris\LaravelFormBuilder\FormHelper;
6+
7+
return [
8+
'defaults' => [
9+
'wrapper_class' => 'form-group',
10+
'wrapper_error_class' => 'has-error',
11+
'label_class' => 'control-label',
12+
'field_class' => 'form-control',
13+
'field_error_class' => '',
14+
'help_block_class' => 'help-block',
15+
'error_class' => 'text-danger',
16+
'required_class' => 'required',
17+
18+
'help_block_tag' => 'p',
19+
20+
// Override a class from a field.
21+
//'text' => [
22+
// 'wrapper_class' => 'form-field-text',
23+
// 'label_class' => 'form-field-text-label',
24+
// 'field_class' => 'form-field-text-field',
25+
//]
26+
//'radio' => [
27+
// 'choice_options' => [
28+
// 'wrapper' => ['class' => 'form-radio'],
29+
// 'label' => ['class' => 'form-radio-label'],
30+
// 'field' => ['class' => 'form-radio-field'],
31+
// ]
32+
//],
33+
//
34+
// 'choice' => [
35+
// 'choice_options' => [
36+
// 'wrapper_class' => 'choice-wrapper-class',
37+
// 'label_class' => 'choice-label-class',
38+
// 'field_class' => 'choice-field-class'
39+
//
40+
// # For choice type you may overwrite default choice options for each variant (checkbox, radio or select)
41+
// 'checkbox' => [
42+
// 'wrapper_class' => 'choice-checkbox-wrapper-class',
43+
// 'label_class' => 'choice-checkbox-label-class',
44+
// 'field_class' => 'choice-checkbox-field-class',
45+
// ]
46+
// ]
47+
//]
48+
],
49+
// Templates
50+
'form' => 'laravel-form-builder::form',
51+
'text' => 'laravel-form-builder::text',
52+
'textarea' => 'laravel-form-builder::textarea',
53+
'button' => 'laravel-form-builder::button',
54+
'buttongroup' => 'laravel-form-builder::buttongroup',
55+
'radio' => 'laravel-form-builder::radio',
56+
'checkbox' => 'laravel-form-builder::checkbox',
57+
'select' => 'laravel-form-builder::select',
58+
'choice' => 'laravel-form-builder::choice',
59+
'repeated' => 'laravel-form-builder::repeated',
60+
'child_form' => 'laravel-form-builder::child_form',
61+
'collection' => 'laravel-form-builder::collection',
62+
'static' => 'laravel-form-builder::static',
63+
64+
// Remove the laravel-form-builder:: prefix above when using template_prefix
65+
'template_prefix' => '',
66+
67+
'default_namespace' => '',
68+
69+
'custom_fields' => [
70+
// 'datetime' => App\Forms\Fields\Datetime::class
71+
],
72+
73+
'plain_form_class' => Form::class,
74+
'form_builder_class' => FormBuilder::class,
75+
'form_helper_class' => FormHelper::class,
76+
];

helpers/helpers.php

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

resources/views/button.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php if ($options['wrapper'] !== false): ?>
2+
<div <?= $options['wrapperAttrs'] ?> >
3+
<?php endif; ?>
4+
5+
<?= Form::button($options['label'], $options['attr']) ?>
6+
<?php include helpBlockPath(); ?>
7+
8+
<?php if ($options['wrapper'] !== false): ?>
9+
</div>
10+
<?php endif; ?>

resources/views/buttongroup.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php if ($options['wrapper'] !== false): ?>
2+
<div <?= $options['wrapperAttrs'] ?> >
3+
<?php endif; ?>
4+
5+
<?php if (! $options['splitted']): ?>
6+
<div class="btn-group btn-group-<?= $options['size'] ?>">
7+
<?php endif; ?>
8+
9+
<?php foreach($options['buttons'] as $button): ?>
10+
<?= Form::button($button['label'], $button['attr']) ?>
11+
<?php endforeach; ?>
12+
13+
<?php if (! $options['splitted']): ?>
14+
</div>
15+
<?php endif; ?>
16+
17+
18+
<?php if ($options['wrapper'] !== false): ?>
19+
</div>
20+
<?php endif; ?>

resources/views/checkbox.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php if ($showLabel && $showField): ?>
2+
<?php if ($options['wrapper'] !== false): ?>
3+
<div <?= $options['wrapperAttrs'] ?> >
4+
<?php endif; ?>
5+
<?php endif; ?>
6+
7+
<?php if ($showField): ?>
8+
<?= Form::checkbox($name, $options['value'], $options['checked'], $options['attr']) ?>
9+
10+
<?php /** label rendering section */ ?>
11+
<?php if ($showLabel && $options['label'] !== false && $options['label_show']): ?>
12+
<?php if(array_key_exists('label_template', $options) && $options['label_template']): ?>
13+
<?= view($options['label_template'], get_defined_vars())->render(); ?>
14+
<?php else: ?>
15+
<?php include labelBlockPath(); ?>
16+
<?php endif; ?>
17+
<?php endif; ?>
18+
19+
<?php include helpBlockPath(); ?>
20+
<?php endif; ?>
21+
22+
<?php include errorBlockPath(); ?>
23+
24+
<?php if ($showLabel && $showField): ?>
25+
<?php if ($options['wrapper'] !== false): ?>
26+
</div>
27+
<?php endif; ?>
28+
<?php endif; ?>

resources/views/child_form.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php if ($showLabel && $showField): ?>
2+
<?php if ($options['wrapper'] !== false): ?>
3+
<div <?= $options['wrapperAttrs'] ?> >
4+
<?php endif; ?>
5+
<?php endif; ?>
6+
7+
<?php /** label rendering section */ ?>
8+
<?php if ($showLabel && $options['label'] !== false && $options['label_show']): ?>
9+
<?php if(array_key_exists('label_template', $options) && $options['label_template']): ?>
10+
<?= view($options['label_template'], get_defined_vars())->render(); ?>
11+
<?php else: ?>
12+
<?php include labelBlockPath(); ?>
13+
<?php endif; ?>
14+
<?php endif; ?>
15+
16+
<?php if ($showField): ?>
17+
<?php foreach ((array) $options['children'] as $child): ?>
18+
<?php if(! in_array($child->getRealName(), (array) $options['exclude'])) { ?>
19+
<?= $child->render() ?>
20+
<?php } ?>
21+
<?php endforeach; ?>
22+
23+
<?php include helpBlockPath(); ?>
24+
25+
<?php endif; ?>
26+
27+
<?php include errorBlockPath(); ?>
28+
29+
<?php if ($showLabel && $showField): ?>
30+
<?php if ($options['wrapper'] !== false): ?>
31+
</div>
32+
<?php endif; ?>
33+
<?php endif; ?>

resources/views/choice.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php if ($showLabel && $showField): ?>
2+
<?php if ($options['wrapper'] !== false): ?>
3+
<div <?= $options['wrapperAttrs'] ?> >
4+
<?php endif; ?>
5+
<?php endif; ?>
6+
7+
<?php /** label rendering section */ ?>
8+
<?php if ($showLabel && $options['label'] !== false && $options['label_show']): ?>
9+
<?php if(array_key_exists('label_template', $options) && $options['label_template']): ?>
10+
<?= view($options['label_template'], get_defined_vars())->render(); ?>
11+
<?php else: ?>
12+
<?php include labelBlockPath(); ?>
13+
<?php endif; ?>
14+
<?php endif; ?>
15+
16+
<?php if ($showField): ?>
17+
<?php foreach ((array) $options['children'] as $child): ?>
18+
<?= $child->render($options['choice_options'], true, true, false) ?>
19+
<?php endforeach; ?>
20+
21+
<?php include helpBlockPath(); ?>
22+
23+
<?php endif; ?>
24+
25+
26+
<?php include errorBlockPath(); ?>
27+
28+
<?php if ($showLabel && $showField): ?>
29+
<?php if ($options['wrapper'] !== false): ?>
30+
</div>
31+
<?php endif; ?>
32+
<?php endif; ?>

0 commit comments

Comments
 (0)