Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
mappings:
ChosenDropdownField: UncleCheese\BootstrapForms\ChosenDropdownField
BootstrapUserForm: UncleCheese\BootstrapForms\BootstrapUserForm
BootstrapFormAction: UncleCheese\BootstrapForms\BootstrapFormAction
BootstrapTextField: UncleCheese\BootstrapForms\BootstrapTextField
BootstrapFormField: UncleCheese\BootstrapForms\BootstrapFormField
ChosenListboxField: UncleCheese\BootstrapForms\ChosenListboxField
SimpleHtmlEditorField: UncleCheese\BootstrapForms\SimpleHtmlEditorField
BootstrapButtonGroupField: UncleCheese\BootstrapForms\BootstrapButtonGroupField
BootstrapDropdownField: UncleCheese\BootstrapForms\BootstrapDropdownField
BootstrapForm: UncleCheese\BootstrapForms\BootstrapForm
BootstrapFieldList: UncleCheese\BootstrapForms\BootstrapFieldList
BootstrapOptionsetField: UncleCheese\BootstrapForms\BootstrapOptionsetField
BootstrapMemberLoginForm: UncleCheese\BootstrapForms\BootstrapMemberLoginForm
41 changes: 21 additions & 20 deletions _config/config.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
---
name: BootstrapForm
---
BootstrapForm:
UncleCheese\BootstrapForms\BootstrapForm:
bootstrap_included: false
jquery_included: false
bootstrap_form_included: false
bootstrap_select_included: false
inline_fields:
- CheckboxField
- FormAction
FormField:
- SilverStripe\Forms\CheckboxField
- SilverStripe\Forms\FormAction
SilverStripe\Forms\FormField:
extensions:
- BootstrapFormField
TextField:
- UncleCheese\BootstrapForms\BootstrapFormField
SilverStripe\Forms\TextField:
extensions:
- BootstrapTextField
OptionsetField:
- UncleCheese\BootstrapForms\BootstrapTextField
SilverStripe\Forms\OptionsetField:
extensions:
- BootstrapOptionsetField
FormAction:
- UncleCheese\BootstrapForms\BootstrapOptionsetField
SilverStripe\Forms\FormAction:
extensions:
- BootstrapFormAction
TextareaField:
- UncleCheese\BootstrapForms\BootstrapFormAction
SilverStripe\Forms\TextareaField:
extensions:
- BootstrapTextField
FieldList:
- UncleCheese\BootstrapForms\BootstrapTextField
SilverStripe\Forms\FieldList:
extensions:
- BootstrapFieldList
Injector:
MemberLoginForm:
class: BootstrapMemberLoginForm
- UncleCheese\BootstrapForms\BootstrapFieldList
SilverStripe\Core\Injector\Injector:
SilverStripe\Security\MemberAuthenticator\MemberLoginForm:
class: UncleCheese\BootstrapForms\BootstrapMemberLoginForm
---
only:
moduleexists: userforms
---
UserDefinedForm_Controller:
SilverStripe\UserForms\Control\UserDefinedFormController:
extensions:
- BootstrapUserForm
- UncleCheese\BootstrapForms\BootstrapUserForm
7 changes: 7 additions & 0 deletions code/BootstrapButtonGroupField.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php

namespace UncleCheese\BootstrapForms;

use SilverStripe\ORM\ArrayList;
use SilverStripe\View\ArrayData;
use SilverStripe\View\Requirements;
use SilverStripe\Forms\FormField;


class BootstrapButtonGroupField extends FormField
{
Expand Down
8 changes: 8 additions & 0 deletions code/BootstrapDropdownField.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?php

namespace UncleCheese\BootstrapForms;

use SilverStripe\Core\Config\Config;
use SilverStripe\i18n\i18n;
use SilverStripe\View\Requirements;
use SilverStripe\Forms\DropdownField;
use Translatable;

/**
* Defines a FormField that uses the bootstrap-select JS plugin for making
* dropdown fields nice.
Expand Down
31 changes: 21 additions & 10 deletions code/BootstrapFieldList.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<?php

namespace UncleCheese\BootstrapForms;

use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\CompositeField;
use SilverStripe\Forms\TabSet;
use SilverStripe\Forms\Tab;
use SilverStripe\View\SSViewer;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Extension;



class BootstrapFieldList extends Extension {
Expand All @@ -14,10 +24,10 @@ class BootstrapFieldList extends Extension {
* Transforms all fields in the FieldList to use Bootstrap templates
* @return FieldList
*/
public function bootstrapify() {
public function bootstrapify() {
foreach($this->owner as $f) {

$sng = Injector::inst()->get($f->class, true, ['dummy', '']);
$sng = Injector::inst()->get(get_class($f), true, ['dummy', '']);

if(isset($this->ignores[$f->getName()])) continue;

Expand All @@ -39,19 +49,20 @@ public function bootstrapify() {

// If the user has customised the holder template already, don't apply the default one.
if($sng->getFieldHolderTemplate() == $f->getFieldHolderTemplate()) {
$template = "Bootstrap{$f->class}_holder";
if(SSViewer::hasTemplate($template)) {
$f->setFieldHolderTemplate($template);
$className = substr(strrchr(get_class($f), "\\"), 1);
$template = "UncleCheese\\BootstrapForms\\Bootstrap{$className}_holder";
if(SSViewer::hasTemplate($template)) {
$f->setFieldHolderTemplate($template);
}
else {
$f->setFieldHolderTemplate("BootstrapFieldHolder");
else {
$f->setFieldHolderTemplate("UncleCheese\\BootstrapForms\\BootstrapFieldHolder");
}

}

// If the user has customised the field template already, don't apply the default one.
if($sng->getTemplate() == $f->getTemplate()) {
foreach(array_reverse(ClassInfo::ancestry($f)) as $className) {
foreach(array_reverse(ClassInfo::ancestry($f)) as $className) {
$bootstrapCandidate = "Bootstrap{$className}";
$nativeCandidate = $className;
if(SSViewer::hasTemplate($bootstrapCandidate)) {
Expand All @@ -68,12 +79,12 @@ public function bootstrapify() {
}
}

return $this->owner;
return $this->owner;
}

/**
* Adds this field as ignored. Should not take on boostrap transformation
*
*
* @param string $field The name of the form field
* @return FieldList
*/
Expand Down
12 changes: 9 additions & 3 deletions code/BootstrapForm.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

namespace UncleCheese\BootstrapForms;

use SilverStripe\Core\Config\Config;
use SilverStripe\View\Requirements;
use SilverStripe\Forms\Form;

/**
* Builds a form that renders {@link FormField} objects
* using templates that are compatible with Twitter Bootstrap.
Expand Down Expand Up @@ -183,13 +189,13 @@ public function addWell() {
*/
public function forTemplate() {
if($this->stat('bootstrap_included')!=false) {
Requirements::css(BOOTSTRAP_FORMS_DIR.'/css/bootstrap.css');
Requirements::css('unclecheese/bootstrap-forms: css/bootstrap.css');
}
if($this->stat('jquery_included')!=false) {
Requirements::javascript(THIRDPARTY_DIR."/jquery/jquery.js");
Requirements::javascript('silverstripe/adimin: thirdparty/jquery/jquery.js');
}
if(!$this->stat('bootstrap_form_included')!=false) {
Requirements::javascript(BOOTSTRAP_FORMS_DIR."/javascript/bootstrap_forms.js");
Requirements::javascript('unclecheese/bootstrap-forms: javascript/bootstrap_forms.js');
}
$this->addExtraClass("form-{$this->formLayout}");

Expand Down
4 changes: 4 additions & 0 deletions code/BootstrapFormAction.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

namespace UncleCheese\BootstrapForms;

use SilverStripe\ORM\DataExtension;

/**
* Creates a {@link FormAction} object that is compatible
* with the Twitter Bootstrap CSS framework.
Expand Down
11 changes: 9 additions & 2 deletions code/BootstrapFormField.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php

namespace UncleCheese\BootstrapForms;

use SilverStripe\Core\Convert;
use SilverStripe\Forms\FormField;
use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\DataExtension;

/**
* The base class for creating a {@link FormField} object
* that is compatible with the Twitter Bootstrap CSS framework.
Expand Down Expand Up @@ -258,9 +265,9 @@ private function loadErrorMessage() {
* @param FormField $field
*/
public function onBeforeRender (FormField $field) {
$inline_fields = Config::inst()->get('BootstrapForm','inline_fields');
$inline_fields = Config::inst()->get(BootstrapForm::class,'inline_fields');

if(!in_array($field->class, $inline_fields )) {
if(!in_array(get_class($field), $inline_fields )) {
$field->addExtraClass('form-control');
}
}
Expand Down
21 changes: 15 additions & 6 deletions code/BootstrapMemberLoginForm.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
<?php

class BootstrapMemberLoginForm extends MemberLoginForm {
namespace UncleCheese\BootstrapForms;

use SilverStripe\Control\Controller;
use SilverStripe\Security\LoginForm;
use SilverStripe\Security\MemberAuthenticator\MemberLoginForm;

public function __construct($controller = null, $name = null, $fields = null, $actions = null, $checkCurrentUser = true) {
if(!$controller) $controller = Controller::curr();
if(!$name) $name = "LoginForm";
parent::__construct($controller, $name, $fields, $actions, $checkCurrentUser);
class BootstrapMemberLoginForm extends MemberLoginForm {
public function __construct(
$controller,
$authenticatorClass,
$name,
$fields = null,
$actions = null,
$checkCurrentUser = true
) {
parent::__construct($controller, $authenticatorClass, $name, $fields, $actions, $checkCurrentUser);
$this->Fields()->bootstrapify();
$this->Actions()->bootstrapify();
$this->setTemplate("BootstrapForm");

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

}
}
3 changes: 3 additions & 0 deletions code/BootstrapOptionsetField.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

namespace UncleCheese\BootstrapForms;

use Exception;

/**
* Creates a {@link OptionsetField} or a subclass thereof that is compatible with the
Expand Down
6 changes: 3 additions & 3 deletions code/BootstrapTextField.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace UncleCheese\BootstrapForms;

/**
* Creates a {@link TextField} or a subclass thereof that is compatible with the
* Twitter Bootstrap CSS framework.
Expand All @@ -22,8 +24,6 @@ public function prependText($text) {
return $this->owner;
}



/**
* Adds text immediately to the right, abut the form field
*
Expand Down Expand Up @@ -69,4 +69,4 @@ public function setSpan($span) {
}


}
}
4 changes: 4 additions & 0 deletions code/BootstrapUserForm.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

namespace UncleCheese\BootstrapForms;

use SilverStripe\Core\Extension;



class BootstrapUserForm extends Extension {
Expand Down
6 changes: 6 additions & 0 deletions code/ChosenDropdownField.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

namespace UncleCheese\BootstrapForms;

use SilverStripe\Core\Config\Config;
use SilverStripe\View\Requirements;
use SilverStripe\Forms\DropdownField;

/**
* Defines a FormField that uses the Chosen JS plugin for making
* dropdown fields nice.
Expand Down
5 changes: 5 additions & 0 deletions code/ChosenListboxField.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?php

namespace UncleCheese\BootstrapForms;

use SilverStripe\View\Requirements;
use SilverStripe\Forms\ListboxField;

class ChosenListboxField extends ListboxField {
/**
* @var int The number of items that need to appear in the dropdown
Expand Down
5 changes: 5 additions & 0 deletions code/SimpleHtmlEditorField.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?php

namespace UncleCheese\BootstrapForms;

use SilverStripe\View\Requirements;
use SilverStripe\Forms\TextareaField;

/**
* Defines a formfield that has HTML editing capability
* using the TinyMCE plugin
Expand Down
32 changes: 21 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
{
"name": "unclecheese/bootstrap-forms",
"description": "Allows you to create forms in SilverStripe that are compatible with Twitter Bootstrap.",
"type": "silverstripe-module",
"type": "silverstripe-vendormodule",
"keywords": ["silverstripe", "bootstrap", "forms", "twitter"],
"license": "BSD-3-Clause",
"authors": [
{
"name": "Uncle Cheese",
"email": "unclecheese@leftandmain.com"
}
{
"name": "Uncle Cheese",
"email": "unclecheese@leftandmain.com"
}
],
"require":
{
"silverstripe/framework": "3.*",
"silverstripe/cms": "3.*"
"require": {
"silverstripe/framework": "^4",
"silverstripe/cms": "^4"
},
"replace": {
"silverstripe/bootstrap-forms": "*"
},
"replace": {"silverstripe/bootstrap-forms": "*"}

"extra": {
"branch-alias": {
"dev-master": "2.x-dev"
}
},
"autoload": {
"psr-4": {
"UncleCheese\\BootstrapForms\\": "code/"
}
}
}