Skip to content

Commit

Permalink
implements container.formGroupClass parameter to pass or disable clas…
Browse files Browse the repository at this point in the history
…s different from form-group to containers
  • Loading branch information
skie committed Nov 17, 2024
1 parent c73af02 commit 8489f2e
Showing 1 changed file with 35 additions and 34 deletions.
69 changes: 35 additions & 34 deletions src/View/Helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,28 +148,27 @@ class FormHelper extends CoreFormHelper
'{{input}}{{label}}',
'datetimeContainer' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group {{type}}{{required}}">{{content}}{{help}}</div>',
'class="{{containerClass}}{{formGroupClass}} {{type}}{{required}}">{{content}}{{help}}</div>',
'datetimeContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group {{formGroupPosition}}{{type}}{{required}} is-invalid">' .
'class="{{containerClass}}{{formGroupClass}} {{formGroupPosition}}{{type}}{{required}} is-invalid">' .
'{{content}}{{error}}{{help}}</div>',
'datetimeLabel' =>
'<label{{attrs}}>{{text}}{{tooltip}}</label>',
'inputContainer' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group {{type}}{{required}}">{{content}}{{help}}</div>',
'class="{{containerClass}}{{formGroupClass}} {{type}}{{required}}">{{content}}{{help}}</div>',
'inputContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group {{formGroupPosition}}{{type}}{{required}} is-invalid">' .
'class="{{containerClass}}{{formGroupClass}} {{formGroupPosition}}{{type}}{{required}} is-invalid">' .
'{{content}}{{error}}{{help}}</div>',
'checkboxContainer' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group form-check{{variant}} ' .
'{{type}}{{required}}">{{content}}{{help}}</div>',
'class="{{containerClass}}{{formGroupClass}} form-check{{variant}} {{type}}{{required}}">{{content}}{{help}}</div>',

Check warning on line 167 in src/View/Helper/FormHelper.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

Line exceeds 120 characters; contains 132 characters
'checkboxContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group form-check{{variant}} ' .
'{{formGroupPosition}}{{type}}{{required}} is-invalid">{{content}}{{error}}{{help}}</div>',
'class="{{containerClass}}{{formGroupClass}} form-check{{variant}} {{formGroupPosition}}{{type}}{{required}} is-invalid">' .

Check warning on line 170 in src/View/Helper/FormHelper.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

Line exceeds 120 characters; contains 140 characters
'{{content}}{{error}}{{help}}</div>',
'checkboxInlineContainer' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-check{{variant}} form-check-inline align-top {{type}}{{required}}">' .
Expand All @@ -185,11 +184,11 @@ class FormHelper extends CoreFormHelper
'checkboxInlineWrapper' =>
'<div class="form-check{{variant}} form-check-inline">{{label}}</div>',
'radioContainer' =>
'<div{{containerAttrs}} class="{{containerClass}}form-group {{type}}{{required}}" role="group" ' .
'<div{{containerAttrs}} class="{{containerClass}}{{formGroupClass}} {{type}}{{required}}" role="group" ' .
'aria-labelledby="{{groupId}}">{{content}}{{help}}</div>',
'radioContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group {{formGroupPosition}}{{type}}{{required}} is-invalid" ' .
'class="{{containerClass}}{{formGroupClass}} {{formGroupPosition}}{{type}}{{required}} is-invalid" ' .
'role="group" aria-labelledby="{{groupId}}">{{content}}{{error}}{{help}}</div>',
'radioLabel' =>
'<label{{attrs}}>{{text}}{{tooltip}}</label>',
Expand All @@ -204,11 +203,11 @@ class FormHelper extends CoreFormHelper
'inputGroupText' =>
'<span class="input-group-text">{{content}}</span>',
'multicheckboxContainer' =>
'<div{{containerAttrs}} class="{{containerClass}}form-group {{type}}{{required}}" role="group" ' .
'<div{{containerAttrs}} class="{{containerClass}}{{formGroupClass}} {{type}}{{required}}" role="group" ' .
'aria-labelledby="{{groupId}}">{{content}}{{help}}</div>',
'multicheckboxContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group {{formGroupPosition}}{{type}}{{required}} is-invalid" ' .
'class="{{containerClass}}{{formGroupClass}} {{formGroupPosition}}{{type}}{{required}} is-invalid" ' .
'role="group" aria-labelledby="{{groupId}}">{{content}}{{error}}{{help}}</div>',
'multicheckboxLabel' =>
'<label{{attrs}}>{{text}}{{tooltip}}</label>',
Expand Down Expand Up @@ -244,31 +243,31 @@ class FormHelper extends CoreFormHelper
'{{formGroupPosition}}{{type}}{{required}} is-invalid">{{content}}{{error}}{{help}}</div>',
'datetimeContainer' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group {{formGroupPosition}}{{type}}{{required}}">' .
'class="{{containerClass}}{{formGroupClass}} {{formGroupPosition}}{{type}}{{required}}">' .
'{{content}}{{help}}</div>',
'datetimeContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group {{formGroupPosition}}{{type}}{{required}} is-invalid">' .
'class="{{containerClass}}{{formGroupClass}} {{formGroupPosition}}{{type}}{{required}} is-invalid">' .

Check warning on line 250 in src/View/Helper/FormHelper.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

Line exceeds 120 characters; contains 122 characters
'{{content}}{{error}}{{help}}</div>',
'datetimeLabel' =>
'<label{{attrs}}>{{text}}{{tooltip}}</label>',
'radioContainer' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group {{formGroupPosition}}{{type}}{{required}}" role="group" ' .
'class="{{containerClass}}{{formGroupClass}} {{formGroupPosition}}{{type}}{{required}}" role="group" ' .

Check warning on line 256 in src/View/Helper/FormHelper.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

Line exceeds 120 characters; contains 124 characters
'aria-labelledby="{{groupId}}">{{content}}{{help}}</div>',
'radioContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group {{formGroupPosition}}{{type}}{{required}} is-invalid" ' .
'class="{{containerClass}}{{formGroupClass}} {{formGroupPosition}}{{type}}{{required}} is-invalid" ' .

Check warning on line 260 in src/View/Helper/FormHelper.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

Line exceeds 120 characters; contains 122 characters
'role="group" aria-labelledby="{{groupId}}">{{content}}{{error}}{{help}}</div>',
'radioLabel' =>
'<span{{attrs}}>{{text}}{{tooltip}}</span>',
'multicheckboxContainer' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group d-flex {{formGroupPosition}}{{type}}{{required}}" ' .
'class="{{containerClass}}{{formGroupClass}} d-flex {{formGroupPosition}}{{type}}{{required}}" ' .
'role="group" aria-labelledby="{{groupId}}">{{content}}{{help}}</div>',
'multicheckboxContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group d-flex ' .
'class="{{containerClass}}{{formGroupClass}} d-flex ' .
'{{formGroupPosition}}{{type}}{{required}} is-invalid" ' .
'role="group" aria-labelledby="{{groupId}}">{{content}}{{error}}{{help}}</div>',
'multicheckboxLabel' =>
Expand All @@ -289,47 +288,47 @@ class FormHelper extends CoreFormHelper
'<div class="%s"><div class="form-check{{variant}}">{{input}}{{label}}{{error}}{{help}}</div></div>',
'datetimeContainer' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group row {{type}}{{required}}">{{content}}</div>',
'class="{{containerClass}}{{formGroupClass}} row {{type}}{{required}}">{{content}}</div>',
'datetimeContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group row {{formGroupPosition}}{{type}}{{required}} is-invalid">' .
'class="{{containerClass}}{{formGroupClass}} row {{formGroupPosition}}{{type}}{{required}} is-invalid">' .

Check warning on line 294 in src/View/Helper/FormHelper.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

Line exceeds 120 characters; contains 126 characters
'{{content}}</div>',
'datetimeLabel' =>
'<label{{attrs}}>{{text}}{{tooltip}}</label>',
'checkboxInlineFormGroup' =>
'<div class="%s"><div class="form-check{{variant}} form-check-inline">{{input}}{{label}}</div></div>',
'submitContainer' =>
'<div{{containerAttrs}} class="{{containerClass}}form-group row">' .
'<div{{containerAttrs}} class="{{containerClass}}{{formGroupClass}} row">' .
'<div class="%s">{{content}}</div></div>',
'inputContainer' =>
'<div{{containerAttrs}} class="{{containerClass}}form-group row {{type}}{{required}}">' .
'<div{{containerAttrs}} class="{{containerClass}}{{formGroupClass}} row {{type}}{{required}}">' .
'{{content}}</div>',
'inputContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group row {{formGroupPosition}}{{type}}{{required}} is-invalid">' .
'class="{{containerClass}}{{formGroupClass}} row {{formGroupPosition}}{{type}}{{required}} is-invalid">' .

Check warning on line 308 in src/View/Helper/FormHelper.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

Line exceeds 120 characters; contains 126 characters
'{{content}}</div>',
'checkboxContainer' =>
'<div{{containerAttrs}} class="{{containerClass}}form-group row {{type}}{{required}}">' .
'<div{{containerAttrs}} class="{{containerClass}}{{formGroupClass}} row {{type}}{{required}}">' .
'{{content}}</div>',
'checkboxContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group row {{formGroupPosition}}{{type}}{{required}} is-invalid">' .
'class="{{containerClass}}{{formGroupClass}} row {{formGroupPosition}}{{type}}{{required}} is-invalid">' .

Check warning on line 315 in src/View/Helper/FormHelper.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

Line exceeds 120 characters; contains 126 characters
'{{content}}</div>',
'radioContainer' =>
'<div{{containerAttrs}} class="{{containerClass}}form-group row {{type}}{{required}}" role="group" ' .
'<div{{containerAttrs}} class="{{containerClass}}{{formGroupClass}} row {{type}}{{required}}" role="group" ' .

Check warning on line 318 in src/View/Helper/FormHelper.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

Line exceeds 120 characters; contains 126 characters
'aria-labelledby="{{groupId}}">{{content}}</div>',
'radioContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group row {{formGroupPosition}}{{type}}{{required}} is-invalid" ' .
'class="{{containerClass}}{{formGroupClass}} row {{formGroupPosition}}{{type}}{{required}} is-invalid" ' .

Check warning on line 322 in src/View/Helper/FormHelper.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

Line exceeds 120 characters; contains 126 characters
'role="group" aria-labelledby="{{groupId}}">{{content}}</div>',
'radioLabel' =>
'<label{{attrs}}>{{text}}{{tooltip}}</label>',
'multicheckboxContainer' =>
'<div{{containerAttrs}} class="{{containerClass}}form-group row {{type}}{{required}}" role="group" ' .
'<div{{containerAttrs}} class="{{containerClass}}{{formGroupClass}} row {{type}}{{required}}" role="group" ' .
'aria-labelledby="{{groupId}}">{{content}}</div>',
'multicheckboxContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group row {{formGroupPosition}}{{type}}{{required}} is-invalid" ' .
'class="{{containerClass}}{{formGroupClass}} row {{formGroupPosition}}{{type}}{{required}} is-invalid" ' .
'role="group" aria-labelledby="{{groupId}}">{{content}}</div>',
'multicheckboxLabel' =>
'<label{{attrs}}>{{text}}{{tooltip}}</label>',
Expand Down Expand Up @@ -658,13 +657,15 @@ protected function _containerOptions(?string $fieldName, array $options): array
$options['container'] = $this->injectClasses('form-floating', (array)($options['container'] ?? []));
}

if (!isset($options['container'])) {
return $options;
}

$containerOptions = $options['container'];
$containerOptions = $options['container'] ?? [];
unset($options['container']);

$options['templateVars']['formGroupClass'] = 'form-group';
if (isset($containerOptions['formGroupClass'])) {
$options['templateVars']['formGroupClass'] = $containerOptions['formGroupClass'];
unset($containerOptions['formGroupClass']);

Check warning on line 666 in src/View/Helper/FormHelper.php

View check run for this annotation

Codecov / codecov/patch

src/View/Helper/FormHelper.php#L665-L666

Added lines #L665 - L666 were not covered by tests
}

if (isset($containerOptions['class'])) {
$options['templateVars']['containerClass'] = $containerOptions['class'] . ' ';
unset($containerOptions['class']);
Expand Down

0 comments on commit 8489f2e

Please sign in to comment.