Permalink
Browse files

Works with UserForms module

  • Loading branch information...
1 parent fc9446d commit dd03b9bd02d23c87244182d76a817aca1c82c31b @ryanwachtl committed Jan 13, 2013
View
@@ -1,8 +1,11 @@
<?php
//forms
-Object::useCustomClass('Form', 'FoundationForm');
-Object::useCustomClass('MemberLoginForm', 'FoundationMemberLoginForm');
+Object::useCustomClass('Form', 'FoundationForm', true);
+Object::useCustomClass('MemberLoginForm', 'FoundationMemberLoginForm', true);
+if (class_exists('UserDefinedForm')) {
+ Object::add_extension('UserDefinedForm_Controller', 'FoundationUserDefinedForm_Controller');
+}
//fields
//Object::add_extension("FormField", "FoundationFormField");
View
@@ -11,100 +11,10 @@
* @package foundation_forms
*/
class FoundationForm extends Form {
-
- /**
- * @var string The template that will render this form
- */
- protected $template = "FoundationForm";
-
-
-
- /**
- * Changes the templates of all the {@link FormField}
- * objects in a given {@link FieldList} object to those
- * that work the Foundation framework
- *
- * @param FieldList $fields
- */
- public static function apply_foundation_to_fieldlist($fields) {
- foreach($fields as $f) {
-
- // If we have a Tabset, bootstrapify all Tabs
- if($f instanceof TabSet) {
- self::apply_foundation_to_fieldlist($f->Tabs());
- }
-
- // If we have a Tab, bootstrapify all its Fields
- if($f instanceof Tab) {
- self::apply_foundation_to_fieldlist($f->Fields());
- }
-
-
- $template = "Foundation{$f->class}_holder";
- if(SSViewer::hasTemplate($template)) {
- $f->setFieldHolderTemplate($template);
- }
- else {
- $f->setFieldHolderTemplate("FoundationFieldHolder");
- }
-
- foreach(array_reverse(ClassInfo::ancestry($f)) as $className) {
- $foundationCandidate = "Foundation{$className}";
- $nativeCandidate = $className;
- if(SSViewer::hasTemplate($foundationCandidate)) {
- $f->setTemplate($foundationCandidate);
- break;
- }
- elseif(SSViewer::hasTemplate($nativeCandidate)) {
- $f->setTemplate($nativeCandidate);
- break;
- }
- }
- }
- }
-
-
- /**
- * Applies the Foundation transformation to the fields and actiosn
- * of the form
- *
- * @return FoundationForm
- */
- public function applyFoundation() {
- $this->applyFoundationToFieldList($this->Fields());
- $this->applyFoundationToFieldList($this->Actions());
- return $this;
- }
-
-
-
- /**
- * Changes the templates of all the {@link FormField}
- * objects in a given {@link FieldList} object to those
- * that work the Foundation framework
- *
- * @param FieldList $fields
- * @return FoundationForm
- */
- protected function applyFoundationToFieldList($fields) {
- self::apply_foundation_to_fieldlist($fields);
- return $this;
- }
-
-
-
- /**
- * Includes the dependency if necessary, applies the Bootstrap templates,
- * and renders the form HTML output
- *
- * @return string
- */
public function forTemplate() {
- $this->applyFoundation();
+ FoundationFormTransformation::transform($this);
return parent::forTemplate();
}
-
-
}
@@ -0,0 +1,86 @@
+<?php
+
+/**
+ * @author Ryan Wachtl <ryan.wachtl@gmail.com>
+ * @package foundation_forms
+ */
+class FoundationFormTransformation {
+
+ protected static $template = "FoundationForm";
+
+ public function transform(Form $form) {
+ self::applyFoundation($form);
+ $form->addExtraClass('custom');
+ $form->setTemplate($template);
+ }
+
+ /**
+ * Changes the templates of all the {@link FormField}
+ * objects in a given {@link FieldList} object to those
+ * that work the Foundation framework
+ *
+ * @param FieldList $fields
+ */
+ public static function apply_foundation_to_fieldlist(FieldList $fields) {
+
+ foreach($fields as $field) {
+
+ // tabset
+ if($field instanceof TabSet) {
+ self::apply_foundation_to_fieldlist($field->Tabs());
+ }
+
+ // tab
+ if($field instanceof Tab) {
+ self::apply_foundation_to_fieldlist($field->Fields());
+ }
+
+ $template = "Foundation{$f->class}_holder";
+
+ if(SSViewer::hasTemplate($template)) {
+ $field->setFieldHolderTemplate($template);
+ }
+ else {
+ $field->setFieldHolderTemplate("FoundationFieldHolder");
+ }
+
+ foreach(array_reverse(ClassInfo::ancestry($field)) as $className) {
+ $foundationCandidate = "Foundation{$className}";
+ $nativeCandidate = $className;
+ if(SSViewer::hasTemplate($foundationCandidate)) {
+ $field->setTemplate($foundationCandidate);
+ break;
+ }
+ elseif(SSViewer::hasTemplate($nativeCandidate)) {
+ $field->setTemplate($nativeCandidate);
+ break;
+ }
+ }
+ }
+ }
+
+
+
+ /**
+ * Applies the Foundation transformation to the fields and actions
+ * of the form
+ */
+ public function applyFoundation(Form $form) {
+ self::applyFoundationToFieldList($form->Fields());
+ self::applyFoundationToFieldList($form->Actions());
+ }
+
+
+
+ /**
+ * Changes the templates of all the {@link FormField}
+ * objects in a given {@link FieldList} object to those
+ * that work the Foundation framework
+ *
+ * @param FieldList $fields
+ */
+ protected function applyFoundationToFieldList(FieldList $fields) {
+ self::apply_foundation_to_fieldlist($fields);
+ }
+
+}
@@ -13,99 +13,14 @@
class FoundationMemberLoginForm extends MemberLoginForm {
/**
- * @var string The template that will render this form
- */
- protected $template = "FoundationForm";
-
-
-
- /**
- * Changes the templates of all the {@link FormField}
- * objects in a given {@link FieldList} object to those
- * that work the Foundation framework
- *
- * @param FieldList $fields
- */
- public static function apply_foundation_to_fieldlist($fields) {
- foreach($fields as $f) {
-
- // If we have a Tabset, bootstrapify all Tabs
- if($f instanceof TabSet) {
- self::apply_foundation_to_fieldlist($f->Tabs());
- }
-
- // If we have a Tab, bootstrapify all its Fields
- if($f instanceof Tab) {
- self::apply_foundation_to_fieldlist($f->Fields());
- }
-
-
- $template = "Foundation{$f->class}_holder";
- if(SSViewer::hasTemplate($template)) {
- $f->setFieldHolderTemplate($template);
- }
- else {
- $f->setFieldHolderTemplate("FoundationFieldHolder");
- }
-
- foreach(array_reverse(ClassInfo::ancestry($f)) as $className) {
- $foundationCandidate = "Foundation{$className}";
- $nativeCandidate = $className;
- if(SSViewer::hasTemplate($foundationCandidate)) {
- $f->setTemplate($foundationCandidate);
- break;
- }
- elseif(SSViewer::hasTemplate($nativeCandidate)) {
- $f->setTemplate($nativeCandidate);
- break;
- }
- }
- }
- }
-
-
-
- /**
- * Applies the Foundation transformation to the fields and actiosn
- * of the form
- *
- * @return FoundationForm
- */
- public function applyFoundation() {
- $this->applyFoundationToFieldList($this->Fields());
- $this->applyFoundationToFieldList($this->Actions());
- return $this;
- }
-
-
-
- /**
- * Changes the templates of all the {@link FormField}
- * objects in a given {@link FieldList} object to those
- * that work the Foundation framework
- *
- * @param FieldList $fields
- * @return FoundationForm
- */
- protected function applyFoundationToFieldList($fields) {
- self::apply_foundation_to_fieldlist($fields);
- return $this;
- }
-
-
-
- /**
- * Includes the dependency if necessary, applies the Bootstrap templates,
+ * Includes the dependency if necessary, applies the Foundation templates,
* and renders the form HTML output
*
* @return string
*/
public function forTemplate() {
- $this->applyFoundation();
- $this->addExtraClass("custom");
+ FoundationFormTransformation::transform($this);
return parent::forTemplate();
}
-
-
}
@@ -0,0 +1,13 @@
+<?php
+
+/**
+ * @author Ryan Wachtl <ryan.wachtl@gmail.com>
+ * @package foundation_forms
+ */
+class FoundationUserDefinedForm_Controller extends DataExtension {
+
+ public function updateForm(Form $form) {
+ FoundationFormTransformation::transform($form);
+ }
+
+}

0 comments on commit dd03b9b

Please sign in to comment.