From c20a51177ee161d6341d23e614b1e03dc467a45e Mon Sep 17 00:00:00 2001 From: helpfulrobot Date: Fri, 1 Jan 2016 04:53:30 +1300 Subject: [PATCH] Converted to PSR-2 --- .../FlexiFormControllerExtension.php | 4 +-- code/extensions/FlexiFormExtension.php | 27 ++++++++-------- code/forms/FlexiForm.php | 5 ++- .../gridfield/GridFieldConfig_FlexiForm.php | 4 +-- .../GridFieldConfig_FlexiFormHandler.php | 4 +-- .../GridFieldConfig_FlexiFormOption.php | 2 -- .../GridFieldConfig_FlexiFormSubmission.php | 9 +++--- ...dFieldConfig_FlexiFormSubmissionValues.php | 6 ++-- code/model/FlexiFormConfig.php | 4 +-- code/model/FlexiFormField.php | 12 +++---- code/model/FlexiFormFieldOption.php | 17 +++++----- code/model/FlexiFormHandler.php | 13 ++++---- code/model/FlexiFormOptionField.php | 3 +- code/model/FlexiFormSubmission.php | 13 ++++---- code/model/FlexiFormSubmissionValue.php | 8 +++-- .../FlexiFormCheckboxField.php | 5 +-- .../FlexiFormCheckboxSetField.php | 6 ++-- .../FlexiFormDropdownField.php | 2 +- .../flexiformfields/FlexiFormEmailField.php | 6 ++-- .../FlexiFormMultiSelectField.php | 4 +-- .../flexiformfields/FlexiFormRadioField.php | 6 ++-- .../FlexiFormTextAreaField.php | 6 ++-- .../flexiformfields/FlexiFormTextField.php | 6 ++-- .../FlexiFormBasicHandler.php | 4 +-- .../FlexiFormEmailHandler.php | 31 ++++++++++--------- .../FlexiFormBooleanHandlerSetting.php | 11 ++++--- .../settings/FlexiFormEnumHandlerSetting.php | 13 ++++---- .../settings/FlexiFormFieldHandlerSetting.php | 21 ++++++------- .../FlexiFormHTMLTextHandlerSetting.php | 2 +- .../settings/FlexiFormHandlerSetting.php | 11 ++++--- .../settings/FlexiFormIntHandlerSetting.php | 11 ++++--- .../settings/FlexiFormTextHandlerSetting.php | 6 ++-- code/util/FlexiFormUtil.php | 12 +++---- 33 files changed, 142 insertions(+), 152 deletions(-) diff --git a/code/extensions/FlexiFormControllerExtension.php b/code/extensions/FlexiFormControllerExtension.php index 4eb7987..2b67a56 100644 --- a/code/extensions/FlexiFormControllerExtension.php +++ b/code/extensions/FlexiFormControllerExtension.php @@ -24,7 +24,7 @@ public function FlexiForm($identifier = null) $form_class = $flexi->stat('flexiform_form_class'); $form_name = Config::inst()->get($form_class, 'flexiform_post_action'); $form = new $form_class($this->owner, $form_name, $fields, $actions, $validator); - $form->addExtraClass(implode(' ',$flexi->stat('flexiform_form_extraclasses'))); + $form->addExtraClass(implode(' ', $flexi->stat('flexiform_form_extraclasses'))); // identify the form in post $form->setFormAction( @@ -93,4 +93,4 @@ public function setFlexiFormObject($flexi) { return $this->flexiform_object = $flexi; } -} \ No newline at end of file +} diff --git a/code/extensions/FlexiFormExtension.php b/code/extensions/FlexiFormExtension.php index b40d8d6..a277348 100644 --- a/code/extensions/FlexiFormExtension.php +++ b/code/extensions/FlexiFormExtension.php @@ -54,7 +54,6 @@ public function updateCMSFields(FieldList $fields) $fields->removeByName('FlexiFormConfigID'); if ($this->owner->exists()) { - $fields_tab = new Tab('Fields'); $settings_tab = new Tab('Settings'); @@ -80,7 +79,7 @@ public function updateCMSFields(FieldList $fields) // hint allowed types to FlexiFormField search fields singleton('FlexiFormField')->set_stat('allowed_types', $field_types); $component = $config->getComponentByType('GridFieldAddExistingSearchButton'); - $component->setSearchList(FlexiFormField::get()->filter('ClassName',array_keys($field_types))); + $component->setSearchList(FlexiFormField::get()->filter('ClassName', array_keys($field_types))); $fields_tab->push( @@ -137,13 +136,15 @@ public function getFlexiFormFrontEndFields() return $fields; } - public function getFlexiFormFrontEndFieldByID($id){ - return $this->owner->FlexiFormFields()->filter('FlexiFormField.ID',$id)->first(); + public function getFlexiFormFrontEndFieldByID($id) + { + return $this->owner->FlexiFormFields()->filter('FlexiFormField.ID', $id)->first(); } // Templates //////////// - public function Form(){ + public function Form() + { return Controller::curr()->FlexiForm($this->FlexiFormID()); } // Getters & Setters @@ -194,7 +195,7 @@ public function getFlexiFormFieldTypes() return $field_types; } - public function setFlexiFormFieldTypes(Array $field_types) + public function setFlexiFormFieldTypes(array $field_types) { return $this->owner->set_stat('flexiform_field_types', $field_types); } @@ -204,7 +205,7 @@ public function getFlexiFormInitialFields() return $this->owner->stat('flexiform_initial_fields'); } - public function setFlexiFormInitialFields(Array $field_definitions) + public function setFlexiFormInitialFields(array $field_definitions) { return $this->owner->set_stat('flexiform_initial_fields', $field_definitions); } @@ -223,7 +224,6 @@ public function setFlexiFormDefaultHandlerName($handler_name) public function setFlexiFormConfigs($value) { if ($configs = Controller::curr()->getRequest()->requestVar('FlexiFormConfig')) { - $conf = $this->FlexiFormConf(); foreach ($configs as $property => $value) { @@ -236,7 +236,7 @@ public function setFlexiFormConfigs($value) } $conf->write(); - if($handler = $this->FlexiFormHandler()) { + if ($handler = $this->FlexiFormHandler()) { $handler->onConfigUpdate($conf, $this->owner); } } @@ -259,7 +259,8 @@ public function FlexiFormHandler() return $this->FlexiFormConf('Handler'); } - public function FlexiFormSetting($setting){ + public function FlexiFormSetting($setting) + { return $this->FlexiFormConf("Setting.$setting"); } @@ -268,7 +269,6 @@ public function validate(ValidationResult $result) $names = array(); if ($result->valid()) { foreach ($this->owner->FlexiFormFields() as $field) { - if (empty($field->Name)) { $result->error("Field names cannot be blank. Encountered a blank {$field->Label()} field."); break; @@ -305,7 +305,6 @@ public function onAfterWrite() // ensure valid config ////////////////////// if (! $conf->exists()) { - if ($name = $this->getFlexiFormDefaultHandlerName()) { if ($handler = FlexiFormHandler::get()->filter('HandlerName', $name)->first()) { $conf->HandlerID = $handler->ID; @@ -324,7 +323,7 @@ public function onAfterWrite() if (!$this->FlexiFormConf('InitializedFields')) { $definitions = $this->getFlexiFormInitialFields(); - if(!empty($definitions)) { + if (!empty($definitions)) { $fields = $this->owner->FlexiFormFields(); foreach ($definitions as $definition) { if (! is_array($definition) || ! isset($definition['Name']) || ! isset($definition['Type'])) { @@ -378,4 +377,4 @@ public function onBeforeDelete() } return parent::onBeforeDelete(); } -} \ No newline at end of file +} diff --git a/code/forms/FlexiForm.php b/code/forms/FlexiForm.php index 85b5fd4..de2420b 100644 --- a/code/forms/FlexiForm.php +++ b/code/forms/FlexiForm.php @@ -49,7 +49,7 @@ public function setFlexiFormOrigin() // @TODO can we use a mock the result of a mock request for a URL instead? // ..Needed in case action requires URL params to display form. $action = $this->controller->getAction(); - if($action != $this->stat('flexiform_post_action')) { + if ($action != $this->stat('flexiform_post_action')) { Session::set("FormInfo.{$this->FormName()}.flexi_origin", $action); } } @@ -77,7 +77,6 @@ public function isSubmitted() public function httpSubmission($request) { if ($this->isSubmitted() && ! $this->getSecurityToken()->checkRequest($request)) { - $this->sessionMessage(_t("FlexiForm.RESUBMISSION_MESSAGE", "Your submission was received."), "warning"); @@ -86,4 +85,4 @@ public function httpSubmission($request) return parent::httpSubmission($request); } -} \ No newline at end of file +} diff --git a/code/forms/gridfield/GridFieldConfig_FlexiForm.php b/code/forms/gridfield/GridFieldConfig_FlexiForm.php index dc7251a..2b36f12 100644 --- a/code/forms/gridfield/GridFieldConfig_FlexiForm.php +++ b/code/forms/gridfield/GridFieldConfig_FlexiForm.php @@ -46,8 +46,7 @@ public function __construct() ), 'DefaultValue' => array( 'title' => 'Default Value', - 'callback' => function ($record, $column_name, $grid) - { + 'callback' => function ($record, $column_name, $grid) { return ($record->hasMethod('getDefaultValueFormField')) ? $record->getDefaultValueFormField( 'DefaultValue') : new TextField($column_name); } @@ -65,4 +64,3 @@ public function __construct() FlexiFormUtil::include_requirements(); } } - diff --git a/code/forms/gridfield/GridFieldConfig_FlexiFormHandler.php b/code/forms/gridfield/GridFieldConfig_FlexiFormHandler.php index 8fd9954..01bcfd2 100644 --- a/code/forms/gridfield/GridFieldConfig_FlexiFormHandler.php +++ b/code/forms/gridfield/GridFieldConfig_FlexiFormHandler.php @@ -36,8 +36,7 @@ public function __construct($allowed_types = array()) array( 'Selected' => array( 'title' => 'Selected', - 'callback' => function ($record, $column_name, $grid) - { + 'callback' => function ($record, $column_name, $grid) { return new CheckboxField_Readonly($column_name); } ), @@ -60,4 +59,3 @@ public function __construct($allowed_types = array()) )); } } - diff --git a/code/forms/gridfield/GridFieldConfig_FlexiFormOption.php b/code/forms/gridfield/GridFieldConfig_FlexiFormOption.php index 05133c9..e32fa4c 100644 --- a/code/forms/gridfield/GridFieldConfig_FlexiFormOption.php +++ b/code/forms/gridfield/GridFieldConfig_FlexiFormOption.php @@ -30,7 +30,5 @@ public function __construct() // Sort Order // /////////// $this->addComponent(new GridFieldOrderableRows('SortOrder')); - } } - diff --git a/code/forms/gridfield/GridFieldConfig_FlexiFormSubmission.php b/code/forms/gridfield/GridFieldConfig_FlexiFormSubmission.php index a063900..91680b3 100644 --- a/code/forms/gridfield/GridFieldConfig_FlexiFormSubmission.php +++ b/code/forms/gridfield/GridFieldConfig_FlexiFormSubmission.php @@ -25,8 +25,8 @@ public function __construct($flexi) $export->setExportColumns($this->getCSVColumns($flexi)); } - private function getCSVColumns($flexi) { - + private function getCSVColumns($flexi) + { $columns = array( 'SubmittedBy' => 'Submitted By', 'IPAddress' => 'IP Address', @@ -36,16 +36,15 @@ private function getCSVColumns($flexi) { $sql = new SQLQuery(); $sql->setFrom('FlexiFormSubmissionValue'); $sql->setSelect('"FlexiFormSubmissionValue"."Name"'); - $sql->addLeftJoin('FlexiFormSubmission','"FlexiFormSubmissionValue"."SubmissionID" = "FlexiFormSubmission"."ID"'); + $sql->addLeftJoin('FlexiFormSubmission', '"FlexiFormSubmissionValue"."SubmissionID" = "FlexiFormSubmission"."ID"'); $sql->addWhere('"FlexiFormSubmission"."FlexiFormID" = ' . $flexi->ID); $sql->addWhere('"FlexiFormSubmission"."FlexiFormClass" = \'' . $flexi->class . '\''); $sql->setDistinct(true); - foreach($sql->execute() as $row) { + foreach ($sql->execute() as $row) { $columns['Values.' . $row['Name']] = $row['Name']; } return $columns; } } - diff --git a/code/forms/gridfield/GridFieldConfig_FlexiFormSubmissionValues.php b/code/forms/gridfield/GridFieldConfig_FlexiFormSubmissionValues.php index d0cb715..48953a6 100644 --- a/code/forms/gridfield/GridFieldConfig_FlexiFormSubmissionValues.php +++ b/code/forms/gridfield/GridFieldConfig_FlexiFormSubmissionValues.php @@ -21,13 +21,11 @@ public function __construct() ), 'Value' => array( 'title' => 'Response Value', - 'callback' => function ($record, $column_name, $grid) - { - return new ReadonlyField($column_name,'XXX','XXX'); + 'callback' => function ($record, $column_name, $grid) { + return new ReadonlyField($column_name, 'XXX', 'XXX'); } ) )); } } - diff --git a/code/model/FlexiFormConfig.php b/code/model/FlexiFormConfig.php index 4ea6f47..19710d1 100644 --- a/code/model/FlexiFormConfig.php +++ b/code/model/FlexiFormConfig.php @@ -41,7 +41,7 @@ public function relField($fieldName) return parent::relField($fieldName); } - public function updateHandlerSettings(Array $settings) + public function updateHandlerSettings(array $settings) { foreach ($settings as $component => $value) { if ($setting = $this->relField("Setting.$component")) { @@ -71,4 +71,4 @@ protected function onBeforeDelete() return parent::onBeforeDelete(); } -} \ No newline at end of file +} diff --git a/code/model/FlexiFormField.php b/code/model/FlexiFormField.php index 98ce518..61d2162 100644 --- a/code/model/FlexiFormField.php +++ b/code/model/FlexiFormField.php @@ -73,7 +73,7 @@ public function getCMSFields() $field->description = 'Shown in submissions. Should be short and without special characters.'; - if($this->hasMethod('getDefaultValueFormField')) { + if ($this->hasMethod('getDefaultValueFormField')) { $fields->replaceField('FieldDefaultValue', $this->getDefaultValueFormField()); } @@ -117,10 +117,10 @@ public function scaffoldSearchFields($_params = null) { $fields = parent::scaffoldSearchFields($_params); - if($allowed_types = $this->stat('allowed_types')) { - $field = $fields->dataFieldByName('ClassName'); - $field->setSource($allowed_types); - $field->setEmptyString('Select Type'); + if ($allowed_types = $this->stat('allowed_types')) { + $field = $fields->dataFieldByName('ClassName'); + $field->setSource($allowed_types); + $field->setEmptyString('Select Type'); } return $fields; } @@ -198,7 +198,7 @@ public function getRequiredFieldDefinitions() return $this->stat('required_field_definitions'); } - public function setRequiredFieldDefinitions(Array $required_field_definitions) + public function setRequiredFieldDefinitions(array $required_field_definitions) { return $this->set_stat('required_field_definitions', $required_field_definitions); } diff --git a/code/model/FlexiFormFieldOption.php b/code/model/FlexiFormFieldOption.php index 45f456f..1258f11 100644 --- a/code/model/FlexiFormFieldOption.php +++ b/code/model/FlexiFormFieldOption.php @@ -1,6 +1,7 @@ 'Varchar', @@ -17,11 +18,12 @@ class FlexiFormFieldOption extends DataObject { ); - public function validate() { + public function validate() + { $result = parent::validate(); - if($result->valid()) { - if(empty($this->Value)) { + if ($result->valid()) { + if (empty($this->Value)) { $result->error('Option Values cannot be blank.'); } } @@ -29,10 +31,9 @@ public function validate() { return $result; } - public function getLabel(){ - + public function getLabel() + { $label = $this->getField('Label'); return (empty($label)) ? $this->Value : $label; } - -} \ No newline at end of file +} diff --git a/code/model/FlexiFormHandler.php b/code/model/FlexiFormHandler.php index 22cd4a0..be0cda4 100644 --- a/code/model/FlexiFormHandler.php +++ b/code/model/FlexiFormHandler.php @@ -82,7 +82,6 @@ public function updateCMSFlexiTabs(TabSet $fields, TabSet $settings_tab, $flexi) $form_settings = $flexi->FlexiFormConf('HandlerSettings'); foreach (Config::inst()->get($this->class, 'handler_settings', Config::INHERITED) as $component => $class) { - if (! $setting = $flexi->FlexiFormSetting($component)) { $setting = new $class(); $setting->Setting = $component; @@ -122,7 +121,7 @@ public function getFrontEndFormValidator($flexi) * @param DataObject $flexi The object extended by FlexiFormExtension * @return Boolean */ - public function onSubmit(Array $data, FlexiForm $form, SS_HTTPRequest $request, DataObject $flexi) + public function onSubmit(array $data, FlexiForm $form, SS_HTTPRequest $request, DataObject $flexi) { return true; } @@ -138,7 +137,8 @@ public function onSubmit(Array $data, FlexiForm $form, SS_HTTPRequest $request, * @param DataObject $flexi The object extended by FlexiFormExtension */ public function onSuccess(FlexiForm $form, DataObject $flexi) - {} + { + } // Templates //////////// @@ -170,7 +170,7 @@ public function getRequiredHandlerDefinitions() return $this->lookup('required_handler_definitions'); } - public function setRequiredHandlerDefinitions(Array $definitions) + public function setRequiredHandlerDefinitions(array $definitions) { return $this->set_stat('required_handler_definitions', $definitions); } @@ -193,7 +193,8 @@ protected function getSettingFieldName($setting) } public function onConfigUpdate(FlexiFormConfig $config, DataObject $flexi) - {} + { + } public function requireDefaultRecords() { @@ -212,4 +213,4 @@ public function onBeforeDelete() return parent::onBeforeDelete(); } -} \ No newline at end of file +} diff --git a/code/model/FlexiFormOptionField.php b/code/model/FlexiFormOptionField.php index 7e10ed0..f4bf043 100644 --- a/code/model/FlexiFormOptionField.php +++ b/code/model/FlexiFormOptionField.php @@ -19,7 +19,6 @@ public function getCMSFields() implode(', ', $this->Options() ->column('Label')))); } else { - $config = new GridFieldConfig_FlexiFormOption(); $fields->addFieldToTab('Root.Main', new GridField('Options', 'Options', $this->Options(), $config)); @@ -75,4 +74,4 @@ public function getDefaultValueFormField($field_name = 'FieldDefaultValue') $field->description = 'Optional. This value will be preselectd.'; return $field; } -} \ No newline at end of file +} diff --git a/code/model/FlexiFormSubmission.php b/code/model/FlexiFormSubmission.php index 5d20d8f..392fe48 100644 --- a/code/model/FlexiFormSubmission.php +++ b/code/model/FlexiFormSubmission.php @@ -71,7 +71,6 @@ public function relField($fieldName) 'SubmissionID' => $this->ID, 'Name' => substr($fieldName, 7) ))->first()) { - return $submission_value->ColumnValue(); } } @@ -79,18 +78,18 @@ public function relField($fieldName) return parent::relField($fieldName); } - public function addStatusMessage($message) { + public function addStatusMessage($message) + { $this->messages[] = $message; } - public function onBeforeWrite(){ - while($message = array_shift($this->messages)) { - $prefix = empty($this->StatusMessages) ? '' : ' ~~ '; + public function onBeforeWrite() + { + while ($message = array_shift($this->messages)) { + $prefix = empty($this->StatusMessages) ? '' : ' ~~ '; $this->StatusMessages .= $prefix . $message; } return parent::onBeforeWrite(); } } - - diff --git a/code/model/FlexiFormSubmissionValue.php b/code/model/FlexiFormSubmissionValue.php index 8bb6592..ca94eb9 100644 --- a/code/model/FlexiFormSubmissionValue.php +++ b/code/model/FlexiFormSubmissionValue.php @@ -1,6 +1,7 @@ 'Int', @@ -17,9 +18,10 @@ class FlexiFormSubmissionValue extends DataObject { 'Name' ); - public function ColumnValue(){ + public function ColumnValue() + { return (class_exists($this->FormFieldClass)) ? singleton($this->FormFieldClass)->transformValue($this->Value) : $this->Value; } -} \ No newline at end of file +} diff --git a/code/model/flexiformfields/FlexiFormCheckboxField.php b/code/model/flexiformfields/FlexiFormCheckboxField.php index e4e3460..a110ae2 100644 --- a/code/model/flexiformfields/FlexiFormCheckboxField.php +++ b/code/model/flexiformfields/FlexiFormCheckboxField.php @@ -28,7 +28,8 @@ public function getDefaultValueFormField($field_name = 'FieldDefaultValue') return $field; } - public function transformValue($value) { + public function transformValue($value) + { return ($value) ? 'checked' : 'unchecked'; } -} \ No newline at end of file +} diff --git a/code/model/flexiformfields/FlexiFormCheckboxSetField.php b/code/model/flexiformfields/FlexiFormCheckboxSetField.php index c2cb038..01834f5 100644 --- a/code/model/flexiformfields/FlexiFormCheckboxSetField.php +++ b/code/model/flexiformfields/FlexiFormCheckboxSetField.php @@ -1,8 +1,8 @@ getField('EmptyString'); return (empty($value)) ? $this->default_empty_string : $value; } -} \ No newline at end of file +} diff --git a/code/model/flexiformfields/FlexiFormEmailField.php b/code/model/flexiformfields/FlexiFormEmailField.php index 9658f0b..ae5f56c 100644 --- a/code/model/flexiformfields/FlexiFormEmailField.php +++ b/code/model/flexiformfields/FlexiFormEmailField.php @@ -1,8 +1,8 @@ saveSubmission($data, $flexi); @@ -96,4 +96,4 @@ protected function saveSubmission($data, $flexi) } } } -} \ No newline at end of file +} diff --git a/code/model/flexiformhandlers/FlexiFormEmailHandler.php b/code/model/flexiformhandlers/FlexiFormEmailHandler.php index e42f758..de3a554 100644 --- a/code/model/flexiformhandlers/FlexiFormEmailHandler.php +++ b/code/model/flexiformhandlers/FlexiFormEmailHandler.php @@ -1,6 +1,6 @@ dataFieldByName('NotificationEmails'); $field->setDescription($this->getEmailFieldDescription()); - $fields->addFieldToTab('Root.Main', $field,'SuccessMessage'); + $fields->addFieldToTab('Root.Main', $field, 'SuccessMessage'); return $fields; } @@ -34,29 +34,30 @@ public function updateCMSFlexiTabs(TabSet $fields, TabSet $settings_tab, $flexi) $settings_tab->fieldByName($this->getSettingFieldName('NotificationEmails'))->setDescription($this->getEmailFieldDescription()); } - private function getEmailFieldDescription(){ - return 'Optional, comma separated list of email addresses that receive submission notifications.'; + private function getEmailFieldDescription() + { + return 'Optional, comma separated list of email addresses that receive submission notifications.'; } // Submission Handling ////////////////////// - public function onSubmit(Array $data, FlexiForm $form, SS_HTTPRequest $request, DataObject $flexi) + public function onSubmit(array $data, FlexiForm $form, SS_HTTPRequest $request, DataObject $flexi) { - if(parent::onSubmit($data, $form, $request, $flexi)) { - // extraplate emails and send notifications + if (parent::onSubmit($data, $form, $request, $flexi)) { + // extraplate emails and send notifications $emails = $flexi->FlexiFormSetting('NotificationEmails')->getValue(); - if(!empty($emails)) { + if (!empty($emails)) { //$from = $flexi->FlexiFormSetting('NotificationFromAddress')->getValue() ?: null; $email = new Email(null, $emails, 'Submission from form: ' . $flexi->FlexiFormID(), $this->getEmailBody()); - $email->sendPlain(); - } + $email->sendPlain(); + } - return true; - } + return true; + } - return false; + return false; } // Utility Methods @@ -65,8 +66,8 @@ protected function getEmailBody() { $body = "A visitor with the IP Address of submitted the following values: \r\n\n"; - foreach($this->submission->Values() as $value) { - $body .= "[{$value->Name}] : {$value->Value} \r\n"; + foreach ($this->submission->Values() as $value) { + $body .= "[{$value->Name}] : {$value->Value} \r\n"; } return $body; diff --git a/code/model/flexiformhandlers/settings/FlexiFormBooleanHandlerSetting.php b/code/model/flexiformhandlers/settings/FlexiFormBooleanHandlerSetting.php index 9f904be..632d4c5 100644 --- a/code/model/flexiformhandlers/settings/FlexiFormBooleanHandlerSetting.php +++ b/code/model/flexiformhandlers/settings/FlexiFormBooleanHandlerSetting.php @@ -1,6 +1,7 @@ 'Boolean' @@ -8,11 +9,11 @@ class FlexiFormBooleanHandlerSetting extends FlexiFormHandlerSetting { public function getCMSField($name) { - return new CheckboxField($name,null,$this->getValue()); + return new CheckboxField($name, null, $this->getValue()); } - public function getValue(){ + public function getValue() + { return (bool) parent::getValue(); } - -} \ No newline at end of file +} diff --git a/code/model/flexiformhandlers/settings/FlexiFormEnumHandlerSetting.php b/code/model/flexiformhandlers/settings/FlexiFormEnumHandlerSetting.php index 93e7c3c..a3ad224 100644 --- a/code/model/flexiformhandlers/settings/FlexiFormEnumHandlerSetting.php +++ b/code/model/flexiformhandlers/settings/FlexiFormEnumHandlerSetting.php @@ -1,19 +1,18 @@ Handler()) { - if($dbField = $handler->dbObject($name)) { + if ($handler = $this->Handler()) { + if ($dbField = $handler->dbObject($name)) { $source = $dbField->enumValues(); } } - return new DropdownField($name,null,$source,$this->getValue()); + return new DropdownField($name, null, $source, $this->getValue()); } - -} \ No newline at end of file +} diff --git a/code/model/flexiformhandlers/settings/FlexiFormFieldHandlerSetting.php b/code/model/flexiformhandlers/settings/FlexiFormFieldHandlerSetting.php index 46eac3f..2b2c476 100644 --- a/code/model/flexiformhandlers/settings/FlexiFormFieldHandlerSetting.php +++ b/code/model/flexiformhandlers/settings/FlexiFormFieldHandlerSetting.php @@ -1,21 +1,21 @@ FlexiFormConfig()) { - if($flexi = $config->getFlexi()) { + if ($config = $this->FlexiFormConfig()) { + if ($flexi = $config->getFlexi()) { $filter = $this->stat('allowed_field_types'); - foreach($flexi->FlexiFormFields() as $field){ - if(!empty($filter)) { - foreach($filter as $class) { - if($field->is_a($class)) { + foreach ($flexi->FlexiFormFields() as $field) { + if (!empty($filter)) { + foreach ($filter as $class) { + if ($field->is_a($class)) { $fields[$field->ID] = $field->Name; break; } @@ -27,7 +27,6 @@ public function getCMSField($name) } } - return new DropdownField($name,null,$fields,$this->getValue()); + return new DropdownField($name, null, $fields, $this->getValue()); } - -} \ No newline at end of file +} diff --git a/code/model/flexiformhandlers/settings/FlexiFormHTMLTextHandlerSetting.php b/code/model/flexiformhandlers/settings/FlexiFormHTMLTextHandlerSetting.php index 013d817..5e8cebb 100644 --- a/code/model/flexiformhandlers/settings/FlexiFormHTMLTextHandlerSetting.php +++ b/code/model/flexiformhandlers/settings/FlexiFormHTMLTextHandlerSetting.php @@ -11,4 +11,4 @@ public function getCMSField($name) { return new HtmlEditorField($name, null, $this->Value); } -} \ No newline at end of file +} diff --git a/code/model/flexiformhandlers/settings/FlexiFormHandlerSetting.php b/code/model/flexiformhandlers/settings/FlexiFormHandlerSetting.php index b4c7d31..150262d 100644 --- a/code/model/flexiformhandlers/settings/FlexiFormHandlerSetting.php +++ b/code/model/flexiformhandlers/settings/FlexiFormHandlerSetting.php @@ -20,7 +20,7 @@ class FlexiFormHandlerSetting extends DataObject // returns the setting field used to edit its value public function getCMSField($name) { - return new TextField($name,null,$this->getValue()); + return new TextField($name, null, $this->getValue()); } public function CastedValue() @@ -28,11 +28,13 @@ public function CastedValue() return DBField::create_field($this->stat('casting')['Value'], $this->getValue(), 'Value', $this); } - public function getValue(){ + public function getValue() + { return ($this->getField('Value')) ?: $this->Handler()->getField($this->Setting); } - public function forTemplate(){ + public function forTemplate() + { return $this->CastedValue()->forTemplate(); } @@ -40,5 +42,4 @@ public function __toString() { return $this->forTemplate(); } - -} \ No newline at end of file +} diff --git a/code/model/flexiformhandlers/settings/FlexiFormIntHandlerSetting.php b/code/model/flexiformhandlers/settings/FlexiFormIntHandlerSetting.php index 72c70dd..c04ff21 100644 --- a/code/model/flexiformhandlers/settings/FlexiFormIntHandlerSetting.php +++ b/code/model/flexiformhandlers/settings/FlexiFormIntHandlerSetting.php @@ -1,6 +1,7 @@ 'Int' @@ -8,11 +9,11 @@ class FlexiFormIntHandlerSetting extends FlexiFormHandlerSetting { public function getCMSField($name) { - return new NumericField($name,null,$this->getValue()); + return new NumericField($name, null, $this->getValue()); } - public function getValue(){ + public function getValue() + { return (int) parent::getValue(); } - -} \ No newline at end of file +} diff --git a/code/model/flexiformhandlers/settings/FlexiFormTextHandlerSetting.php b/code/model/flexiformhandlers/settings/FlexiFormTextHandlerSetting.php index ccd9bb5..69e3744 100644 --- a/code/model/flexiformhandlers/settings/FlexiFormTextHandlerSetting.php +++ b/code/model/flexiformhandlers/settings/FlexiFormTextHandlerSetting.php @@ -1,6 +1,7 @@ 'Text' @@ -10,5 +11,4 @@ public function getCMSField($name) { return new TextareaField($name, null, $this->Value); } - -} \ No newline at end of file +} diff --git a/code/util/FlexiFormUtil.php b/code/util/FlexiFormUtil.php index adaea11..f47c5f1 100644 --- a/code/util/FlexiFormUtil.php +++ b/code/util/FlexiFormUtil.php @@ -18,13 +18,14 @@ public static function include_requirements() Requirements::css($moduleDir . '/css/flexiform.css'); } - public static function GetFlexiByIdentifier($identifier){ - if(isset(self::$identifier_cache[$identifier])) { + public static function GetFlexiByIdentifier($identifier) + { + if (isset(self::$identifier_cache[$identifier])) { return self::$identifier_cache[$identifier]; } - if($config = FlexiFormConfig::get()->filter('FormIdentifier',$identifier)->first()) { - if($flexi = $config->getFlexi()) { + if ($config = FlexiFormConfig::get()->filter('FormIdentifier', $identifier)->first()) { + if ($flexi = $config->getFlexi()) { self::$identifier_cache[$identifier] = $flexi; return $flexi; } @@ -120,7 +121,6 @@ public static function AutoCreateFlexiField($className, $definition) // only create field if it's name doesn't yet exist if (! FlexiFormField::get()->filter($filter)->first()) { - if ($obj = FlexiFormUtil::CreateFlexiField($className, $definition)) { $prefix = ($obj->Readonly) ? 'Readonly' : 'Normal'; DB::alteration_message("flexiform - Created $prefix $className named `{$obj->FieldName}`.", @@ -173,12 +173,10 @@ public static function AutoCreateFlexiHandler($className, $definition) // only create handler it doesn't yet exist if (! FlexiFormHandler::get()->filter($filter)->first()) { - if ($obj = FlexiFormUtil::CreateFlexiHandler($className, $definition)) { DB::alteration_message("flexiform - Created $className named `{$obj->HandlerName}`.", "created"); } } } - }