From b66a61addb6c8e66cb26fcf74b532d68891267e4 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Wed, 23 May 2018 22:23:28 +0200 Subject: Refactored code, many fixes and improvements in chat backend+frontend --- .../app/sprinkles/FormGenerator/asset-bundles.json | 26 ++--- .../assets/js/widget-formGenerator.js | 101 ++++++++-------- main/app/sprinkles/FormGenerator/bower.json | 56 ++++----- main/app/sprinkles/FormGenerator/composer.json | 48 ++++---- .../FormGenerator/routes/FormGenerator.php | 2 +- .../src/Controller/FormGeneratorController.php | 4 +- .../sprinkles/FormGenerator/src/Element/Alert.php | 7 +- .../FormGenerator/src/Element/BaseInput.php | 12 +- .../FormGenerator/src/Element/Checkbox.php | 11 +- .../sprinkles/FormGenerator/src/Element/Hidden.php | 7 +- .../FormGenerator/src/Element/InputInterface.php | 7 +- .../sprinkles/FormGenerator/src/Element/Select.php | 7 +- .../sprinkles/FormGenerator/src/Element/Text.php | 7 +- .../FormGenerator/src/Element/Textarea.php | 7 +- main/app/sprinkles/FormGenerator/src/Form.php | 40 +++---- .../FormGenerator/FormGenerator.html.twig | 34 +++--- .../templates/FormGenerator/confirm.html.twig | 52 +++++---- .../templates/FormGenerator/macros/alert.html.twig | 4 +- .../FormGenerator/macros/checkbox.html.twig | 2 +- .../FormGenerator/macros/hidden.html.twig | 2 +- .../FormGenerator/macros/select.html.twig | 6 +- .../templates/FormGenerator/macros/text.html.twig | 10 +- .../FormGenerator/macros/textarea.html.twig | 5 +- .../templates/FormGenerator/modal.html.twig | 93 +++++++-------- .../templates/FormGenerator/typehead.html.twig | 20 ++-- .../FormGenerator/tests/Unit/FormGeneratorTest.php | 28 ++--- .../FormGenerator/tests/Unit/data/bad.json | 18 +-- .../FormGenerator/tests/Unit/data/good.json | 128 ++++++++++----------- 28 files changed, 381 insertions(+), 363 deletions(-) (limited to 'main/app/sprinkles/FormGenerator') diff --git a/main/app/sprinkles/FormGenerator/asset-bundles.json b/main/app/sprinkles/FormGenerator/asset-bundles.json index b763d55..43ea863 100644 --- a/main/app/sprinkles/FormGenerator/asset-bundles.json +++ b/main/app/sprinkles/FormGenerator/asset-bundles.json @@ -1,17 +1,17 @@ { - "bundle": { - "js/FormGenerator": { - "scripts": [ - "vendor/bootstrap3-typeahead/bootstrap3-typeahead.js", - "js/widget-formGenerator.js" - ], - "options": { - "result": { - "type": { - "scripts": "plain" - } - } - } + "bundle": { + "js/FormGenerator": { + "scripts": [ + "vendor/bootstrap3-typeahead/bootstrap3-typeahead.js", + "js/widget-formGenerator.js" + ], + "options": { + "result": { + "type": { + "scripts": "plain" + } } + } } + } } diff --git a/main/app/sprinkles/FormGenerator/assets/js/widget-formGenerator.js b/main/app/sprinkles/FormGenerator/assets/js/widget-formGenerator.js index 52743f6..6cfcce8 100644 --- a/main/app/sprinkles/FormGenerator/assets/js/widget-formGenerator.js +++ b/main/app/sprinkles/FormGenerator/assets/js/widget-formGenerator.js @@ -10,20 +10,20 @@ * @license MIT */ -;(function($, window, document, undefined) { - "use strict"; +;(function ($, window, document, undefined) { + "use strict"; // Define plugin name and defaults. var pluginName = "formGenerator", defaults = { - DEBUG : false, - mainAlertElement : $('#alerts-page'), - redirectAfterSuccess : true, - autofocusModalElement : true + DEBUG: false, + mainAlertElement: $('#alerts-page'), + redirectAfterSuccess: true, + autofocusModalElement: true }; // Constructor - function Plugin (element, options) { + function Plugin(element, options) { this.elements = element; this.$elements = $(this.elements); this.settings = $.extend(true, {}, defaults, options); @@ -31,7 +31,11 @@ this._name = pluginName; // Detect changes to element attributes - this.$elements.attrchange({ callback: function (event) { this.elements = event.target; }.bind(this) }); + this.$elements.attrchange({ + callback: function (event) { + this.elements = event.target; + }.bind(this) + }); // Initialise ufAlerts if (!this.settings.mainAlertElement.data('ufAlerts')) { @@ -46,21 +50,21 @@ /** * Bind the display action for a form to the button */ - display: function() { + display: function () { this.$elements.on('click', $.proxy(this._fetchForm, this)); return this.$elements; }, /** * Bind the confirm action to the button */ - confirm: function() { + confirm: function () { this.$elements.on('click', $.proxy(this._fetchConfirmModal, this)); return this.$elements; }, /** * Fetch the form HTML */ - _fetchForm: function(event) { + _fetchForm: function (event) { // Get the button element var button = event.currentTarget; @@ -72,14 +76,15 @@ } // Delete any existing instance of the form with the same name - if($('#' + box_id).length) { + if ($('#' + box_id).length) { $('#' + box_id).remove(); } // Prepare the ajax payload var payload = $.extend({ - box_id: box_id} - , button.dataset); + box_id: box_id + } + , button.dataset); // Fetch and render the form $.ajax({ @@ -88,19 +93,19 @@ data: payload, cache: false }) - .done($.proxy(this._displayForm, this, box_id, button)) - .fail($.proxy(this._displayFailure, this, button)); + .done($.proxy(this._displayForm, this, box_id, button)) + .fail($.proxy(this._displayFailure, this, button)); }, /** * Displays the form modal and set up ufForm */ - _displayForm: function(box_id, button, data) { + _displayForm: function (box_id, button, data) { // Trigger pre-display event $(button).trigger("displayForm." + this._name); // Append the form as a modal dialog to the body - $( "body" ).append(data); + $("body").append(data); $('#' + box_id).modal('show'); // Set focus on first element @@ -111,7 +116,7 @@ } // Setup ufAlerts - var boxMsgTarget = $("#"+box_id+" #form-alerts"); + var boxMsgTarget = $("#" + box_id + " #form-alerts"); // Show the alert. We could have info alert coming in if (!boxMsgTarget.data('ufAlerts')) { @@ -122,15 +127,15 @@ // Setup the loaded form with ufForm $('#' + box_id).find("form").ufForm({ validators: validators, - msgTarget: $("#"+box_id+" #form-alerts") + msgTarget: $("#" + box_id + " #form-alerts") }) - .on("submitSuccess.ufForm", $.proxy(this._formPostSuccess, this, box_id, button)) - .on("submitError.ufForm", $.proxy(this._displayFormFaillure, this, box_id, button)); + .on("submitSuccess.ufForm", $.proxy(this._formPostSuccess, this, box_id, button)) + .on("submitError.ufForm", $.proxy(this._displayFormFaillure, this, box_id, button)); }, /** * Action done when a form is successful */ - _formPostSuccess: function(box_id, button, event, data) { + _formPostSuccess: function (box_id, button, event, data) { // Trigger success event $(button).trigger("formSuccess." + this._name, data); @@ -146,7 +151,7 @@ /** * Fetch confirmation modal */ - _fetchConfirmModal: function(event) { + _fetchConfirmModal: function (event) { // Get the button element var button = event.currentTarget; @@ -158,7 +163,7 @@ } // Delete any existing instance of the form with the same name - if($('#' + box_id).length) { + if ($('#' + box_id).length) { $('#' + box_id).remove(); } @@ -179,19 +184,19 @@ data: payload, cache: false }) - .done($.proxy(this._displayConfirmation, this, box_id, button)) - .fail($.proxy(this._displayFailure, this, button)); + .done($.proxy(this._displayConfirmation, this, box_id, button)) + .fail($.proxy(this._displayFailure, this, button)); }, /** * Display confirmation modal */ - _displayConfirmation: function(box_id, button, data) { + _displayConfirmation: function (box_id, button, data) { // Trigger pre-display event $(button).trigger("displayConfirmation." + this._name); // Append the form as a modal dialog to the body - $( "body" ).append(data); + $("body").append(data); $('#' + box_id).modal('show'); $('#' + box_id + ' .js-confirm').on('click', $.proxy(this._sendConfirmation, this, box_id, button)); @@ -199,7 +204,7 @@ /** * Send confirmation query */ - _sendConfirmation: function(box_id, button) { + _sendConfirmation: function (box_id, button) { // Prepare payload var url = $(button).data('postUrl'); @@ -212,17 +217,17 @@ // Send ajax $.ajax({ - type: method, - url: url, - data: data + type: method, + url: url, + data: data }) - .done($.proxy(this._confirmationSuccess, this, box_id, button)) - .fail($.proxy(this._displayConfirmationFaillure, this, box_id, button)); + .done($.proxy(this._confirmationSuccess, this, box_id, button)) + .fail($.proxy(this._displayConfirmationFaillure, this, box_id, button)); }, - /** + /** * Action done when a confirmation request is successful */ - _confirmationSuccess: function(box_id, button, data) { + _confirmationSuccess: function (box_id, button, data) { // Trigger success event $(button).trigger("confirmSuccess." + this._name, data); @@ -244,14 +249,14 @@ /** * Failure callback for ajax requests. Displays the error in the main alertElement */ - _displayFailure: function(button, response) { + _displayFailure: function (button, response) { $(button).trigger("error." + this._name); if ((typeof site !== "undefined") && site.debug.ajax && response.responseText) { document.write(response.responseText); document.close(); } else { if (this.settings.DEBUG) { - $.error("Error (" + response.status + "): " + response.responseText ); + $.error("Error (" + response.status + "): " + response.responseText); } this.settings.mainAlertElement.ufAlerts('clear').ufAlerts('fetch').ufAlerts('render'); } @@ -259,18 +264,18 @@ /** * Faillure callback for ajax requests to be displayed in a modal form */ - _displayFormFaillure: function(box_id, button) { + _displayFormFaillure: function (box_id, button) { $(button).trigger("error." + this._name); - $("#"+box_id+" #form-alerts").show(); + $("#" + box_id + " #form-alerts").show(); }, /** * Faillure callback for ajax requests to be displayed in a confirmation form */ - _displayConfirmationFaillure: function(box_id, button) { + _displayConfirmationFaillure: function (box_id, button) { $(button).trigger("error." + this._name); // Setup ufAlerts - var boxMsgTarget = $("#"+box_id+" #confirmation-alerts"); + var boxMsgTarget = $("#" + box_id + " #confirmation-alerts"); // Show the alert. We could have info alert coming in if (!boxMsgTarget.data('ufAlerts')) { @@ -281,7 +286,7 @@ /** * Completely destroy the ufAlerts plugin on the element. */ - destroy: function() { + destroy: function () { // Unbind any bound events this.$elements.off('.' + this._name); @@ -296,7 +301,7 @@ }); // Handles instantiation and access to non-private methods. - $.fn[pluginName] = function(methodOrOptions) { + $.fn[pluginName] = function (methodOrOptions) { // If the plugin is called on a non existing element, return nothing if (this.length == 0) { @@ -319,11 +324,11 @@ var options = Array.prototype.slice.call(arguments, 1)[0]; } else { - $.error( 'Method ' + methodOrOptions + ' is private!' ); + $.error('Method ' + methodOrOptions + ' is private!'); } } else { - $.error( 'Method ' + methodOrOptions + ' is invalid.' ); + $.error('Method ' + methodOrOptions + ' is invalid.'); } // Only initalise if not previously done. @@ -337,7 +342,7 @@ // Run the required method return instance[method](options); } else { - $.error( 'Method ' + method + ' does not exist.' ); + $.error('Method ' + method + ' does not exist.'); } }; diff --git a/main/app/sprinkles/FormGenerator/bower.json b/main/app/sprinkles/FormGenerator/bower.json index 723b5cc..6ce7156 100644 --- a/main/app/sprinkles/FormGenerator/bower.json +++ b/main/app/sprinkles/FormGenerator/bower.json @@ -1,30 +1,30 @@ { - "name": "formgenerator-assets", - "version": "0.0.1", - "homepage": "https://github.com/lcharette/UF_FormGenerator", - "authors": [ - "lcharette" - ], - "moduleType": [ - "node" - ], - "license": "MIT", - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "assets/vendor", - "examples", - "demo-resources", - "demo", - "test", - "tests" - ], - "dependencies": { - "bootstrap3-typeahead": "~3.1.0" - }, - "resolutions": { - "jquery": ">= 2.2.4", - "bootstrap": "3.x" - } + "name": "formgenerator-assets", + "version": "0.0.1", + "homepage": "https://github.com/lcharette/UF_FormGenerator", + "authors": [ + "lcharette" + ], + "moduleType": [ + "node" + ], + "license": "MIT", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "assets/vendor", + "examples", + "demo-resources", + "demo", + "test", + "tests" + ], + "dependencies": { + "bootstrap3-typeahead": "~3.1.0" + }, + "resolutions": { + "jquery": ">= 2.2.4", + "bootstrap": "3.x" + } } diff --git a/main/app/sprinkles/FormGenerator/composer.json b/main/app/sprinkles/FormGenerator/composer.json index e37a372..797e029 100644 --- a/main/app/sprinkles/FormGenerator/composer.json +++ b/main/app/sprinkles/FormGenerator/composer.json @@ -1,25 +1,29 @@ { - "name": "lcharette/uf_formgenerator", - "type": "userfrosting-sprinkle", - "description": "Form generator for UserFrosting V4", - "keywords": ["Form", "generator", "userfrosting"], - "homepage": "https://github.com/lcharette/UF_FormGenerator", - "license" : "MIT", - "authors" : [ - { - "name": "Louis Charette", - "homepage": "https://github.com/lcharette" - } - ], - "require": { - "php": ">=5.6" - }, - "autoload": { - "psr-4": { - "UserFrosting\\Sprinkle\\FormGenerator\\": "src/" - } - }, - "extra": { - "installer-name": "FormGenerator" + "name": "lcharette/uf_formgenerator", + "type": "userfrosting-sprinkle", + "description": "Form generator for UserFrosting V4", + "keywords": [ + "Form", + "generator", + "userfrosting" + ], + "homepage": "https://github.com/lcharette/UF_FormGenerator", + "license": "MIT", + "authors": [ + { + "name": "Louis Charette", + "homepage": "https://github.com/lcharette" } + ], + "require": { + "php": ">=5.6" + }, + "autoload": { + "psr-4": { + "UserFrosting\\Sprinkle\\FormGenerator\\": "src/" + } + }, + "extra": { + "installer-name": "FormGenerator" + } } diff --git a/main/app/sprinkles/FormGenerator/routes/FormGenerator.php b/main/app/sprinkles/FormGenerator/routes/FormGenerator.php index 0b7ea51..c770793 100644 --- a/main/app/sprinkles/FormGenerator/routes/FormGenerator.php +++ b/main/app/sprinkles/FormGenerator/routes/FormGenerator.php @@ -9,4 +9,4 @@ global $app; -$app->get('/forms/confirm','UserFrosting\Sprinkle\FormGenerator\Controller\FormGeneratorController:confirm'); \ No newline at end of file +$app->get('/forms/confirm', 'UserFrosting\Sprinkle\FormGenerator\Controller\FormGeneratorController:confirm'); \ No newline at end of file diff --git a/main/app/sprinkles/FormGenerator/src/Controller/FormGeneratorController.php b/main/app/sprinkles/FormGenerator/src/Controller/FormGeneratorController.php index e731011..5bd46e1 100644 --- a/main/app/sprinkles/FormGenerator/src/Controller/FormGeneratorController.php +++ b/main/app/sprinkles/FormGenerator/src/Controller/FormGeneratorController.php @@ -6,6 +6,7 @@ * @copyright Copyright (c) 2017 Louis Charette * @license https://github.com/lcharette/UF_FormGenerator/blob/master/LICENSE (MIT License) */ + namespace UserFrosting\Sprinkle\FormGenerator\Controller; use UserFrosting\Sprinkle\Core\Controller\SimpleController; @@ -15,7 +16,8 @@ use UserFrosting\Sprinkle\Core\Controller\SimpleController; * * Controller class for /forms/confirm/* URLs. Handles rendering the confirm dialog */ -class FormGeneratorController extends SimpleController { +class FormGeneratorController extends SimpleController +{ /** * Display the confirmation dialog diff --git a/main/app/sprinkles/FormGenerator/src/Element/Alert.php b/main/app/sprinkles/FormGenerator/src/Element/Alert.php index f848b5c..31453d3 100644 --- a/main/app/sprinkles/FormGenerator/src/Element/Alert.php +++ b/main/app/sprinkles/FormGenerator/src/Element/Alert.php @@ -6,6 +6,7 @@ * @copyright Copyright (c) 2017 Louis Charette * @license https://github.com/lcharette/UF_FormGenerator/blob/master/LICENSE (MIT License) */ + namespace UserFrosting\Sprinkle\FormGenerator\Element; use UserFrosting\Sprinkle\FormGenerator\Element\BaseInput; @@ -16,13 +17,13 @@ use UserFrosting\Sprinkle\FormGenerator\Element\BaseInput; * * @extends BaseInput */ -class Alert extends BaseInput { +class Alert extends BaseInput +{ /** * {@inheritDoc} */ - protected function applyTransformations() - { + protected function applyTransformations() { $this->element = array_merge([ "class" => "alert-danger", "icon" => "fa-ban", diff --git a/main/app/sprinkles/FormGenerator/src/Element/BaseInput.php b/main/app/sprinkles/FormGenerator/src/Element/BaseInput.php index d892001..cf78dc6 100644 --- a/main/app/sprinkles/FormGenerator/src/Element/BaseInput.php +++ b/main/app/sprinkles/FormGenerator/src/Element/BaseInput.php @@ -6,6 +6,7 @@ * @copyright Copyright (c) 2017 Louis Charette * @license https://github.com/lcharette/UF_FormGenerator/blob/master/LICENSE (MIT License) */ + namespace UserFrosting\Sprinkle\FormGenerator\Element; use UserFrosting\Sprinkle\FormGenerator\Element\InputInterface; @@ -20,7 +21,8 @@ use UserFrosting\Sprinkle\Core\Facades\Debug; * @abstract * @implements InputInterface */ -abstract class BaseInput implements InputInterface { +abstract class BaseInput implements InputInterface +{ /** * @var String The name of the input. @@ -46,8 +48,7 @@ abstract class BaseInput implements InputInterface { * @param mixed $value (default: null) * @return void */ - public function __construct($name, $element, $value = null) - { + public function __construct($name, $element, $value = NULL) { $this->name = $name; $this->element = $element; $this->value = $value; @@ -60,8 +61,7 @@ abstract class BaseInput implements InputInterface { * @access public * @return void */ - public function parse() - { + public function parse() { $this->applyTransformations(); return $this->element; } @@ -89,7 +89,7 @@ abstract class BaseInput implements InputInterface { * @return string The input current value */ public function getValue() { - if (isset($this->value) && $this->value !== null) { + if (isset($this->value) && $this->value !== NULL) { return $this->value; } else if (isset($this->element['default'])) { return $this->element['default']; diff --git a/main/app/sprinkles/FormGenerator/src/Element/Checkbox.php b/main/app/sprinkles/FormGenerator/src/Element/Checkbox.php index 59e6eaf..97bfdba 100644 --- a/main/app/sprinkles/FormGenerator/src/Element/Checkbox.php +++ b/main/app/sprinkles/FormGenerator/src/Element/Checkbox.php @@ -6,6 +6,7 @@ * @copyright Copyright (c) 2017 Louis Charette * @license https://github.com/lcharette/UF_FormGenerator/blob/master/LICENSE (MIT License) */ + namespace UserFrosting\Sprinkle\FormGenerator\Element; use UserFrosting\Sprinkle\FormGenerator\Element\BaseInput; @@ -16,22 +17,22 @@ use UserFrosting\Sprinkle\FormGenerator\Element\BaseInput; * * @extends BaseInput */ -class Checkbox extends BaseInput { +class Checkbox extends BaseInput +{ /** * {@inheritDoc} */ - protected function applyTransformations() - { + protected function applyTransformations() { $this->element = array_merge([ "class" => "js-icheck", "name" => $this->name, "id" => "field_" . $this->name, - "binary" => true + "binary" => TRUE ], $this->element); // We add the check status instead of the value - if ($this->element["binary"] !== false && $this->getValue() == 1) { + if ($this->element["binary"] !== FALSE && $this->getValue() == 1) { $this->element["checked"] = "checked"; } } diff --git a/main/app/sprinkles/FormGenerator/src/Element/Hidden.php b/main/app/sprinkles/FormGenerator/src/Element/Hidden.php index 08c22f7..6f79ecd 100644 --- a/main/app/sprinkles/FormGenerator/src/Element/Hidden.php +++ b/main/app/sprinkles/FormGenerator/src/Element/Hidden.php @@ -6,6 +6,7 @@ * @copyright Copyright (c) 2017 Louis Charette * @license https://github.com/lcharette/UF_FormGenerator/blob/master/LICENSE (MIT License) */ + namespace UserFrosting\Sprinkle\FormGenerator\Element; use UserFrosting\Sprinkle\FormGenerator\Element\BaseInput; @@ -16,13 +17,13 @@ use UserFrosting\Sprinkle\FormGenerator\Element\BaseInput; * * @extends BaseInput */ -class Hidden extends BaseInput { +class Hidden extends BaseInput +{ /** * {@inheritDoc} */ - protected function applyTransformations() - { + protected function applyTransformations() { $this->element = array_merge([ "value" => $this->getValue(), "name" => $this->name, diff --git a/main/app/sprinkles/FormGenerator/src/Element/InputInterface.php b/main/app/sprinkles/FormGenerator/src/Element/InputInterface.php index 7405109..66225bc 100644 --- a/main/app/sprinkles/FormGenerator/src/Element/InputInterface.php +++ b/main/app/sprinkles/FormGenerator/src/Element/InputInterface.php @@ -6,6 +6,7 @@ * @copyright Copyright (c) 2017 Louis Charette * @license https://github.com/lcharette/UF_FormGenerator/blob/master/LICENSE (MIT License) */ + namespace UserFrosting\Sprinkle\FormGenerator\Element; /** @@ -13,7 +14,9 @@ namespace UserFrosting\Sprinkle\FormGenerator\Element; * * Interface for Form elements classes */ -interface InputInterface { - public function __construct($name, $element, $value = null); +interface InputInterface +{ + public function __construct($name, $element, $value = NULL); + public function parse(); } diff --git a/main/app/sprinkles/FormGenerator/src/Element/Select.php b/main/app/sprinkles/FormGenerator/src/Element/Select.php index bb23772..da91fbd 100644 --- a/main/app/sprinkles/FormGenerator/src/Element/Select.php +++ b/main/app/sprinkles/FormGenerator/src/Element/Select.php @@ -6,6 +6,7 @@ * @copyright Copyright (c) 2017 Louis Charette * @license https://github.com/lcharette/UF_FormGenerator/blob/master/LICENSE (MIT License) */ + namespace UserFrosting\Sprinkle\FormGenerator\Element; use UserFrosting\Sprinkle\FormGenerator\Element\BaseInput; @@ -16,13 +17,13 @@ use UserFrosting\Sprinkle\FormGenerator\Element\BaseInput; * * @extends BaseInput */ -class Select extends BaseInput { +class Select extends BaseInput +{ /** * {@inheritDoc} */ - protected function applyTransformations() - { + protected function applyTransformations() { $this->element = array_merge([ "class" => "form-control js-select2", "value" => $this->getValue(), diff --git a/main/app/sprinkles/FormGenerator/src/Element/Text.php b/main/app/sprinkles/FormGenerator/src/Element/Text.php index b936fe2..375153d 100644 --- a/main/app/sprinkles/FormGenerator/src/Element/Text.php +++ b/main/app/sprinkles/FormGenerator/src/Element/Text.php @@ -6,6 +6,7 @@ * @copyright Copyright (c) 2017 Louis Charette * @license https://github.com/lcharette/UF_FormGenerator/blob/master/LICENSE (MIT License) */ + namespace UserFrosting\Sprinkle\FormGenerator\Element; use UserFrosting\Sprinkle\FormGenerator\Element\BaseInput; @@ -16,13 +17,13 @@ use UserFrosting\Sprinkle\FormGenerator\Element\BaseInput; * * @extends BaseInput */ -class Text extends BaseInput { +class Text extends BaseInput +{ /** * {@inheritDoc} */ - protected function applyTransformations() - { + protected function applyTransformations() { $this->element = array_merge([ "autocomplete" => "off", "class" => "form-control", diff --git a/main/app/sprinkles/FormGenerator/src/Element/Textarea.php b/main/app/sprinkles/FormGenerator/src/Element/Textarea.php index bec3a6c..b2a84f9 100644 --- a/main/app/sprinkles/FormGenerator/src/Element/Textarea.php +++ b/main/app/sprinkles/FormGenerator/src/Element/Textarea.php @@ -6,6 +6,7 @@ * @copyright Copyright (c) 2017 Louis Charette * @license https://github.com/lcharette/UF_FormGenerator/blob/master/LICENSE (MIT License) */ + namespace UserFrosting\Sprinkle\FormGenerator\Element; use UserFrosting\Sprinkle\FormGenerator\Element\BaseInput; @@ -16,13 +17,13 @@ use UserFrosting\Sprinkle\FormGenerator\Element\BaseInput; * * @extends BaseInput */ -class Textarea extends BaseInput { +class Textarea extends BaseInput +{ /** * {@inheritDoc} */ - protected function applyTransformations() - { + protected function applyTransformations() { $this->element = array_merge([ "autocomplete" => "off", "class" => "form-control", diff --git a/main/app/sprinkles/FormGenerator/src/Form.php b/main/app/sprinkles/FormGenerator/src/Form.php index e845e3e..5b948f7 100644 --- a/main/app/sprinkles/FormGenerator/src/Form.php +++ b/main/app/sprinkles/FormGenerator/src/Form.php @@ -6,6 +6,7 @@ * @copyright Copyright (c) 2017 Louis Charette * @license https://github.com/lcharette/UF_FormGenerator/blob/master/LICENSE (MIT License) */ + namespace UserFrosting\Sprinkle\FormGenerator; use Illuminate\Contracts\Config\Repository; @@ -20,7 +21,8 @@ use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface; * The FormGenerator class, which is used to return the `form` part from a Fortress * schema for html form generator in Twig. */ -class Form { +class Form +{ /** * @var RequestSchemaInterface The form fields definition @@ -44,8 +46,7 @@ class Form { * @param array|object $data (default: []) * @return void */ - public function __construct(RequestSchemaInterface $schema, $data = []) - { + public function __construct(RequestSchemaInterface $schema, $data = []) { $this->setSchema($schema); $this->setData($data); } @@ -55,8 +56,7 @@ class Form { * * @param array|object $data The form values */ - public function setData($data) - { + public function setData($data) { if ($data instanceof Collection || $data instanceof Model) { $this->data = $data->toArray(); } else if (is_array($data) || $data instanceof Repository) { @@ -71,8 +71,7 @@ class Form { * * @param RequestSchemaInterface $schema A RequestSchemaInterface object, containing the form definition. */ - public function setSchema(RequestSchemaInterface $schema) - { + public function setSchema(RequestSchemaInterface $schema) { $this->schema = $schema; } @@ -83,8 +82,7 @@ class Form { * @param mixed $value * @return void */ - public function setValue($inputName, $value) - { + public function setValue($inputName, $value) { $this->data[$inputName] = $value; } @@ -94,12 +92,11 @@ class Form { * Use `setCustomFormData` to set any other tag. * * @param string $inputName The input name where the argument will be added - * @param string $property The argument name. Example "data-color" - * @param string $data The value of the argument + * @param string $property The argument name. Example "data-color" + * @param string $data The value of the argument * @return void */ - public function setInputArgument($inputName, $property, $data) - { + public function setInputArgument($inputName, $property, $data) { if ($this->schema->has($inputName)) { // Get the element and force set the property $element = $this->schema->get($inputName); @@ -115,12 +112,11 @@ class Form { * `setInputArgument` and `setValue`. * * @param string $inputName The select name to add options to - * @param array $data An array of `value => label` options - * @param string $selected The selected key + * @param array $data An array of `value => label` options + * @param string $selected The selected key * @return void */ - public function setOptions($inputName, $data = [], $selected = null) - { + public function setOptions($inputName, $data = [], $selected = NULL) { // Set opdations $this->setInputArgument($inputName, 'options', $data); @@ -139,8 +135,7 @@ class Form { * @param string $namespace * @return void */ - public function setFormNamespace($namespace) - { + public function setFormNamespace($namespace) { $this->formNamespace = $namespace; } @@ -150,8 +145,7 @@ class Form { * * @return array The form fields data */ - public function generate() - { + public function generate() { $form = collect([]); // Loop all the the fields in the schema @@ -161,10 +155,10 @@ class Form { if (isset($input['form'])) { // Get the value from the data - $value = isset($this->data[$name]) ? $this->data[$name] : null; + $value = isset($this->data[$name]) ? $this->data[$name] : NULL; // Add the namespace to the name if it's defined - $name = ($this->formNamespace != "") ? $this->formNamespace."[".$name."]" : $name; + $name = ($this->formNamespace != "") ? $this->formNamespace . "[" . $name . "]" : $name; // Get the element class and make sure it exist $type = (isset($input['form']['type'])) ? $input['form']['type'] : "text"; diff --git a/main/app/sprinkles/FormGenerator/templates/FormGenerator/FormGenerator.html.twig b/main/app/sprinkles/FormGenerator/templates/FormGenerator/FormGenerator.html.twig index c902064..688c96c 100644 --- a/main/app/sprinkles/FormGenerator/templates/FormGenerator/FormGenerator.html.twig +++ b/main/app/sprinkles/FormGenerator/templates/FormGenerator/FormGenerator.html.twig @@ -12,22 +12,24 @@ {{ alert.generate(input) }} {% else %} {% if not input.hidden %} -
- {% if formLayout == 'horizontal' %}
+
+ {% if formLayout == 'horizontal' %}
{% endif %} {% endif %} {% endfor %} \ No newline at end of file diff --git a/main/app/sprinkles/FormGenerator/templates/FormGenerator/confirm.html.twig b/main/app/sprinkles/FormGenerator/templates/FormGenerator/confirm.html.twig index 96d0072..67ba757 100644 --- a/main/app/sprinkles/FormGenerator/templates/FormGenerator/confirm.html.twig +++ b/main/app/sprinkles/FormGenerator/templates/FormGenerator/confirm.html.twig @@ -1,28 +1,30 @@ -