@@ -11,7 +11,7 @@ class FormBuilder extends IlluminateFormBuilder {
1111 *
1212 * @var array
1313 */
14- protected $ groupStack = array () ;
14+ protected $ groupStack = [] ;
1515
1616 /**
1717 * Open a new form group.
@@ -22,19 +22,23 @@ class FormBuilder extends IlluminateFormBuilder {
2222 * @param array $labelOptions
2323 * @return string
2424 */
25- public function openGroup ($ name , $ label = null , $ options = array () , $ labelOptions = array () )
25+ public function openGroup ($ name , $ label = null , $ options = [] , $ labelOptions = [] )
2626 {
2727 $ options = $ this ->appendClassToOptions ('form-group ' , $ options );
2828
2929 // Append the name of the group to the groupStack.
3030 $ this ->groupStack [] = $ name ;
3131
32- if ($ this ->hasErrors ($ name ))
33- {
34- // If the form element with the given name has any errors,
35- // apply the 'has-error' class to the group.
36- $ options = $ this ->appendClassToOptions ('has-error ' , $ options );
37- }
32+ // Check to see if error blocks are enabled
33+ if ($ this ->errorBlockEnabled ($ options ))
34+ {
35+ if ($ this ->hasErrors ($ name ))
36+ {
37+ // If the form element with the given name has any errors,
38+ // apply the 'has-error' class to the group.
39+ $ options = $ this ->appendClassToOptions ('has-error ' , $ options );
40+ }
41+ }
3842
3943 // If a label is given, we set it up here. Otherwise, we will just
4044 // set it to an empty string.
@@ -46,16 +50,21 @@ public function openGroup($name, $label = null, $options = array(), $labelOption
4650 /**
4751 * Close out the last opened form group.
4852 *
53+ * @param bool $helpBlock - determines whether the formatted field errors should be displayed
4954 * @return string
5055 */
51- public function closeGroup ()
56+ public function closeGroup ($ helpBlock = TRUE )
5257 {
5358 // Get the last added name from the groupStack and
5459 // remove it from the array.
5560 $ name = array_pop ($ this ->groupStack );
5661
57- // Get the formatted errors for this form group.
58- $ errors = $ this ->getFormattedErrors ($ name );
62+ // Check to see if we are to include the formatted help block
63+ if ($ helpBlock )
64+ {
65+ // Get the formatted errors for this form group.
66+ $ errors = $ this ->getFormattedErrors ($ name );
67+ }
5968
6069 // Append the errors to the group and close it out.
6170 return $ errors .'</div> ' ;
@@ -70,7 +79,7 @@ public function closeGroup()
7079 * @param array $options
7180 * @return string
7281 */
73- public function input ($ type , $ name , $ value = null , $ options = array () )
82+ public function input ($ type , $ name , $ value = null , $ options = [] )
7483 {
7584 // Don't add form-control for some input types (like submit, checkbox, radio)
7685 if (!in_array ($ type , ['submit ' , 'checkbox ' , 'radio ' , 'reset ' ])) {
@@ -91,7 +100,7 @@ public function input($type, $name, $value = null, $options = array())
91100 * @param array $options
92101 * @return string
93102 */
94- public function select ($ name , $ list = array () , $ selected = null , $ options = array () )
103+ public function select ($ name , $ list = [] , $ selected = null , $ options = [] )
95104 {
96105 $ options = $ this ->appendClassToOptions ('form-control ' , $ options );
97106
@@ -109,7 +118,7 @@ public function select($name, $list = array(), $selected = null, $options = arra
109118 * @param array $options
110119 * @return string
111120 */
112- public function plainInput ($ type , $ name , $ value = null , $ options = array () )
121+ public function plainInput ($ type , $ name , $ value = null , $ options = [] )
113122 {
114123 return parent ::input ($ type , $ name , $ value , $ options );
115124 }
@@ -123,7 +132,7 @@ public function plainInput($type, $name, $value = null, $options = array())
123132 * @param array $options
124133 * @return string
125134 */
126- public function plainSelect ($ name , $ list = array () , $ selected = null , $ options = array () )
135+ public function plainSelect ($ name , $ list = [] , $ selected = null , $ options = [] )
127136 {
128137 return parent ::select ($ name , $ list , $ selected , $ options );
129138 }
@@ -157,7 +166,7 @@ protected function checkable($type, $name, $value, $checked, $options)
157166 * @param array $options
158167 * @return string
159168 */
160- public function checkbox ($ name , $ value = 1 , $ label = null , $ checked = null , $ options = array () )
169+ public function checkbox ($ name , $ value = 1 , $ label = null , $ checked = null , $ options = [] )
161170 {
162171 $ checkable = parent ::checkbox ($ name , $ value , $ checked , $ options );
163172
@@ -174,7 +183,7 @@ public function checkbox($name, $value = 1, $label = null, $checked = null, $opt
174183 * @param array $options
175184 * @return string
176185 */
177- public function radio ($ name , $ value = null , $ label = null , $ checked = null , $ options = array () )
186+ public function radio ($ name , $ value = null , $ label = null , $ checked = null , $ options = [] )
178187 {
179188 $ checkable = parent ::radio ($ name , $ value , $ checked , $ options );
180189
@@ -191,7 +200,7 @@ public function radio($name, $value = null, $label = null, $checked = null, $opt
191200 * @param array $options
192201 * @return string
193202 */
194- public function inlineCheckbox ($ name , $ value = 1 , $ label = null , $ checked = null , $ options = array () )
203+ public function inlineCheckbox ($ name , $ value = 1 , $ label = null , $ checked = null , $ options = [] )
195204 {
196205 $ checkable = parent ::checkbox ($ name , $ value , $ checked , $ options );
197206
@@ -208,7 +217,7 @@ public function inlineCheckbox($name, $value = 1, $label = null, $checked = null
208217 * @param array $options
209218 * @return string
210219 */
211- public function inlineRadio ($ name , $ value = null , $ label = null , $ checked = null , $ options = array () )
220+ public function inlineRadio ($ name , $ value = null , $ label = null , $ checked = null , $ options = [] )
212221 {
213222 $ checkable = parent ::radio ($ name , $ value , $ checked , $ options );
214223
@@ -223,7 +232,7 @@ public function inlineRadio($name, $value = null, $label = null, $checked = null
223232 * @param array $options
224233 * @return string
225234 */
226- public function textarea ($ name , $ value = null , $ options = array () )
235+ public function textarea ($ name , $ value = null , $ options = [] )
227236 {
228237 $ options = $ this ->appendClassToOptions ('form-control ' , $ options );
229238
@@ -238,7 +247,7 @@ public function textarea($name, $value = null, $options = array())
238247 * @param array $options
239248 * @return string
240249 */
241- public function plainTextarea ($ name , $ value = null , $ options = array () )
250+ public function plainTextarea ($ name , $ value = null , $ options = [] )
242251 {
243252 return parent ::textarea ($ name , $ value , $ options );
244253 }
@@ -250,7 +259,7 @@ public function plainTextarea($name, $value = null, $options = array())
250259 * @param array $options
251260 * @return array
252261 */
253- private function appendClassToOptions ($ class , array $ options = array () )
262+ private function appendClassToOptions ($ class , array $ options = [] )
254263 {
255264 // If a 'class' is already specified, append the 'form-control'
256265 // class to it. Otherwise, set the 'class' to 'form-control'.
@@ -334,4 +343,24 @@ private function wrapInlineCheckable($label, $type, $checkable)
334343 return '<div class=" ' .$ type .'-inline"> ' .$ checkable .' ' .$ label .'</div> ' ;
335344 }
336345
346+ /**
347+ * errorBlockEnabled
348+ *
349+ * @param array $options
350+ *
351+ * @return bool
352+ * @author Vincent Sposato <Vincent.Sposato@gmail.com>
353+ * @version v1.0
354+ */
355+ private function errorBlockEnabled ( $ options = [ ] )
356+ {
357+ // Check to see if errorBlock key exists
358+ if ( array_key_exists ( "errorBlock " , $ options ) ) {
359+ // Return the value from the array
360+ return $ options [ "errorBlock " ];
361+ }
362+
363+ // Default to true if it does not exist
364+ return TRUE ;
365+ }
337366}
0 commit comments