From f330448791c624fa8c5c92837a830ca207e60c1a Mon Sep 17 00:00:00 2001 From: Yevgeny Tomenko Date: Sat, 16 Nov 2024 11:37:57 +0300 Subject: [PATCH 1/5] implements container.formGroupClass parameter to pass or disable class different from form-group to containers --- src/View/Helper/FormHelper.php | 81 +++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 31 deletions(-) diff --git a/src/View/Helper/FormHelper.php b/src/View/Helper/FormHelper.php index b7d5c6ab..85ab34df 100644 --- a/src/View/Helper/FormHelper.php +++ b/src/View/Helper/FormHelper.php @@ -148,27 +148,27 @@ class FormHelper extends CoreFormHelper '{{input}}{{label}}', 'datetimeContainer' => '{{content}}{{help}}', + 'class="{{containerClass}}{{type}}{{required}}">{{content}}{{help}}', 'datetimeContainerError' => '' . + 'class="{{containerClass}}{{formGroupPosition}}{{type}}{{required}} is-invalid">' . '{{content}}{{error}}{{help}}', 'datetimeLabel' => '{{text}}{{tooltip}}', 'inputContainer' => '{{content}}{{help}}', + 'class="{{containerClass}}{{type}}{{required}}">{{content}}{{help}}', 'inputContainerError' => '' . + 'class="{{containerClass}}{{formGroupPosition}}{{type}}{{required}} is-invalid">' . '{{content}}{{error}}{{help}}', 'checkboxContainer' => '{{content}}{{help}}', 'checkboxContainerError' => '{{content}}{{error}}{{help}}', 'checkboxInlineContainer' => ' '
{{label}}
', 'radioContainer' => - '{{content}}{{help}}', 'radioContainerError' => '{{content}}{{error}}{{help}}', 'radioLabel' => '{{text}}{{tooltip}}', @@ -204,11 +204,11 @@ class FormHelper extends CoreFormHelper 'inputGroupText' => '{{content}}', 'multicheckboxContainer' => - '{{content}}{{help}}', 'multicheckboxContainerError' => '{{content}}{{error}}{{help}}', 'multicheckboxLabel' => '{{text}}{{tooltip}}', @@ -244,31 +244,31 @@ class FormHelper extends CoreFormHelper '{{formGroupPosition}}{{type}}{{required}} is-invalid">{{content}}{{error}}{{help}}', 'datetimeContainer' => '' . + 'class="{{containerClass}}{{formGroupPosition}}{{type}}{{required}}">' . '{{content}}{{help}}', 'datetimeContainerError' => '' . + 'class="{{containerClass}}{{formGroupPosition}}{{type}}{{required}} is-invalid">' . '{{content}}{{error}}{{help}}', 'datetimeLabel' => '{{text}}{{tooltip}}', 'radioContainer' => '{{content}}{{help}}', 'radioContainerError' => '{{content}}{{error}}{{help}}', 'radioLabel' => '{{text}}{{tooltip}}', 'multicheckboxContainer' => '{{content}}{{help}}', 'multicheckboxContainerError' => '{{content}}{{error}}{{help}}', 'multicheckboxLabel' => @@ -289,47 +289,47 @@ class FormHelper extends CoreFormHelper '
{{input}}{{label}}{{error}}{{help}}
', 'datetimeContainer' => '{{content}}', + 'class="{{containerClass}}row {{type}}{{required}}">{{content}}', 'datetimeContainerError' => '' . + 'class="{{containerClass}}row {{formGroupPosition}}{{type}}{{required}} is-invalid">' . '{{content}}', 'datetimeLabel' => '{{text}}{{tooltip}}', 'checkboxInlineFormGroup' => '
{{input}}{{label}}
', 'submitContainer' => - '' . + '' . '
{{content}}
', 'inputContainer' => - '' . + '' . '{{content}}', 'inputContainerError' => '' . + 'class="{{containerClass}}row {{formGroupPosition}}{{type}}{{required}} is-invalid">' . '{{content}}', 'checkboxContainer' => - '' . + '' . '{{content}}', 'checkboxContainerError' => '' . + 'class="{{containerClass}}row {{formGroupPosition}}{{type}}{{required}} is-invalid">' . '{{content}}', 'radioContainer' => - '{{content}}', 'radioContainerError' => '{{content}}', 'radioLabel' => '{{text}}{{tooltip}}', 'multicheckboxContainer' => - '{{content}}', 'multicheckboxContainerError' => '{{content}}', 'multicheckboxLabel' => '{{text}}{{tooltip}}', @@ -476,6 +476,11 @@ public function submit(?string $caption = null, array $options = []): string $options += [ 'class' => 'primary', ]; + + if ($this->_align !== static::ALIGN_HORIZONTAL && !isset($options['container']['formGroupClass'])) { + $options['container']['formGroupClass'] = false; + } + $options = $this->applyButtonClasses($options); $options = $this->_containerOptions(null, $options); @@ -657,21 +662,34 @@ protected function _containerOptions(?string $fieldName, array $options): array ) { $options['container'] = $this->injectClasses('form-floating', (array)($options['container'] ?? [])); } + $skipFormGroupClass = (isset($options['container']['formGroupClass']) && $options['container']['formGroupClass'] === false); - if (!isset($options['container'])) { - return $options; + if ($skipFormGroupClass) { + unset($options['container']['formGroupClass']); + if (empty($options['container'])) { + unset($options['container']); + } } $containerOptions = $options['container']; unset($options['container']); - + if ($containerOptions['formGroupClass'] === null && !$skipFormGroupClass) { + $containerOptions['formGroupClass'] = 'form-group'; + } + $containerClass = ''; if (isset($containerOptions['class'])) { - $options['templateVars']['containerClass'] = $containerOptions['class'] . ' '; + $containerClass = $containerOptions['class'] . ' '; unset($containerOptions['class']); } + if ($containerOptions['formGroupClass']) { + $containerClass = $containerClass . $containerOptions['formGroupClass'] . ' '; + } + $options['templateVars']['containerClass'] = $containerClass; + unset($containerOptions['formGroupClass']); if (!empty($containerOptions)) { $options['templateVars']['containerAttrs'] = $this->templater()->formatAttributes($containerOptions); } + unset($options['container']); return $options; } @@ -731,6 +749,7 @@ protected function _checkboxOptions(string $fieldName, array $options): array $options['templates']['checkboxContainer'] = $checkboxContainer; $options['templates']['checkboxContainerError'] = $checkboxContainerError; + $options['container']['formGroupClass'] = false; } if ($options['nestedInput']) { From b47728f1e94c2a226c0d61e45185140179efc34d Mon Sep 17 00:00:00 2001 From: Yevgeny Tomenko Date: Sat, 16 Nov 2024 11:47:06 +0300 Subject: [PATCH 2/5] code style fixes --- src/View/Helper/FormHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/View/Helper/FormHelper.php b/src/View/Helper/FormHelper.php index 85ab34df..e53fd4a4 100644 --- a/src/View/Helper/FormHelper.php +++ b/src/View/Helper/FormHelper.php @@ -662,7 +662,7 @@ protected function _containerOptions(?string $fieldName, array $options): array ) { $options['container'] = $this->injectClasses('form-floating', (array)($options['container'] ?? [])); } - $skipFormGroupClass = (isset($options['container']['formGroupClass']) && $options['container']['formGroupClass'] === false); + $skipFormGroupClass = ($options['container']['formGroupClass'] ?? null) === false; if ($skipFormGroupClass) { unset($options['container']['formGroupClass']); From 8ee08c4d8f36e3f5a3fb6d1da6706d77115aa6f5 Mon Sep 17 00:00:00 2001 From: Yevgeny Tomenko Date: Sat, 16 Nov 2024 11:37:57 +0300 Subject: [PATCH 3/5] implements container.formGroupClass parameter to pass or disable class different from form-group to containers --- src/View/Helper/FormHelper.php | 81 +++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 31 deletions(-) diff --git a/src/View/Helper/FormHelper.php b/src/View/Helper/FormHelper.php index b7d5c6ab..85ab34df 100644 --- a/src/View/Helper/FormHelper.php +++ b/src/View/Helper/FormHelper.php @@ -148,27 +148,27 @@ class FormHelper extends CoreFormHelper '{{input}}{{label}}', 'datetimeContainer' => '{{content}}{{help}}', + 'class="{{containerClass}}{{type}}{{required}}">{{content}}{{help}}', 'datetimeContainerError' => '' . + 'class="{{containerClass}}{{formGroupPosition}}{{type}}{{required}} is-invalid">' . '{{content}}{{error}}{{help}}', 'datetimeLabel' => '{{text}}{{tooltip}}', 'inputContainer' => '{{content}}{{help}}', + 'class="{{containerClass}}{{type}}{{required}}">{{content}}{{help}}', 'inputContainerError' => '' . + 'class="{{containerClass}}{{formGroupPosition}}{{type}}{{required}} is-invalid">' . '{{content}}{{error}}{{help}}', 'checkboxContainer' => '{{content}}{{help}}', 'checkboxContainerError' => '{{content}}{{error}}{{help}}', 'checkboxInlineContainer' => ' '
{{label}}
', 'radioContainer' => - '{{content}}{{help}}', 'radioContainerError' => '{{content}}{{error}}{{help}}', 'radioLabel' => '{{text}}{{tooltip}}', @@ -204,11 +204,11 @@ class FormHelper extends CoreFormHelper 'inputGroupText' => '{{content}}', 'multicheckboxContainer' => - '{{content}}{{help}}', 'multicheckboxContainerError' => '{{content}}{{error}}{{help}}', 'multicheckboxLabel' => '{{text}}{{tooltip}}', @@ -244,31 +244,31 @@ class FormHelper extends CoreFormHelper '{{formGroupPosition}}{{type}}{{required}} is-invalid">{{content}}{{error}}{{help}}', 'datetimeContainer' => '' . + 'class="{{containerClass}}{{formGroupPosition}}{{type}}{{required}}">' . '{{content}}{{help}}', 'datetimeContainerError' => '' . + 'class="{{containerClass}}{{formGroupPosition}}{{type}}{{required}} is-invalid">' . '{{content}}{{error}}{{help}}', 'datetimeLabel' => '{{text}}{{tooltip}}', 'radioContainer' => '{{content}}{{help}}', 'radioContainerError' => '{{content}}{{error}}{{help}}', 'radioLabel' => '{{text}}{{tooltip}}', 'multicheckboxContainer' => '{{content}}{{help}}', 'multicheckboxContainerError' => '{{content}}{{error}}{{help}}', 'multicheckboxLabel' => @@ -289,47 +289,47 @@ class FormHelper extends CoreFormHelper '
{{input}}{{label}}{{error}}{{help}}
', 'datetimeContainer' => '{{content}}', + 'class="{{containerClass}}row {{type}}{{required}}">{{content}}', 'datetimeContainerError' => '' . + 'class="{{containerClass}}row {{formGroupPosition}}{{type}}{{required}} is-invalid">' . '{{content}}', 'datetimeLabel' => '{{text}}{{tooltip}}', 'checkboxInlineFormGroup' => '
{{input}}{{label}}
', 'submitContainer' => - '' . + '' . '
{{content}}
', 'inputContainer' => - '' . + '' . '{{content}}', 'inputContainerError' => '' . + 'class="{{containerClass}}row {{formGroupPosition}}{{type}}{{required}} is-invalid">' . '{{content}}', 'checkboxContainer' => - '' . + '' . '{{content}}', 'checkboxContainerError' => '' . + 'class="{{containerClass}}row {{formGroupPosition}}{{type}}{{required}} is-invalid">' . '{{content}}', 'radioContainer' => - '{{content}}', 'radioContainerError' => '{{content}}', 'radioLabel' => '{{text}}{{tooltip}}', 'multicheckboxContainer' => - '{{content}}', 'multicheckboxContainerError' => '{{content}}', 'multicheckboxLabel' => '{{text}}{{tooltip}}', @@ -476,6 +476,11 @@ public function submit(?string $caption = null, array $options = []): string $options += [ 'class' => 'primary', ]; + + if ($this->_align !== static::ALIGN_HORIZONTAL && !isset($options['container']['formGroupClass'])) { + $options['container']['formGroupClass'] = false; + } + $options = $this->applyButtonClasses($options); $options = $this->_containerOptions(null, $options); @@ -657,21 +662,34 @@ protected function _containerOptions(?string $fieldName, array $options): array ) { $options['container'] = $this->injectClasses('form-floating', (array)($options['container'] ?? [])); } + $skipFormGroupClass = (isset($options['container']['formGroupClass']) && $options['container']['formGroupClass'] === false); - if (!isset($options['container'])) { - return $options; + if ($skipFormGroupClass) { + unset($options['container']['formGroupClass']); + if (empty($options['container'])) { + unset($options['container']); + } } $containerOptions = $options['container']; unset($options['container']); - + if ($containerOptions['formGroupClass'] === null && !$skipFormGroupClass) { + $containerOptions['formGroupClass'] = 'form-group'; + } + $containerClass = ''; if (isset($containerOptions['class'])) { - $options['templateVars']['containerClass'] = $containerOptions['class'] . ' '; + $containerClass = $containerOptions['class'] . ' '; unset($containerOptions['class']); } + if ($containerOptions['formGroupClass']) { + $containerClass = $containerClass . $containerOptions['formGroupClass'] . ' '; + } + $options['templateVars']['containerClass'] = $containerClass; + unset($containerOptions['formGroupClass']); if (!empty($containerOptions)) { $options['templateVars']['containerAttrs'] = $this->templater()->formatAttributes($containerOptions); } + unset($options['container']); return $options; } @@ -731,6 +749,7 @@ protected function _checkboxOptions(string $fieldName, array $options): array $options['templates']['checkboxContainer'] = $checkboxContainer; $options['templates']['checkboxContainerError'] = $checkboxContainerError; + $options['container']['formGroupClass'] = false; } if ($options['nestedInput']) { From 2406180aa8cf7e3f62c20d83ed5987dec640575e Mon Sep 17 00:00:00 2001 From: Yevgeny Tomenko Date: Sat, 16 Nov 2024 11:47:06 +0300 Subject: [PATCH 4/5] code style fixes --- src/View/Helper/FormHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/View/Helper/FormHelper.php b/src/View/Helper/FormHelper.php index 85ab34df..e53fd4a4 100644 --- a/src/View/Helper/FormHelper.php +++ b/src/View/Helper/FormHelper.php @@ -662,7 +662,7 @@ protected function _containerOptions(?string $fieldName, array $options): array ) { $options['container'] = $this->injectClasses('form-floating', (array)($options['container'] ?? [])); } - $skipFormGroupClass = (isset($options['container']['formGroupClass']) && $options['container']['formGroupClass'] === false); + $skipFormGroupClass = ($options['container']['formGroupClass'] ?? null) === false; if ($skipFormGroupClass) { unset($options['container']['formGroupClass']); From c7bb04e2640ae71544dfd0aaceaadd73c4961be3 Mon Sep 17 00:00:00 2001 From: Yevgeny Tomenko Date: Sun, 17 Nov 2024 02:45:55 +0300 Subject: [PATCH 5/5] remove not necessary logic --- src/View/Helper/FormHelper.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/View/Helper/FormHelper.php b/src/View/Helper/FormHelper.php index e53fd4a4..9341c92d 100644 --- a/src/View/Helper/FormHelper.php +++ b/src/View/Helper/FormHelper.php @@ -666,9 +666,6 @@ protected function _containerOptions(?string $fieldName, array $options): array if ($skipFormGroupClass) { unset($options['container']['formGroupClass']); - if (empty($options['container'])) { - unset($options['container']); - } } $containerOptions = $options['container'];