forked from AsgardCms/Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmacros.php
More file actions
148 lines (128 loc) · 5.17 KB
/
macros.php
File metadata and controls
148 lines (128 loc) · 5.17 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/*
|--------------------------------------------------------------------------
| Translatable fields
|--------------------------------------------------------------------------
*/
/**
* Add an input field
* @param string $name The field name
* @param string $title The field title
* @param object $errors The laravel errors object
* @param string $lang the language of the field
* @param null|object $object The entity of the field
*/
Form::macro('i18nInput', function ($name, $title, $errors, $lang, $object = null) {
$string = "<div class='form-group " . ($errors->has($lang . '.' . $name) ? ' has-error' : '') . "'>";
$string .= Form::label("{$lang}[{$name}]", $title);
if (is_object($object)) {
$currentData = $object->hasTranslation($lang) ? $object->translate($lang)->{$name} : '';
} else {
$currentData = '';
}
$string .= Form::text("{$lang}[{$name}]", Input::old("{$lang}[{$name}]", $currentData),
['class' => "form-control", 'placeholder' => $title]);
$string .= $errors->first("{$lang}.{$name}", '<span class="help-block">:message</span>');
$string .= "</div>";
return $string;
});
/**
* Add a textarea
* @param string $name The field name
* @param string $title The field title
* @param object $errors The laravel errors object
* @param string $lang the language of the field
* @param null|object $object The entity of the field
*/
Form::macro('i18nTextarea', function ($name, $title, $errors, $lang, $object = null) {
$string = "<div class='form-group " . ($errors->has($lang . '.' . $name) ? ' has-error' : '') . "'>";
$string .= Form::label("{$lang}[{$name}]", $title);
if (is_object($object)) {
$currentData = $object->hasTranslation($lang) ? $object->translate($lang)->{$name} : '';
} else {
$currentData = '';
}
$oldInput = Input::old("{$lang}.{$name}", $currentData);
$string .= "<textarea class='ckeditor' name='{$lang}[$name]' rows='10' cols='80'>{$oldInput}</textarea>";
$string .= $errors->first("{$lang}.{$name}", '<span class="help-block">:message</span>');
$string .= "</div>";
return $string;
});
/**
* Add a checkbox input field
* @param string $name The field name
* @param string $title The field title
* @param object $errors The laravel errors object
* @param string $lang the language of the field
* @param null|object $object The entity of the field
*/
Form::macro('i18nCheckbox', function($name, $title, $errors, $lang, $object = null)
{
$string = "<div class='checkbox" . ($errors->has($lang . '.' . $name) ? ' has-error' : '') . "'>";
$string .= "<label for='{$lang}[{$name}]'>";
$string .= "<input id='{$lang}[{$name}]' name='{$lang}[{$name}]' type='checkbox' class='flat-blue'";
if (is_object($object)) {
$currentData = $object->hasTranslation($lang) ? (bool) $object->translate($lang)->{$name} : '';
} else {
$currentData = false;
}
$oldInput = Input::old("{$lang}.$name", $currentData) ? 'checked' : '';
$string .= "value='1' {$oldInput}>";
$string .= $title;
$string .= $errors->first($name, '<span class="help-block">:message</span>');
$string .= "</label>";
$string .= "</div>";
return $string;
});
/*
|--------------------------------------------------------------------------
| Standard fields
|--------------------------------------------------------------------------
*/
/**
* Add an input field
* @param string $name The field name
* @param string $title The field title
* @param object $errors The laravel errors object
* @param null|object $object The entity of the field
*/
Form::macro('normalInput', function ($name, $title, $errors, $object = null) {
$string = "<div class='form-group " . ($errors->has($name) ? ' has-error' : '') . "'>";
$string .= Form::label($name, $title);
if (is_object($object)) {
$currentData = $object->{$name} ?: '';
} else {
$currentData = '';
}
$string .= Form::text($name, Input::old($name, $currentData),
['class' => "form-control", 'placeholder' => $title]);
$string .= $errors->first($name, '<span class="help-block">:message</span>');
$string .= "</div>";
return $string;
});
/**
* Add a checkbox input field
* @param string $name The field name
* @param string $title The field title
* @param object $errors The laravel errors object
* @param null|object $object The entity of the field
*/
Form::macro('normalCheckbox', function($name, $title, $errors, $object = null)
{
$string = "<div class='checkbox" . ($errors->has($name) ? ' has-error' : '') . "'>";
$string .= "<input type='hidden' value='0' name='{$name}'/>";
$string .= "<label for='$name'>";
$string .= "<input id='$name' name='$name' type='checkbox' class='flat-blue'";
if (is_object($object)) {
$currentData = isset($object->$name) && (bool) $object->$name ? 'checked' : '';
} else {
$currentData = false;
}
$oldInput = Input::old($name, $currentData) ? 'checked' : '';
$string .= "value='1' {$oldInput}>";
$string .= $title;
$string .= $errors->first($name, '<span class="help-block">:message</span>');
$string .= "</label>";
$string .= "</div>";
return $string;
});