Completed
Push — master ( 83e5ff...b2c8b7 )
by Kristijan
04:29
created

FormField::setOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
ccs 3
cts 3
cp 1
crap 1
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
     * Get validation rules for a field if any with label for attributes.
648
     *
649
     * @return array|null
650
     */
651 9
    public function getValidationRules()
652
    {
653 9
        $rules = $this->getOption('rules', []);
654 9
        $name = $this->getNameKey();
655 9
        $messages = $this->getOption('error_messages', []);
656 9
        $formName = $this->formHelper->transformToDotSyntax($this->parent->getName());
657
658 9
        if ($messages && $formName) {
659 1
            $newMessages = [];
660 1
            foreach ($messages as $messageKey => $message) {
661 1
                $messageKey = sprintf('%s.%s', $formName, $messageKey);
662 1
                $newMessages[$messageKey] = $message;
663
            }
664 1
            $messages = $newMessages;
665
        }
666
667 9
        if (!$rules) {
668 2
            return [];
669
        }
670
671 8
        if (is_array($rules)) {
672 2
            $rules = array_map(function($rule) {
673 2
                if ($rule instanceof \Closure) {
674
                    return $rule($name);
0 ignored issues
show
Bug introduced by
The variable $name does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
675
                }
676
677 2
                return $rule;
678 2
            }, $rules);
679
        }
680
681
        return [
682 8
            'rules' => [$name => $rules],
683 8
            'attributes' => [$name => $this->getOption('label')],
684 8
            'error_messages' => $messages
685
        ];
686
    }
687
688
    /**
689
     * Get this field's attributes, probably just one.
690
     *
691
     * @return array
692
     */
693 3
    public function getAllAttributes()
694
    {
695 3
        return [$this->getNameKey()];
696
    }
697
698
    /**
699
     * Get value property.
700
     *
701
     * @param mixed|null $default
702
     * @return mixed
703
     */
704 37
    public function getValue($default = null)
705
    {
706 37
        return $this->getOption($this->valueProperty, $default);
707
    }
708
709
    /**
710
     * Get default value property.
711
     *
712
     * @param mixed|null $default
713
     * @return mixed
714
     */
715 34
    public function getDefaultValue($default = null)
716
    {
717 34
        return $this->getOption($this->defaultValueProperty, $default);
718
    }
719
720
    /**
721
     * Check if provided value is valid for this type.
722
     *
723
     * @return bool
724
     */
725 92
    protected function isValidValue($value)
726
    {
727 92
        return $value !== null;
728
    }
729
730
    /**
731
     * Method initFilters used to initialize filters
732
     * from field options and bind it to the same.
733
     *
734
     * @return $this
735
     */
736 92
    protected function initFilters()
737
    {
738
        // If override status is set in field options to true
739
        // we will change filtersOverride property value to true
740
        // so we can override existing filters with registered
741
        // alias/name in addFilter method.
742 92
        $overrideStatus = $this->getOption('filters_override', false);
743 92
        if ($overrideStatus) {
744 2
            $this->setFiltersOverride(true);
745
        }
746
747
        // Get filters and bind it to field.
748 92
        $filters = $this->getOption('filters', []);
749 92
        foreach ($filters as $filter) {
750 8
            $this->addFilter($filter);
751
        }
752
753 92
        return $this;
754
    }
755
756
    /**
757
     * Method setFilters used to set filters to current filters property.
758
     *
759
     * @param  array $filters
760
     *
761
     * @return \Kris\LaravelFormBuilder\Fields\FormField
762
     */
763
    public function setFilters(array $filters)
764
    {
765
        $this->clearFilters();
766
        foreach ($filters as $filter) {
767
            $this->addFilter($filter);
768
        }
769
770
        return $this;
771
    }
772
773
    /**
774
     * Method getFilters returns array of binded filters
775
     * if there are any binded. Otherwise empty array.
776
     *
777
     * @return array
778
     */
779 23
    public function getFilters()
780
    {
781 23
        return $this->filters;
782
    }
783
784
    /**
785
     * @param  string|FilterInterface $filter
786
     *
787
     * @return \Kris\LaravelFormBuilder\Fields\FormField
788
     *
789
     * @throws FilterAlreadyBindedException
790
     */
791 8
    public function addFilter($filter)
792
    {
793
        // Resolve filter object from string/object or throw Ex.
794 8
        $filterObj = FilterResolver::instance($filter);
795
796
        // If filtersOverride is allowed we will override filter
797
        // with same alias/name if there is one with new resolved filter.
798 8
        if ($this->getFiltersOverride()) {
799 1
            if ($key = array_search($filterObj->getName(), $this->getFilters())) {
800
                $this->filters[$key] = $filterObj;
801
            } else {
802 1
                $this->filters[$filterObj->getName()] = $filterObj;
803
            }
804
        } else {
805
            // If filtersOverride is disabled and we found
806
            // equal alias defined we will throw Ex.
807 7
            if (array_key_exists($filterObj->getName(), $this->getFilters())) {
808 1
                $ex = new FilterAlreadyBindedException($filterObj->getName(), $this->getName());
809 1
                throw $ex;
810
            }
811
812
            // Filter with resolvedFilter alias/name doesn't exist
813
            // so we will bind it as new one to field.
814 7
            $this->filters[$filterObj->getName()] = $filterObj;
815
        }
816
817 8
        return $this;
818
    }
819
820
    /**
821
     * Method removeFilter used to remove filter by provided alias/name.
822
     *
823
     * @param  string $name
824
     *
825
     * @return \Kris\LaravelFormBuilder\Fields\FormField
826
     */
827 1
    public function removeFilter($name)
828
    {
829 1
        $filters = $this->getFilters();
830 1
        if (array_key_exists($name, $filters)) {
831 1
            unset($filters[$name]);
832 1
            $this->filters = $filters;
833
        }
834
835 1
        return $this;
836
    }
837
838
    /**
839
     * Method removeFilters used to remove filters by provided aliases/names.
840
     *
841
     * @param  array $filterNames
842
     *
843
     * @return \Kris\LaravelFormBuilder\Fields\FormField
844
     */
845 1
    public function removeFilters(array $filterNames)
846
    {
847 1
        $filters = $this->getFilters();
848 1
        foreach ($filterNames as $filterName) {
849 1
            if (array_key_exists($filterName, $filters)) {
850 1
                unset($filters[$filterName]);
851 1
                $this->filters = $filters;
852
            }
853
        }
854
855 1
        return $this;
856
    }
857
858
    /**
859
     * Method clearFilters used to empty current filters property.
860
     *
861
     * @return \Kris\LaravelFormBuilder\Fields\FormField
862
     */
863 1
    public function clearFilters()
864
    {
865 1
        $this->filters = [];
866 1
        return $this;
867
    }
868
869
    /**
870
     * Method used to set FiltersOverride status to provided value.
871
     *
872
     * @param $status
873
     *
874
     * @return \Kris\LaravelFormBuilder\Fields\FormField
875
     */
876 2
    public function setFiltersOverride($status)
877
    {
878 2
        $this->filtersOverride = $status;
879 2
        return $this;
880
    }
881
882
    /**
883
     * @return bool
884
     */
885 9
    public function getFiltersOverride()
886
    {
887 9
        return $this->filtersOverride;
888
    }
889
890
    /**
891
     * Method used to set Unfiltered/Unmutated field value.
892
     * Method is called before field value mutating starts - request value filtering.
893
     *
894
     * @param mixed $value
895
     *
896
     * @return \Kris\LaravelFormBuilder\Fields\FormField
897
     */
898 1
    public function setRawValue($value)
899
    {
900 1
        $this->rawValue = $value;
901 1
        return $this;
902
    }
903
904
    /**
905
     * Returns unfiltered raw value of field.
906
     *
907
     * @return mixed
908
     */
909
    public function getRawValue()
910
    {
911
        return $this->rawValue;
912
    }
913
}
914