Skip to content

Commit

Permalink
ENHANCEMENTS: inject bootstrap login form, remove redundant methods, …
Browse files Browse the repository at this point in the history
…apply extra classes in boostrapify() rather than onBeforeRender
  • Loading branch information
Uncle Cheese committed Jan 13, 2015
1 parent e7807ff commit 4fa8e51
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 46 deletions.
3 changes: 3 additions & 0 deletions _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ TextareaField:
FieldList:
extensions:
- BootstrapFieldList
Injector:
MemberLoginForm:
class: BootstrapMemberLoginForm
---
only:
moduleexists: userforms
Expand Down
6 changes: 6 additions & 0 deletions code/BootstrapFieldList.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class BootstrapFieldList extends Extension {


public function bootstrapify() {
$inline_fields = Config::inst()->get('BootstrapForm','inline_fields');

foreach($this->owner as $f) {


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

if(!in_array($f->class, $inline_fields )) {
$f->addExtraClass('form-control');
}

$template = "Bootstrap{$f->class}_holder";
if(SSViewer::hasTemplate($template)) {
$f->setFieldHolderTemplate($template);
Expand Down
33 changes: 2 additions & 31 deletions code/BootstrapForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,49 +66,20 @@ public static function set_bootstrap_form_included($bool = true) {
}


/**
* Changes the templates of all the {@link FormField}
* objects in a given {@link FieldList} object to those
* that work the Bootstrap framework
*
* @param FieldList $fields
*/
public static function apply_bootstrap_to_fieldlist($fields) {
$fields->bootstrapify();
}




/**
* Applies the Bootstrap transformation to the fields and actiosn
* of the form
*
* @return BootstrapForm
*/
public function applyBootstrap() {
$this->applyBootstrapToFieldList($this->Fields());
$this->applyBootstrapToFieldList($this->Actions());
return $this;
}

$this->Fields()->bootstrapify();
$this->Actions()->bootstrapify();


/**
* Changes the templates of all the {@link FormField}
* objects in a given {@link FieldList} object to those
* that work the Bootstrap framework
*
* @param FieldList $fields
* @return BootstrapForm
*/
protected function applyBootstrapToFieldList($fields) {
self::apply_bootstrap_to_fieldlist($fields);
return $this;
}



/**
* Sets the desired layout of the form. Options include:
* - "vertical" (default)
Expand Down
15 changes: 0 additions & 15 deletions code/BootstrapFormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,21 +166,6 @@ public function HolderClasses() {
return implode(" ",$this->holderClasses);
}

/**
* Adds requisite classes to the form field
*
* @return BootstrapFormField
*/
public function onBeforeRender() {
if(
!in_array($this->owner->class, Config::inst()->get('BootstrapForm','inline_fields')) &&
($this->owner->getForm() && $this->owner->getForm() instanceof BootstrapForm)
) {
$this->owner->addExtraClass('form-control');
}
return $this->owner;
}

/**
* checks for error messages in owner form field
* adds error class to holder and loads error message as helptext
Expand Down
2 changes: 2 additions & 0 deletions code/BootstrapMemberLoginForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public function __construct($controller = null, $name = null, $fields = null, $a
$this->Fields()->bootstrapify();
$this->Actions()->bootstrapify();
$this->setTemplate("BootstrapForm");

$this->invokeWithExtensions('updateBoostrapMemberLoginForm', $this);
}

}

0 comments on commit 4fa8e51

Please sign in to comment.