From 35a0142cac960ea864fe2ec5da1cc44d5d235ef7 Mon Sep 17 00:00:00 2001 From: Michal Lulco Date: Thu, 28 Mar 2019 10:46:50 +0100 Subject: [PATCH 1/2] Updated version of nette/forms --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 22f3896..26ff2a2 100644 --- a/composer.json +++ b/composer.json @@ -11,8 +11,8 @@ } ], "require": { - "php": ">= 5.3.7", - "nette/forms": "~2.3" + "php": ">= 7.1.0", + "nette/forms": "^2.3 | ^3.0" }, "autoload": { "classmap": [ From 906ea2005db237222f27f3b7c8d82b3aab4a44d6 Mon Sep 17 00:00:00 2001 From: Michal Lulco Date: Thu, 28 Mar 2019 11:56:09 +0100 Subject: [PATCH 2/2] Update renderers --- composer.json | 2 +- src/BootstrapInlineRenderer.php | 72 +++++++++++++++--------------- src/BootstrapRenderer.php | 72 +++++++++++++++--------------- src/BootstrapVerticalRenderer.php | 74 +++++++++++++++---------------- 4 files changed, 110 insertions(+), 110 deletions(-) diff --git a/composer.json b/composer.json index 26ff2a2..b568cce 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require": { "php": ">= 7.1.0", - "nette/forms": "^2.3 | ^3.0" + "nette/forms": "^3.0" }, "autoload": { "classmap": [ diff --git a/src/BootstrapInlineRenderer.php b/src/BootstrapInlineRenderer.php index 20bee86..33060bd 100644 --- a/src/BootstrapInlineRenderer.php +++ b/src/BootstrapInlineRenderer.php @@ -2,36 +2,42 @@ namespace Tomaj\Form\Renderer; -use Nette; +use Nette\Forms\Controls\Button; +use Nette\Forms\Controls\Checkbox; +use Nette\Forms\Controls\CheckboxList; +use Nette\Forms\Controls\MultiSelectBox; +use Nette\Forms\Controls\RadioList; +use Nette\Forms\Controls\SelectBox; +use Nette\Forms\Controls\TextBase; +use Nette\Forms\Form; use Nette\Forms\Rendering\DefaultFormRenderer; -use Nette\Forms\Controls; class BootstrapInlineRenderer extends DefaultFormRenderer { - public $wrappers = array( - 'form' => array( + public $wrappers = [ + 'form' => [ 'container' => '', - ), - 'error' => array( + ], + 'error' => [ 'container' => 'div class="alert alert-danger"', 'item' => 'p', - ), - 'group' => array( + ], + 'group' => [ 'container' => 'fieldset', 'label' => 'legend', 'description' => 'p', - ), - 'controls' => array( + ], + 'controls' => [ 'container' => '', - ), - 'pair' => array( + ], + 'pair' => [ 'container' => 'div class=form-group', '.required' => 'required', '.optional' => null, '.odd' => null, '.error' => 'has-error', - ), - 'control' => array( + ], + 'control' => [ 'container' => null, '.odd' => null, 'description' => 'span class=help-block', @@ -45,32 +51,26 @@ class BootstrapInlineRenderer extends DefaultFormRenderer '.submit' => 'button', '.image' => 'imagebutton', '.button' => 'button', - ), - 'label' => array( + ], + 'label' => [ 'container' => '', 'suffix' => null, 'requiredsuffix' => '', - ), - 'hidden' => array( + ], + 'hidden' => [ 'container' => 'div', - ), - ); + ], + ]; /** @var bool */ private $novalidate; - public function __construct($novalidate = true) + public function __construct(bool $novalidate = true) { $this->novalidate = $novalidate; } - /** - * Provides complete form rendering. - * @param Nette\Forms\Form - * @param string 'begin', 'errors', 'ownerrors', 'body', 'end' or empty to render all - * @return string - */ - public function render(Nette\Forms\Form $form, $mode = null) + public function render(Form $form, string $mode = null): string { $form->getElementPrototype()->addClass('form-inline'); @@ -79,18 +79,18 @@ public function render(Nette\Forms\Form $form, $mode = null) } foreach ($form->getControls() as $control) { - if ($control instanceof Controls\Button) { - if (strpos($control->getControlPrototype()->getClass(), 'btn') === FALSE) { + if ($control instanceof Button) { + if (strpos($control->getControlPrototype()->getClass(), 'btn') === false) { $control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn btn-default'); $usedPrimary = true; } - } elseif ($control instanceof Controls\TextBase || - $control instanceof Controls\SelectBox || - $control instanceof Controls\MultiSelectBox) { + } elseif ($control instanceof TextBase || + $control instanceof SelectBox || + $control instanceof MultiSelectBox) { $control->getControlPrototype()->addClass('form-control'); - } elseif ($control instanceof Controls\Checkbox || - $control instanceof Controls\CheckboxList || - $control instanceof Controls\RadioList) { + } elseif ($control instanceof Checkbox || + $control instanceof CheckboxList || + $control instanceof RadioList) { $control->getSeparatorPrototype()->setName('div')->addClass($control->getControlPrototype()->type); } } diff --git a/src/BootstrapRenderer.php b/src/BootstrapRenderer.php index 6a4da5f..ecbc7d6 100644 --- a/src/BootstrapRenderer.php +++ b/src/BootstrapRenderer.php @@ -2,36 +2,42 @@ namespace Tomaj\Form\Renderer; -use Nette; +use Nette\Forms\Controls\Button; +use Nette\Forms\Controls\Checkbox; +use Nette\Forms\Controls\CheckboxList; +use Nette\Forms\Controls\MultiSelectBox; +use Nette\Forms\Controls\RadioList; +use Nette\Forms\Controls\SelectBox; +use Nette\Forms\Controls\TextBase; +use Nette\Forms\Form; use Nette\Forms\Rendering\DefaultFormRenderer; -use Nette\Forms\Controls; class BootstrapRenderer extends DefaultFormRenderer { - public $wrappers = array( - 'form' => array( + public $wrappers = [ + 'form' => [ 'container' => null, - ), - 'error' => array( + ], + 'error' => [ 'container' => 'div class="alert alert-danger"', 'item' => 'p', - ), - 'group' => array( + ], + 'group' => [ 'container' => 'fieldset', 'label' => 'legend', 'description' => 'p', - ), - 'controls' => array( + ], + 'controls' => [ 'container' => 'div', - ), - 'pair' => array( + ], + 'pair' => [ 'container' => 'div class=form-group', '.required' => 'required', '.optional' => null, '.odd' => null, '.error' => 'has-error', - ), - 'control' => array( + ], + 'control' => [ 'container' => 'div class=col-sm-9', '.odd' => null, 'description' => 'span class=help-block', @@ -45,32 +51,26 @@ class BootstrapRenderer extends DefaultFormRenderer '.submit' => 'button', '.image' => 'imagebutton', '.button' => 'button', - ), - 'label' => array( + ], + 'label' => [ 'container' => 'div class="col-sm-3 control-label"', 'suffix' => null, 'requiredsuffix' => '', - ), - 'hidden' => array( + ], + 'hidden' => [ 'container' => 'div', - ), - ); + ], + ]; /** @var bool */ private $novalidate; - public function __construct($novalidate = true) + public function __construct(bool $novalidate = true) { $this->novalidate = $novalidate; } - /** - * Provides complete form rendering. - * @param Nette\Forms\Form - * @param string 'begin', 'errors', 'ownerrors', 'body', 'end' or empty to render all - * @return string - */ - public function render(Nette\Forms\Form $form, $mode = null) + public function render(Form $form, string $mode = null): string { $form->getElementPrototype()->addClass('form-horizontal'); @@ -79,18 +79,18 @@ public function render(Nette\Forms\Form $form, $mode = null) } foreach ($form->getControls() as $control) { - if ($control instanceof Controls\Button) { - if (strpos($control->getControlPrototype()->getClass(), 'btn') === FALSE) { + if ($control instanceof Button) { + if (strpos($control->getControlPrototype()->getClass(), 'btn') === false) { $control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn btn-default'); $usedPrimary = true; } - } elseif ($control instanceof Controls\TextBase || - $control instanceof Controls\SelectBox || - $control instanceof Controls\MultiSelectBox) { + } elseif ($control instanceof TextBase || + $control instanceof SelectBox || + $control instanceof MultiSelectBox) { $control->getControlPrototype()->addClass('form-control'); - } elseif ($control instanceof Controls\Checkbox || - $control instanceof Controls\CheckboxList || - $control instanceof Controls\RadioList) { + } elseif ($control instanceof Checkbox || + $control instanceof CheckboxList || + $control instanceof RadioList) { $control->getSeparatorPrototype()->setName('div')->addClass($control->getControlPrototype()->type); } } diff --git a/src/BootstrapVerticalRenderer.php b/src/BootstrapVerticalRenderer.php index 440a43c..c346c03 100644 --- a/src/BootstrapVerticalRenderer.php +++ b/src/BootstrapVerticalRenderer.php @@ -2,36 +2,42 @@ namespace Tomaj\Form\Renderer; -use Nette; +use Nette\Forms\Controls\Button; +use Nette\Forms\Controls\Checkbox; +use Nette\Forms\Controls\CheckboxList; +use Nette\Forms\Controls\MultiSelectBox; +use Nette\Forms\Controls\RadioList; +use Nette\Forms\Controls\SelectBox; +use Nette\Forms\Controls\TextBase; +use Nette\Forms\Form; use Nette\Forms\Rendering\DefaultFormRenderer; -use Nette\Forms\Controls; class BootstrapVerticalRenderer extends DefaultFormRenderer { - public $wrappers = array( - 'form' => array( + public $wrappers = [ + 'form' => [ 'container' => null, - ), - 'error' => array( + ], + 'error' => [ 'container' => 'div class="alert alert-danger"', 'item' => 'p', - ), - 'group' => array( + ], + 'group' => [ 'container' => 'fieldset', 'label' => 'legend', 'description' => 'p', - ), - 'controls' => array( + ], + 'controls' => [ 'container' => null, - ), - 'pair' => array( + ], + 'pair' => [ 'container' => 'div class=form-group', '.required' => 'required', '.optional' => null, '.odd' => null, '.error' => 'has-error', - ), - 'control' => array( + ], + 'control' => [ 'container' => '', '.odd' => null, 'description' => 'span class=help-block', @@ -45,51 +51,45 @@ class BootstrapVerticalRenderer extends DefaultFormRenderer '.submit' => 'button', '.image' => 'imagebutton', '.button' => 'button', - ), - 'label' => array( + ], + 'label' => [ 'container' => '', 'suffix' => null, 'requiredsuffix' => '', - ), - 'hidden' => array( + ], + 'hidden' => [ 'container' => 'div', - ), - ); + ], + ]; /** @var bool */ private $novalidate; - public function __construct($novalidate = true) + public function __construct(bool $novalidate = true) { $this->novalidate = $novalidate; } - /** - * Provides complete form rendering. - * @param Nette\Forms\Form - * @param string 'begin', 'errors', 'ownerrors', 'body', 'end' or empty to render all - * @return string - */ - public function render(Nette\Forms\Form $form, $mode = null) + public function render(Form $form, string $mode = null): string { if ($this->novalidate) { $form->getElementPrototype()->setNovalidate('novalidate'); } - $usedPrimary = FALSE; + $usedPrimary = false; foreach ($form->getControls() as $control) { - if ($control instanceof Controls\Button) { - if (strpos($control->getControlPrototype()->getClass(), 'btn') === FALSE) { + if ($control instanceof Button) { + if (strpos($control->getControlPrototype()->getClass(), 'btn') === false) { $control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn btn-default'); $usedPrimary = true; } - } elseif ($control instanceof Controls\TextBase || - $control instanceof Controls\SelectBox || - $control instanceof Controls\MultiSelectBox) { + } elseif ($control instanceof TextBase || + $control instanceof SelectBox || + $control instanceof MultiSelectBox) { $control->getControlPrototype()->addClass('form-control'); - } elseif ($control instanceof Controls\Checkbox || - $control instanceof Controls\CheckboxList || - $control instanceof Controls\RadioList) { + } elseif ($control instanceof Checkbox || + $control instanceof CheckboxList || + $control instanceof RadioList) { $control->getSeparatorPrototype()->setName('div')->addClass($control->getControlPrototype()->type); } }