Completed
Pull Request — master (#534)
by Damian
34:19
created

UserFormsCheckboxSetField::getSourceAsArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/**
4
 * @package userforms
5
 */
6
class UserFormsCheckboxSetField extends CheckboxSetField
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
9
    /**
10
     * jQuery validate requires that the value of the option does not contain
11
     * the actual value of the input.
12
     *
13
     * @return ArrayList
14
     */
15
    public function getOptions()
16
    {
17
        $options = parent::getOptions();
18
19
        foreach ($options as $option) {
20
            $option->Name = "{$this->name}[]";
21
        }
22
23
        return $options;
24
    }
25
26
    /**
27
     * @inheritdoc
28
     *
29
     * @param Validator $validator
30
     *
31
     * @return bool
32
     */
33
    public function validate($validator)
34
    {
35
        // get the previous values (could contain comma-delimited list)
36
37
        $previous = $value = $this->Value();
38
39
        if (is_string($value) && strstr($value, ",")) {
40
            $value = explode(",", $value);
41
        }
42
43
        // set the value as an array for parent validation
44
45
        $this->setValue($value);
46
47
        $validated = parent::validate($validator);
48
49
        // restore previous value after validation
50
51
        $this->setValue($previous);
52
53
        return $validated;
54
    }
55
}
56