Completed
Pull Request — master (#379)
by
unknown
04:34
created

FormField::prepareOptions()   F

Complexity

Conditions 14
Paths 720

Size

Total Lines 64
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 36
CRAP Score 14

Importance

Changes 0
Metric Value
cc 14
eloc 36
nc 720
nop 1
dl 0
loc 64
ccs 36
cts 36
cp 1
crap 14
rs 3.125
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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