Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 84 lines (68 sloc) 2.445 kb
4a5d9b0 @Hayden Moved Sapphire module to open source path
Hayden authored
1 <?php
b1d2e39 @sminnee API Documentation updates
sminnee authored
2 /**
a9fa281 @chillu Form field docs update (fixes #7521)
chillu authored
3 * SelectionGroup represents a number of fields which are selectable by a radio
07d2d52 @wilr ENHANCEMENT: populate FormField:: on the fly based on class name of f…
wilr authored
4 * button that appears at the beginning of each item. Using CSS, you can
5 * configure the field to only display its contents if the corresponding radio
6 * button is selected.
7 *
b1d2e39 @sminnee API Documentation updates
sminnee authored
8 * @package forms
9 * @subpackage fields-structural
4a5d9b0 @Hayden Moved Sapphire module to open source path
Hayden authored
10 */
11 class SelectionGroup extends CompositeField {
03547fb @chillu ENHANCEMENT Added FormField->setTemplate() and getTemplate(), using i…
chillu authored
12
4a5d9b0 @Hayden Moved Sapphire module to open source path
Hayden authored
13 /**
14 * Create a new selection group.
15 * @param name The field name of the selection group.
16 * @param items The list of items to show. This should be a map. The keys will be the radio
17 * button option names, and the values should be the associated field to display. If you want,
18 * you can make this field a composite field.
19 *
20 * If you want to a have a title that is different from the value of the key, you can express it
21 * as "InternalVal//This is the Title"
22 */
e2f073f @chillu Method visibility according to coding conventions
chillu authored
23 public function __construct($name, $items) {
4a5d9b0 @Hayden Moved Sapphire module to open source path
Hayden authored
24 $this->name = $name;
1e332e6 @chillu !!BUGFIX: Refactored CSS and Requirements: Created more specific css-…
chillu authored
25
4a5d9b0 @Hayden Moved Sapphire module to open source path
Hayden authored
26 parent::__construct($items);
1e332e6 @chillu !!BUGFIX: Refactored CSS and Requirements: Created more specific css-…
chillu authored
27
3a6341a @simonwelsh API-CHANGE sapphire folder can now be renamed.
simonwelsh authored
28 Requirements::css(FRAMEWORK_DIR . '/css/SelectionGroup.css');
4a5d9b0 @Hayden Moved Sapphire module to open source path
Hayden authored
29 }
639caea @chillu MINOR Using FieldList instead of FieldSet on SelectionGroup to comply…
chillu authored
30
e2f073f @chillu Method visibility according to coding conventions
chillu authored
31 public function FieldSet() {
639caea @chillu MINOR Using FieldList instead of FieldSet on SelectionGroup to comply…
chillu authored
32 return $this->FieldList();
33 }
34
e2f073f @chillu Method visibility according to coding conventions
chillu authored
35 public function FieldList() {
639caea @chillu MINOR Using FieldList instead of FieldSet on SelectionGroup to comply…
chillu authored
36 $items = parent::FieldList()->toArray();
18991b1 fix the bug that initialises with preloaded selected items with right…
Normann Lou authored
37
4a5d9b0 @Hayden Moved Sapphire module to open source path
Hayden authored
38 $count = 0;
18991b1 fix the bug that initialises with preloaded selected items with right…
Normann Lou authored
39 $firstSelected = $checked ="";
b649c09 @jakr BUG prevent notice when using selection group
jakr authored
40 $newItems = array();
41
4a5d9b0 @Hayden Moved Sapphire module to open source path
Hayden authored
42 foreach($items as $key => $item) {
43 if(strpos($key,'//') !== false) {
44 list($key,$title) = explode('//', $key,2);
45 } else {
46 $title = $key;
47 }
48 if($this->value == $key) {
49 $firstSelected = " class=\"selected\"";
50 $checked = " checked=\"checked\"";
51 }
52
53 $itemID = $this->ID() . '_' . (++$count);
54 $extra = array(
1f7fc1f @sminnee FIX Remove instances of lines longer than 120c
sminnee authored
55 "RadioButton" => "<input class=\"selector\" type=\"radio\" id=\"$itemID\" name=\"$this->name\""
56 . " value=\"$key\"$checked />",
4a5d9b0 @Hayden Moved Sapphire module to open source path
Hayden authored
57 "RadioLabel" => "<label for=\"$itemID\">$title</label>",
58 "Selected" => $firstSelected,
59 );
60 if(is_object($item)) $newItems[] = $item->customise($extra);
61 else $newItems[] = new ArrayData($extra);
62
2b8e14f @halkyon API CHANGE Fixing CompositeField/SelectionGroup
halkyon authored
63 $firstSelected = $checked ="";
4a5d9b0 @Hayden Moved Sapphire module to open source path
Hayden authored
64 }
07d2d52 @wilr ENHANCEMENT: populate FormField:: on the fly based on class name of f…
wilr authored
65
3f132a1 @ajshort API CHANGE: Replaced DataObjectSet instances with ArrayList.
ajshort authored
66 return new ArrayList($newItems);
4a5d9b0 @Hayden Moved Sapphire module to open source path
Hayden authored
67 }
68
e2f073f @chillu Method visibility according to coding conventions
chillu authored
69 public function hasData() {
4a5d9b0 @Hayden Moved Sapphire module to open source path
Hayden authored
70 return true;
71 }
72
e2f073f @chillu Method visibility according to coding conventions
chillu authored
73 public function FieldHolder($properties = array()) {
d5e2db7 @ajshort BUGFIX: Included jQuery in SelectionGroup->FieldHolder(), and used ne…
ajshort authored
74 Requirements::javascript(THIRDPARTY_DIR .'/jquery/jquery.js');
3a6341a @simonwelsh API-CHANGE sapphire folder can now be renamed.
simonwelsh authored
75 Requirements::javascript(FRAMEWORK_DIR . '/javascript/SelectionGroup.js');
76 Requirements::css(FRAMEWORK_DIR . '/css/SelectionGroup.css');
716ff9d @ajoneil MINOR: Ensure all form fields have FieldHolder() with identical signa…
ajoneil authored
77
78 $obj = $properties ? $this->customise($properties) : $this;
7df26fd @wilr BUGFIX: fix missing TabSet template from previous changes and selecti…
wilr authored
79
80 return $obj->renderWith($this->getTemplates());
4a5d9b0 @Hayden Moved Sapphire module to open source path
Hayden authored
81 }
82 }
83
Something went wrong with that request. Please try again.