1 | <?php |
||
8 | class ChoiceFieldBuilder extends FieldBuilder |
||
9 | { |
||
10 | /** |
||
11 | * @var array |
||
12 | */ |
||
13 | private $choices = []; |
||
14 | |||
15 | /** |
||
16 | * @param string $name Field Name, conventionally 'snake_case'. |
||
17 | * @param string $type Field Type. |
||
18 | * @param array $config Additional Field Configuration. |
||
19 | */ |
||
20 | public function __construct($name, $type, $config = []) |
||
28 | |||
29 | /** |
||
30 | * Add a choice with optional label. If label not supplied, choice value |
||
31 | * will be used. |
||
32 | * @param string $choice choice value |
||
33 | * @param string $label label that appears |
||
34 | * @return $this |
||
35 | */ |
||
36 | public function addChoice($choice, $label = null) |
||
42 | |||
43 | /** |
||
44 | * Add multiple choices. Also accepts multiple arguments, one for each choice. |
||
45 | * @param array $choices Can be an array of key values ['choice' => 'label'] |
||
46 | * @return $this |
||
47 | */ |
||
48 | public function addChoices($choices) |
||
67 | |||
68 | /** |
||
69 | * Discards existing choices and adds multiple choices. |
||
70 | * Also accepts multiple arguments, one for each choice. |
||
71 | * @param array $choices Can be an array of key values ['choice' => 'label'] |
||
72 | * @return $this |
||
73 | */ |
||
74 | public function setChoices($choices) |
||
83 | |||
84 | /** |
||
85 | * @return array |
||
86 | */ |
||
87 | private function getChoices() |
||
91 | |||
92 | /** |
||
93 | * Build the field configuration array |
||
94 | * @return array Field configuration array |
||
95 | */ |
||
96 | public function build() |
||
102 | } |
||
103 |