Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 69 lines (57 sloc) 1.339 kB
4a5d9b0 @Hayden Moved Sapphire module to open source path
Hayden authored
1 <?php
2 /**
3 * Single checkbox field.
07d2d52 @wilr ENHANCEMENT: populate FormField:: on the fly based on class name of f…
wilr authored
4 *
b1d2e39 @sminnee API Documentation updates
sminnee authored
5 * @package forms
6 * @subpackage fields-basic
4a5d9b0 @Hayden Moved Sapphire module to open source path
Hayden authored
7 */
8 class CheckboxField extends FormField {
a5e82dd @halkyon Merged from branches/2.3
halkyon authored
9
e2f073f @chillu Method visibility according to coding conventions
chillu authored
10 public function setValue($value) {
a5e82dd @halkyon Merged from branches/2.3
halkyon authored
11 $this->value = ($value) ? 1 : 0;
7602d08 @chillu ENHANCEMENT Fluent interface in Form API by returning instance from a…
chillu authored
12 return $this;
a5e82dd @halkyon Merged from branches/2.3
halkyon authored
13 }
14
e2f073f @chillu Method visibility according to coding conventions
chillu authored
15 public function dataValue() {
771e93e @wilr BUGFIX: return null data from checkbox field if not set. Fixes issue …
wilr authored
16 return ($this->value) ? 1 : NULL;
a5e82dd @halkyon Merged from branches/2.3
halkyon authored
17 }
9e548f5 @halkyon API CHANGE FormField::Field() and FormField::FieldHolder() now render…
halkyon authored
18
e2f073f @chillu Method visibility according to coding conventions
chillu authored
19 public function Value() {
a5e82dd @halkyon Merged from branches/2.3
halkyon authored
20 return ($this->value) ? 1 : 0;
21 }
22
e2f073f @chillu Method visibility according to coding conventions
chillu authored
23 public function getAttributes() {
b5421d9 @chillu ENHANCEMENT Allowing custom attributes in (most) FormField implementa…
chillu authored
24 $attrs = parent::getAttributes();
25 $attrs['value'] = 1;
26 return array_merge(
27 $attrs,
28 array(
29 'checked' => ($this->Value()) ? 'checked' : null,
30 'type' => 'checkbox',
31 )
32 );
33 }
34
4a5d9b0 @Hayden Moved Sapphire module to open source path
Hayden authored
35 /**
36 * Returns a readonly version of this field
37 */
e2f073f @chillu Method visibility according to coding conventions
chillu authored
38 public function performReadonlyTransformation() {
dee3939 @sunnysideup BUGFIX: Fix the broken perform readonly transformation which was alw…
sunnysideup authored
39 $field = new CheckboxField_Readonly($this->name, $this->title, $this->value);
4a5d9b0 @Hayden Moved Sapphire module to open source path
Hayden authored
40 $field->setForm($this->form);
41 return $field;
42 }
43
e2f073f @chillu Method visibility according to coding conventions
chillu authored
44 public function performDisabledTransformation() {
d26f08b @chillu MINOR merged branches/2.3 into trunk
chillu authored
45 $clone = clone $this;
46 $clone->setDisabled(true);
47 return $clone;
4a5d9b0 @Hayden Moved Sapphire module to open source path
Hayden authored
48 }
9e548f5 @halkyon API CHANGE FormField::Field() and FormField::FieldHolder() now render…
halkyon authored
49
4a5d9b0 @Hayden Moved Sapphire module to open source path
Hayden authored
50 }
51
41a11b2 @sminnee Improved API documentation
sminnee authored
52 /**
53 * Readonly version of a checkbox field - "Yes" or "No".
07d2d52 @wilr ENHANCEMENT: populate FormField:: on the fly based on class name of f…
wilr authored
54 *
41a11b2 @sminnee Improved API documentation
sminnee authored
55 * @package forms
56 * @subpackage fields-basic
57 */
4a5d9b0 @Hayden Moved Sapphire module to open source path
Hayden authored
58 class CheckboxField_Readonly extends ReadonlyField {
9e548f5 @halkyon API CHANGE FormField::Field() and FormField::FieldHolder() now render…
halkyon authored
59
e2f073f @chillu Method visibility according to coding conventions
chillu authored
60 public function performReadonlyTransformation() {
d26f08b @chillu MINOR merged branches/2.3 into trunk
chillu authored
61 return clone $this;
4a5d9b0 @Hayden Moved Sapphire module to open source path
Hayden authored
62 }
dee3939 @sunnysideup BUGFIX: Fix the broken perform readonly transformation which was alw…
sunnysideup authored
63
e2f073f @chillu Method visibility according to coding conventions
chillu authored
64 public function Value() {
dee3939 @sunnysideup BUGFIX: Fix the broken perform readonly transformation which was alw…
sunnysideup authored
65 return Convert::raw2xml($this->value ? _t('CheckboxField.YES', 'Yes') : _t('CheckboxField.NO', 'No'));
4a5d9b0 @Hayden Moved Sapphire module to open source path
Hayden authored
66 }
794ae40 @chillu API CHANGE Moved CheckboxFieldDisabled class to more common CheckboxF…
chillu authored
67
f8082e4 @simonwelsh MINOR Add newline to end of files without one
simonwelsh authored
68 }
Something went wrong with that request. Please try again.