Skip to content

Commit 4fa8e51

Browse files
author
Uncle Cheese
committed
ENHANCEMENTS: inject bootstrap login form, remove redundant methods, apply extra classes in boostrapify() rather than onBeforeRender
1 parent e7807ff commit 4fa8e51

File tree

5 files changed

+13
-46
lines changed

5 files changed

+13
-46
lines changed

_config/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ TextareaField:
2525
FieldList:
2626
extensions:
2727
- BootstrapFieldList
28+
Injector:
29+
MemberLoginForm:
30+
class: BootstrapMemberLoginForm
2831
---
2932
only:
3033
moduleexists: userforms

code/BootstrapFieldList.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class BootstrapFieldList extends Extension {
88

99

1010
public function bootstrapify() {
11+
$inline_fields = Config::inst()->get('BootstrapForm','inline_fields');
12+
1113
foreach($this->owner as $f) {
1214

1315

@@ -23,6 +25,10 @@ public function bootstrapify() {
2325
$f->Fields()->bootstrapify();
2426
}
2527

28+
if(!in_array($f->class, $inline_fields )) {
29+
$f->addExtraClass('form-control');
30+
}
31+
2632
$template = "Bootstrap{$f->class}_holder";
2733
if(SSViewer::hasTemplate($template)) {
2834
$f->setFieldHolderTemplate($template);

code/BootstrapForm.php

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -66,49 +66,20 @@ public static function set_bootstrap_form_included($bool = true) {
6666
}
6767

6868

69-
/**
70-
* Changes the templates of all the {@link FormField}
71-
* objects in a given {@link FieldList} object to those
72-
* that work the Bootstrap framework
73-
*
74-
* @param FieldList $fields
75-
*/
76-
public static function apply_bootstrap_to_fieldlist($fields) {
77-
$fields->bootstrapify();
78-
}
79-
80-
81-
82-
8369
/**
8470
* Applies the Bootstrap transformation to the fields and actiosn
8571
* of the form
8672
*
8773
* @return BootstrapForm
8874
*/
8975
public function applyBootstrap() {
90-
$this->applyBootstrapToFieldList($this->Fields());
91-
$this->applyBootstrapToFieldList($this->Actions());
92-
return $this;
93-
}
94-
76+
$this->Fields()->bootstrapify();
77+
$this->Actions()->bootstrapify();
9578

96-
97-
/**
98-
* Changes the templates of all the {@link FormField}
99-
* objects in a given {@link FieldList} object to those
100-
* that work the Bootstrap framework
101-
*
102-
* @param FieldList $fields
103-
* @return BootstrapForm
104-
*/
105-
protected function applyBootstrapToFieldList($fields) {
106-
self::apply_bootstrap_to_fieldlist($fields);
10779
return $this;
10880
}
10981

11082

111-
11283
/**
11384
* Sets the desired layout of the form. Options include:
11485
* - "vertical" (default)

code/BootstrapFormField.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,6 @@ public function HolderClasses() {
166166
return implode(" ",$this->holderClasses);
167167
}
168168

169-
/**
170-
* Adds requisite classes to the form field
171-
*
172-
* @return BootstrapFormField
173-
*/
174-
public function onBeforeRender() {
175-
if(
176-
!in_array($this->owner->class, Config::inst()->get('BootstrapForm','inline_fields')) &&
177-
($this->owner->getForm() && $this->owner->getForm() instanceof BootstrapForm)
178-
) {
179-
$this->owner->addExtraClass('form-control');
180-
}
181-
return $this->owner;
182-
}
183-
184169
/**
185170
* checks for error messages in owner form field
186171
* adds error class to holder and loads error message as helptext

code/BootstrapMemberLoginForm.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public function __construct($controller = null, $name = null, $fields = null, $a
1010
$this->Fields()->bootstrapify();
1111
$this->Actions()->bootstrapify();
1212
$this->setTemplate("BootstrapForm");
13+
14+
$this->invokeWithExtensions('updateBoostrapMemberLoginForm', $this);
1315
}
1416

1517
}

0 commit comments

Comments
 (0)