KnockoutDropdownField::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 4
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace AntonyThorpe\Knockout;
4
5
require_once('Common.php');
6
use SilverStripe\Forms\DropdownField;
7
8
/**
9
 * KnockoutDropdownField
10
 *
11
 * Creates a dropdown field with an additional data-bind attribute that
12
 * links to a Knockout observable
13
 */
14
class KnockoutDropdownField extends DropdownField
15
{
16
    use \AntonyThorpe\Knockout\Common;
17
18
    /**
19
     * bindingType
20
     *
21
     * @var string a data-bind attribute key
22
     * @example   <select data-bind="value: spaceship, etc. ".  Note: the options elements are supplied by Silverstripe
23
     */
24
    protected $bindingType = 'value';
25
26
    /**
27
     * casting of variables for security purposes
28
     *
29
     * @see http://docs.silverstripe.org/en/3.1/developer_guides/security/secure_coding/
30
     */
31
    protected $casting = array(
32
        "Observable" => "Varchar",
33
        "BindingType" => "Varchar",
34
        "OtherBindings" => "Varchar",
35
        "HasFocus" => "Boolean"
36
    );
37
38
    /**
39
     * Constructor
40
     *
41
     * @param string $name The field name
42
     * @param string $title The field title
43
     * @param array $source An map of the dropdown items
44
     * @param string $value The current value
45
     */
46
    public function __construct($name, $title = null, $source = array(), $value = '')
47
    {
48
        parent::__construct($name, $title, $source, $value);
49
        $this->setAttribute('class', 'form-control');
50
    }
51
}
52