Completed
Pull Request — master (#384)
by
unknown
04:10
created

FormField::hidden()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
ccs 0
cts 3
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Kris\LaravelFormBuilder\Fields;
4
5
use Kris\LaravelFormBuilder\Filters\Exception\FilterAlreadyBindedException;
6
use Kris\LaravelFormBuilder\Filters\FilterInterface;
7
use Kris\LaravelFormBuilder\Filters\FilterResolver;
8
use Kris\LaravelFormBuilder\Form;
9
use Kris\LaravelFormBuilder\FormHelper;
10
11
/**
12
 * Class FormField
13
 *
14
 * @package Kris\LaravelFormBuilder\Fields
15
 */
16
abstract class FormField
17
{
18
    /**
19
     * Name of the field.
20
     *
21
     * @var string
22
     */
23
    protected $name;
24
25
    /**
26
     * Type of the field.
27
     *
28
     * @var string
29
     */
30
    protected $type;
31
32
    /**
33
     * All options for the field.
34
     *
35
     * @var array
36
     */
37
    protected $options = [];
38
39
    /**
40
     * Is field rendered.
41
     *
42
     * @var bool
43
     */
44
    protected $rendered = false;
45
46
    /**
47
     * @var Form
48
     */
49
    protected $parent;
50
51
    /**
52
     * @var string
53
     */
54
    protected $template;
55
56
    /**
57
     * @var FormHelper
58
     */
59
    protected $formHelper;
60
61
    /**
62
     * Name of the property for value setting.
63
     *
64
     * @var string
65
     */
66
    protected $valueProperty = 'value';
67
68
    /**
69
     * Name of the property for default value.
70
     *
71
     * @var string
72
     */
73
    protected $defaultValueProperty = 'default_value';
74
75
    /**
76
     * Is default value set?
77
     *
78
     * @var bool|false
79
     */
80
    protected $hasDefault = false;
81
82
    /**
83
     * @var \Closure|null
84
     */
85
    protected $valueClosure = null;
86
87
    /**
88
     * Array of filters key(alias/name) => objects.
89
     *
90
     * @var array
91
     */
92
    protected $filters = [];
93
94
    /**
95
     * Raw/unfiltered field value.
96
     *
97
     * @var mixed $rawValues
98
     */
99
    protected $rawValue;
100
101
    /**
102
     * Override filters with same alias/name for field.
103
     *
104
     * @var bool
105
     */
106
    protected $filtersOverride = false;
107
108
    /**
109
     * @param string $name
110
     * @param string $type
111
     * @param Form $parent
112
     * @param array $options
113
     */
114 97
    public function __construct($name, $type, Form $parent, array $options = [])
115
    {
116 97
        $this->name = $name;
117 97
        $this->type = $type;
118 97
        $this->parent = $parent;
119 97
        $this->formHelper = $this->parent->getFormHelper();
120 97
        $this->setTemplate();
121 97
        $this->setDefaultOptions($options);
122 97
        $this->setupValue();
123 92
        $this->initFilters();
124 92
    }
125
126
127
    /**
128
     * Setup the value of the form field.
129
     *
130
     * @return void
131
     */
132 97
    protected function setupValue()
133
    {
134 97
        $value = $this->getOption($this->valueProperty);
135 97
        $isChild = $this->getOption('is_child');
136
137 97
        if ($value instanceof \Closure) {
138
            $this->valueClosure = $value;
139
        }
140
141 97
        if (($value === null || $value instanceof \Closure) && !$isChild) {
142 86
            $this->setValue($this->getModelValueAttribute($this->parent->getModel(), $this->name));
143 22
        } elseif (!$isChild) {
144 14
            $this->hasDefault = true;
145
        }
146 92
    }
147
148
    /**
149
     * Get the template, can be config variable or view path.
150
     *
151
     * @return string
152
     */
153
    abstract protected function getTemplate();
154
155
    /**
156
     * @return string
157
     */
158 34
    protected function getViewTemplate()
159
    {
160 34
        return $this->parent->getTemplatePrefix() . $this->getOption('template', $this->template);
161
    }
162
163
    /**
164
     * Render the field.
165
     *
166
     * @param array $options
167
     * @param bool  $showLabel
168
     * @param bool  $showField
169
     * @param bool  $showError
170
     * @return string
171
     */
172 34
    public function render(array $options = [], $showLabel = true, $showField = true, $showError = true)
173
    {
174 34
        $this->prepareOptions($options);
175 34
        $value = $this->getValue();
176 34
        $defaultValue = $this->getDefaultValue();
177
178 34
        if ($showField) {
179 34
            $this->rendered = true;
180
        }
181
182
        // Override default value with value
183 34
        if (!$this->isValidValue($value) && $this->isValidValue($defaultValue)) {
184
            $this->setOption($this->valueProperty, $defaultValue);
185
        }
186
187 34
        if (!$this->needsLabel()) {
188 10
            $showLabel = false;
189
        }
190
191 34
        if ($showError) {
192 33
            $showError = $this->parent->haveErrorsEnabled();
193
        }
194
195 34
        $data = $this->getRenderData();
196
197 34
        return $this->formHelper->getView()->make(
198 34
            $this->getViewTemplate(),
199
            $data + [
200 34
                'name' => $this->name,
201 34
                'nameKey' => $this->getNameKey(),
202 34
                'type' => $this->type,
203 34
                'options' => $this->options,
204 34
                'showLabel' => $showLabel,
205 34
                'showField' => $showField,
206 34
                'showError' => $showError
207
            ]
208 34
        )->render();
209
    }
210
211
    /**
212
     * Return the extra render data for this form field, passed into the field's template directly.
213
     *
214
     * @return array
215
     */
216 34
    protected function getRenderData() {
217 34
        return [];
218
    }
219
220
    /**
221
     * Get the attribute value from the model by name.
222
     *
223
     * @param mixed $model
224
     * @param string $name
225
     * @return mixed
226
     */
227 88
    protected function getModelValueAttribute($model, $name)
228
    {
229 88
        $transformedName = $this->transformKey($name);
230 88
        if (is_string($model)) {
231
            return $model;
232 88
        } elseif (is_object($model)) {
233 3
            return object_get($model, $transformedName);
234 88
        } elseif (is_array($model)) {
235 87
            return array_get($model, $transformedName);
236
        }
237 5
    }
238
239
    /**
240
     * Transform array like syntax to dot syntax.
241
     *
242
     * @param string $key
243
     * @return mixed
244
     */
245 97
    protected function transformKey($key)
246
    {
247 97
        return $this->formHelper->transformToDotSyntax($key);
248
    }
249
250
    /**
251
     * Prepare options for rendering.
252
     *
253
     * @param array $options
254
     * @return array
255
     */
256 97
    protected function prepareOptions(array $options = [])
257
    {
258 97
        $helper = $this->formHelper;
259 97
        $rulesParser = $helper->createRulesParser($this);
260 97
        $rules = $this->getOption('rules');
261 97
        $parsedRules = $rules ? $rulesParser->parse($rules) : [];
262
263 97
        $this->options = $helper->mergeOptions($this->options, $options);
264
265 97
        foreach (['attr', 'label_attr', 'wrapper'] as $appendable) {
266
            // Append values to the 'class' attribute
267 97
            if ($this->getOption("{$appendable}.class_append")) {
268
                // Combine the current class attribute with the appends
269 3
                $append = $this->getOption("{$appendable}.class_append");
270 3
                $classAttribute = $this->getOption("{$appendable}.class", '').' '.$append;
271 3
                $this->setOption("{$appendable}.class", $classAttribute);
272
273
                // Then remove the class_append option to prevent it from showing up as an attribute in the HTML
274 97
                $this->setOption("{$appendable}.class_append", null);
275
            }
276
        }
277
278 97
        if ($this->getOption('attr.multiple') && !$this->getOption('tmp.multipleBracesSet')) {
279 2
            $this->name = $this->name.'[]';
280 2
            $this->setOption('tmp.multipleBracesSet', true);
281
        }
282
283 97
        if ($this->parent->haveErrorsEnabled()) {
284 97
            $this->addErrorClass();
285
        }
286
287 97
        if ($this->getOption('required') === true || isset($parsedRules['required'])) {
288 4
            $lblClass = $this->getOption('label_attr.class', '');
289 4
            $requiredClass = $helper->getConfig('defaults.required_class', 'required');
290
291 4
            if (! str_contains($lblClass, $requiredClass)) {
292 4
                $lblClass .= ' '.$requiredClass;
293 4
                $this->setOption('label_attr.class', $lblClass);
294
            }
295
296 4
            if ($this->parent->clientValidationEnabled()) {
297 3
                $this->setOption('attr.required', 'required');
298
            }
299
        }
300
301 97
        if ($this->parent->clientValidationEnabled() && $parsedRules) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $parsedRules of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
302 1
            $attrs = $this->getOption('attr') + $parsedRules;
303 1
            $this->setOption('attr', $attrs);
304
        }
305
306 97
        $this->setOption('wrapperAttrs', $helper->prepareAttributes($this->getOption('wrapper')));
307 97
        $this->setOption('errorAttrs', $helper->prepareAttributes($this->getOption('errors')));
308
309 97
        if ($this->getOption('help_block.text')) {
310 1
            $this->setOption(
311 1
                'help_block.helpBlockAttrs',
312 1
                $helper->prepareAttributes($this->getOption('help_block.attr'))
313
            );
314
        }
315
316 97
        return $this->options;
317
    }
318
319
    /**
320
     * Get name of the field.
321
     *
322
     * @return string
323
     */
324 39
    public function getName()
325
    {
326 39
        return $this->name;
327
    }
328
329
    /**
330
     * Set name of the field.
331
     *
332
     * @param string $name
333
     * @return $this
334
     */
335 12
    public function setName($name)
336
    {
337 12
        $this->name = $name;
338
339 12
        return $this;
340
    }
341
342
    /**
343
     * Get dot notation key for fields.
344
     *
345
     * @return string
346
     **/
347 53
    public function getNameKey()
348
    {
349 53
        return $this->transformKey($this->name);
350
    }
351
352
    /**
353
     * Get field options.
354
     *
355
     * @return array
356
     */
357 12
    public function getOptions()
358
    {
359 12
        return $this->options;
360
    }
361
362
    /**
363
     * Get single option from options array. Can be used with dot notation ('attr.class').
364
     *
365
     * @param string $option
366
     * @param mixed|null $default
367
     * @return mixed
368
     */
369 97
    public function getOption($option, $default = null)
370
    {
371 97
        return array_get($this->options, $option, $default);
372
    }
373
374
    /**
375
     * Set field options.
376
     *
377
     * @param array $options
378
     * @return $this
379
     */
380 12
    public function setOptions($options)
381
    {
382 12
        $this->options = $this->prepareOptions($options);
383
384 12
        return $this;
385
    }
386
387
    /**
388
     * Set single option on the field.
389
     *
390
     * @param string $name
391
     * @param mixed $value
392
     * @return $this
393
     */
394 97
    public function setOption($name, $value)
395
    {
396 97
        array_set($this->options, $name, $value);
397
398 97
        return $this;
399
    }
400
401
    /**
402
     * Get the type of the field.
403
     *
404
     * @return string
405
     */
406 62
    public function getType()
407
    {
408 62
        return $this->type;
409
    }
410
411
    /**
412
     * Set type of the field.
413
     *
414
     * @param mixed $type
415
     * @return $this
416
     */
417 1
    public function setType($type)
418
    {
419 1
        if ($this->formHelper->getFieldType($type)) {
420 1
            $this->type = $type;
421
        }
422
423 1
        return $this;
424
    }
425
426
    /**
427
     * @return Form
428
     */
429 97
    public function getParent()
430
    {
431 97
        return $this->parent;
432
    }
433
434
    /**
435
     * Check if the field is rendered.
436
     *
437
     * @return bool
438
     */
439 4
    public function isRendered()
440
    {
441 4
        return $this->rendered;
442
    }
443
444
    /**
445
     * Default options for field.
446
     *
447
     * @return array
448
     */
449 75
    protected function getDefaults()
450
    {
451 75
        return [];
452
    }
453
454
    /**
455
     * Defaults used across all fields.
456
     *
457
     * @return array
458
     */
459 97
    private function allDefaults()
460
    {
461
        return [
462 97
            'wrapper' => ['class' => $this->formHelper->getConfig('defaults.wrapper_class')],
463 97
            'attr' => ['class' => $this->formHelper->getConfig('defaults.field_class')],
464 97
            'help_block' => ['text' => null, 'tag' => 'p', 'attr' => [
465 97
                'class' => $this->formHelper->getConfig('defaults.help_block_class')
466
            ]],
467
            'value' => null,
468
            'default_value' => null,
469
            'label' => null,
470
            'label_show' => true,
471
            'is_child' => false,
472 97
            'label_attr' => ['class' => $this->formHelper->getConfig('defaults.label_class')],
473 97
            'errors' => ['class' => $this->formHelper->getConfig('defaults.error_class')],
474
            'rules' => [],
475
            'error_messages' => []
476
        ];
477
    }
478
479
    /**
480
     * Get real name of the field without form namespace.
481
     *
482
     * @return string
483
     */
484 96
    public function getRealName()
485
    {
486 96
        return $this->getOption('real_name', $this->name);
487
    }
488
489
    /**
490
     * @param $value
491
     * @return $this
492
     */
493 90
    public function setValue($value)
494
    {
495 90
        if ($this->hasDefault) {
496 1
            return $this;
497
        }
498
499 90
        $closure = $this->valueClosure;
500
501 90
        if ($closure instanceof \Closure) {
502
            $value = $closure($value ?: null);
503
        }
504
505 90
        if (!$this->isValidValue($value)) {
506 87
            $value = $this->getOption($this->defaultValueProperty);
507
        }
508
509 90
        $this->options[$this->valueProperty] = $value;
510
511 90
        return $this;
512
    }
513
514
    /**
515
     * Set the template property on the object.
516
     *
517
     * @return void
518
     */
519 97
    private function setTemplate()
520
    {
521 97
        $this->template = $this->formHelper->getConfig($this->getTemplate(), $this->getTemplate());
522 97
    }
523
524
    /**
525
     * Add error class to wrapper if validation errors exist.
526
     *
527
     * @return void
528
     */
529 97
    protected function addErrorClass()
530
    {
531 97
        $errors = $this->parent->getRequest()->session()->get('errors');
532
533 97
        if ($errors && $errors->has($this->getNameKey())) {
534
            $errorClass = $this->formHelper->getConfig('defaults.wrapper_error_class');
535
            $wrapperClass = $this->getOption('wrapper.class');
536
537
            if ($this->getOption('wrapper') && !str_contains($wrapperClass, $errorClass)) {
538
                $wrapperClass .= ' ' . $errorClass;
539
                $this->setOption('wrapper.class', $wrapperClass);
540
            }
541
        }
542 97
    }
543
544
    /**
545
     * Merge all defaults with field specific defaults and set template if passed.
546
     *
547
     * @param array $options
548
     */
549 97
    protected function setDefaultOptions(array $options = [])
550
    {
551 97
        $this->options = $this->formHelper->mergeOptions($this->allDefaults(), $this->getDefaults());
552 97
        $this->options = $this->prepareOptions($options);
553
554 97
        $defaults = $this->setDefaultClasses($options);
555 97
        $this->options = $this->formHelper->mergeOptions($this->options, $defaults);
556
557 97
        $this->setupLabel();
558 97
    }
559
560
    /**
561
     * Creates default wrapper classes for the form element.
562
     *
563
     * @param array $options
564
     * @return array
565
     */
566 97
    protected function setDefaultClasses(array $options = [])
567
    {
568 97
        $wrapper_class = $this->formHelper->getConfig('defaults.' . $this->type . '.wrapper_class', '');
569 97
        $label_class = $this->formHelper->getConfig('defaults.' . $this->type . '.label_class', '');
570 97
        $field_class = $this->formHelper->getConfig('defaults.' . $this->type . '.field_class', '');
571
572 97
        $defaults = [];
573 97
        if ($wrapper_class && !array_get($options, 'wrapper.class')) {
574
            $defaults['wrapper']['class'] = $wrapper_class;
575
        }
576 97
        if ($label_class && !array_get($options, 'label_attr.class')) {
577
            $defaults['label_attr']['class'] = $label_class;
578
        }
579 97
        if ($field_class && !array_get($options, 'attr.class')) {
580 1
            $defaults['attr']['class'] = $field_class;
581
        }
582 97
        return $defaults;
583
    }
584
585
    /**
586
     * Setup the label for the form field.
587
     *
588
     * @return void
589
     */
590 97
    protected function setupLabel()
591
    {
592 97
        if ($this->getOption('label') !== null) {
593 23
            return;
594
        }
595
596 95
        if ($langName = $this->parent->getLanguageName()) {
597 4
            $label = sprintf('%s.%s', $langName, $this->getRealName());
598
        } else {
599 92
            $label = $this->getRealName();
600
        }
601
602 95
        $this->setOption('label', $this->formHelper->formatLabel($label));
603 95
    }
604
605
    /**
606
     * Check if fields needs label.
607
     *
608
     * @return bool
609
     */
610 34
    protected function needsLabel()
611
    {
612
        // If field is <select> and child of choice, we don't need label for it
613 34
        $isChildSelect = $this->type == 'select' && $this->getOption('is_child') === true;
614
615 34
        if ($this->type == 'hidden' || $isChildSelect) {
616 10
            return false;
617
        }
618
619 30
        return true;
620
    }
621
622
    /**
623
     * Disable field.
624
     *
625
     * @return $this
626
     */
627 1
    public function disable()
628
    {
629 1
        $this->setOption('attr.disabled', 'disabled');
630
631 1
        return $this;
632
    }
633
634
    /**
635
     * Enable field.
636
     *
637
     * @return $this
638
     */
639 1
    public function enable()
640
    {
641 1
        array_forget($this->options, 'attr.disabled');
642
643 1
        return $this;
644
    }
645
646
    /**
647
     * Hidden field.
648
     *
649
     * @return $this
650
     */
651
    public function hidden()
652
    {
653
        $this->setOption('attr.style', 'display:none;');
654
655
        return $this;
656
    }
657
658
    /**
659
     * Get validation rules for a field if any with label for attributes.
660
     *
661
     * @return array|null
662
     */
663 9
    public function getValidationRules()
664
    {
665 9
        $rules = $this->getOption('rules', []);
666 9
        $name = $this->getNameKey();
667 9
        $messages = $this->getOption('error_messages', []);
668 9
        $formName = $this->formHelper->transformToDotSyntax($this->parent->getName());
669
670 9
        if ($messages && $formName) {
671 1
            $newMessages = [];
672 1
            foreach ($messages as $messageKey => $message) {
673 1
                $messageKey = sprintf('%s.%s', $formName, $messageKey);
674 1
                $newMessages[$messageKey] = $message;
675
            }
676 1
            $messages = $newMessages;
677
        }
678
679 9
        if (!$rules) {
680 2
            return [];
681
        }
682
683
        return [
684 8
            'rules' => [$name => $rules],
685 8
            'attributes' => [$name => $this->getOption('label')],
686 8
            'error_messages' => $messages
687
        ];
688
    }
689
690
    /**
691
     * Get this field's attributes, probably just one.
692
     *
693
     * @return array
694
     */
695 3
    public function getAllAttributes()
696
    {
697 3
        return [$this->getNameKey()];
698
    }
699
700
    /**
701
     * Get value property.
702
     *
703
     * @param mixed|null $default
704
     * @return mixed
705
     */
706 37
    public function getValue($default = null)
707
    {
708 37
        return $this->getOption($this->valueProperty, $default);
709
    }
710
711
    /**
712
     * Get default value property.
713
     *
714
     * @param mixed|null $default
715
     * @return mixed
716
     */
717 34
    public function getDefaultValue($default = null)
718
    {
719 34
        return $this->getOption($this->defaultValueProperty, $default);
720
    }
721
722
    /**
723
     * Check if provided value is valid for this type.
724
     *
725
     * @return bool
726
     */
727 92
    protected function isValidValue($value)
728
    {
729 92
        return $value !== null;
730
    }
731
732
    /**
733
     * Method initFilters used to initialize filters
734
     * from field options and bind it to the same.
735
     *
736
     * @return $this
737
     */
738 92
    protected function initFilters()
739
    {
740
        // If override status is set in field options to true
741
        // we will change filtersOverride property value to true
742
        // so we can override existing filters with registered
743
        // alias/name in addFilter method.
744 92
        $overrideStatus = $this->getOption('filters_override', false);
745 92
        if ($overrideStatus) {
746 2
            $this->setFiltersOverride(true);
747
        }
748
749
        // Get filters and bind it to field.
750 92
        $filters = $this->getOption('filters', []);
751 92
        foreach ($filters as $filter) {
752 8
            $this->addFilter($filter);
753
        }
754
755 92
        return $this;
756
    }
757
758
    /**
759
     * Method setFilters used to set filters to current filters property.
760
     *
761
     * @param  array $filters
762
     *
763
     * @return \Kris\LaravelFormBuilder\Fields\FormField
764
     */
765
    public function setFilters(array $filters)
766
    {
767
        $this->clearFilters();
768
        foreach ($filters as $filter) {
769
            $this->addFilter($filter);
770
        }
771
772
        return $this;
773
    }
774
775
    /**
776
     * Method getFilters returns array of binded filters
777
     * if there are any binded. Otherwise empty array.
778
     *
779
     * @return array
780
     */
781 23
    public function getFilters()
782
    {
783 23
        return $this->filters;
784
    }
785
786
    /**
787
     * @param  string|FilterInterface $filter
788
     *
789
     * @return \Kris\LaravelFormBuilder\Fields\FormField
790
     *
791
     * @throws FilterAlreadyBindedException
792
     */
793 8
    public function addFilter($filter)
794
    {
795
        // Resolve filter object from string/object or throw Ex.
796 8
        $filterObj = FilterResolver::instance($filter);
797
798
        // If filtersOverride is allowed we will override filter
799
        // with same alias/name if there is one with new resolved filter.
800 8
        if ($this->getFiltersOverride()) {
801 1
            if ($key = array_search($filterObj->getName(), $this->getFilters())) {
802
                $this->filters[$key] = $filterObj;
803
            } else {
804 1
                $this->filters[$filterObj->getName()] = $filterObj;
805
            }
806
        } else {
807
            // If filtersOverride is disabled and we found
808
            // equal alias defined we will throw Ex.
809 7
            if (array_key_exists($filterObj->getName(), $this->getFilters())) {
810 1
                $ex = new FilterAlreadyBindedException($filterObj->getName(), $this->getName());
811 1
                throw $ex;
812
            }
813
814
            // Filter with resolvedFilter alias/name doesn't exist
815
            // so we will bind it as new one to field.
816 7
            $this->filters[$filterObj->getName()] = $filterObj;
817
        }
818
819 8
        return $this;
820
    }
821
822
    /**
823
     * Method removeFilter used to remove filter by provided alias/name.
824
     *
825
     * @param  string $name
826
     *
827
     * @return \Kris\LaravelFormBuilder\Fields\FormField
828
     */
829 1
    public function removeFilter($name)
830
    {
831 1
        $filters = $this->getFilters();
832 1
        if (array_key_exists($name, $filters)) {
833 1
            unset($filters[$name]);
834 1
            $this->filters = $filters;
835
        }
836
837 1
        return $this;
838
    }
839
840
    /**
841
     * Method removeFilters used to remove filters by provided aliases/names.
842
     *
843
     * @param  array $filterNames
844
     *
845
     * @return \Kris\LaravelFormBuilder\Fields\FormField
846
     */
847 1
    public function removeFilters(array $filterNames)
848
    {
849 1
        $filters = $this->getFilters();
850 1
        foreach ($filterNames as $filterName) {
851 1
            if (array_key_exists($filterName, $filters)) {
852 1
                unset($filters[$filterName]);
853 1
                $this->filters = $filters;
854
            }
855
        }
856
857 1
        return $this;
858
    }
859
860
    /**
861
     * Method clearFilters used to empty current filters property.
862
     *
863
     * @return \Kris\LaravelFormBuilder\Fields\FormField
864
     */
865 1
    public function clearFilters()
866
    {
867 1
        $this->filters = [];
868 1
        return $this;
869
    }
870
871
    /**
872
     * Method used to set FiltersOverride status to provided value.
873
     *
874
     * @param $status
875
     *
876
     * @return \Kris\LaravelFormBuilder\Fields\FormField
877
     */
878 2
    public function setFiltersOverride($status)
879
    {
880 2
        $this->filtersOverride = $status;
881 2
        return $this;
882
    }
883
884
    /**
885
     * @return bool
886
     */
887 9
    public function getFiltersOverride()
888
    {
889 9
        return $this->filtersOverride;
890
    }
891
892
    /**
893
     * Method used to set Unfiltered/Unmutated field value.
894
     * Method is called before field value mutating starts - request value filtering.
895
     *
896
     * @param mixed $value
897
     *
898
     * @return \Kris\LaravelFormBuilder\Fields\FormField
899
     */
900 1
    public function setRawValue($value)
901
    {
902 1
        $this->rawValue = $value;
903 1
        return $this;
904
    }
905
906
    /**
907
     * Returns unfiltered raw value of field.
908
     *
909
     * @return mixed
910
     */
911
    public function getRawValue()
912
    {
913
        return $this->rawValue;
914
    }
915
}
916