Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implements container.formGroupClass parameter #403

Closed
wants to merge 6 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 50 additions & 31 deletions src/View/Helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,27 +148,27 @@ class FormHelper extends CoreFormHelper
'{{input}}{{label}}',
'datetimeContainer' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group {{type}}{{required}}">{{content}}{{help}}</div>',
'class="{{containerClass}}{{type}}{{required}}">{{content}}{{help}}</div>',
'datetimeContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group {{formGroupPosition}}{{type}}{{required}} is-invalid">' .
'class="{{containerClass}}{{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}}{{type}}{{required}}">{{content}}{{help}}</div>',
'inputContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group {{formGroupPosition}}{{type}}{{required}} is-invalid">' .
'class="{{containerClass}}{{formGroupPosition}}{{type}}{{required}} is-invalid">' .
'{{content}}{{error}}{{help}}</div>',
'checkboxContainer' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group form-check{{variant}} ' .
'class="{{containerClass}}form-check{{variant}} ' .
'{{type}}{{required}}">{{content}}{{help}}</div>',
'checkboxContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group form-check{{variant}} ' .
'class="{{containerClass}}form-check{{variant}} ' .
'{{formGroupPosition}}{{type}}{{required}} is-invalid">{{content}}{{error}}{{help}}</div>',
'checkboxInlineContainer' =>
'<div{{containerAttrs}} ' .
Expand All @@ -185,11 +185,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}}{{type}}{{required}}" role="group" ' .
'aria-labelledby="{{groupId}}">{{content}}{{help}}</div>',
'radioContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group {{formGroupPosition}}{{type}}{{required}} is-invalid" ' .
'class="{{containerClass}}{{formGroupPosition}}{{type}}{{required}} is-invalid" ' .
'role="group" aria-labelledby="{{groupId}}">{{content}}{{error}}{{help}}</div>',
'radioLabel' =>
'<label{{attrs}}>{{text}}{{tooltip}}</label>',
Expand All @@ -204,11 +204,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}}{{type}}{{required}}" role="group" ' .
'aria-labelledby="{{groupId}}">{{content}}{{help}}</div>',
'multicheckboxContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group {{formGroupPosition}}{{type}}{{required}} is-invalid" ' .
'class="{{containerClass}}{{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 +244,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}}{{formGroupPosition}}{{type}}{{required}}">' .
'{{content}}{{help}}</div>',
'datetimeContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group {{formGroupPosition}}{{type}}{{required}} is-invalid">' .
'class="{{containerClass}}{{formGroupPosition}}{{type}}{{required}} is-invalid">' .
'{{content}}{{error}}{{help}}</div>',
'datetimeLabel' =>
'<label{{attrs}}>{{text}}{{tooltip}}</label>',
'radioContainer' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group {{formGroupPosition}}{{type}}{{required}}" role="group" ' .
'class="{{containerClass}}{{formGroupPosition}}{{type}}{{required}}" role="group" ' .
'aria-labelledby="{{groupId}}">{{content}}{{help}}</div>',
'radioContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group {{formGroupPosition}}{{type}}{{required}} is-invalid" ' .
'class="{{containerClass}}{{formGroupPosition}}{{type}}{{required}} is-invalid" ' .
'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}}d-flex {{formGroupPosition}}{{type}}{{required}}" ' .
'role="group" aria-labelledby="{{groupId}}">{{content}}{{help}}</div>',
'multicheckboxContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group d-flex ' .
'class="{{containerClass}}d-flex ' .
'{{formGroupPosition}}{{type}}{{required}} is-invalid" ' .
'role="group" aria-labelledby="{{groupId}}">{{content}}{{error}}{{help}}</div>',
'multicheckboxLabel' =>
Expand All @@ -289,47 +289,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}}row {{type}}{{required}}">{{content}}</div>',
'datetimeContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group row {{formGroupPosition}}{{type}}{{required}} is-invalid">' .
'class="{{containerClass}}row {{formGroupPosition}}{{type}}{{required}} is-invalid">' .
'{{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}}row">' .
'<div class="%s">{{content}}</div></div>',
'inputContainer' =>
'<div{{containerAttrs}} class="{{containerClass}}form-group row {{type}}{{required}}">' .
'<div{{containerAttrs}} class="{{containerClass}}row {{type}}{{required}}">' .
'{{content}}</div>',
'inputContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group row {{formGroupPosition}}{{type}}{{required}} is-invalid">' .
'class="{{containerClass}}row {{formGroupPosition}}{{type}}{{required}} is-invalid">' .
'{{content}}</div>',
'checkboxContainer' =>
'<div{{containerAttrs}} class="{{containerClass}}form-group row {{type}}{{required}}">' .
'<div{{containerAttrs}} class="{{containerClass}}row {{type}}{{required}}">' .
'{{content}}</div>',
'checkboxContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group row {{formGroupPosition}}{{type}}{{required}} is-invalid">' .
'class="{{containerClass}}row {{formGroupPosition}}{{type}}{{required}} is-invalid">' .
'{{content}}</div>',
'radioContainer' =>
'<div{{containerAttrs}} class="{{containerClass}}form-group row {{type}}{{required}}" role="group" ' .
'<div{{containerAttrs}} class="{{containerClass}}row {{type}}{{required}}" role="group" ' .
'aria-labelledby="{{groupId}}">{{content}}</div>',
'radioContainerError' =>
'<div{{containerAttrs}} ' .
'class="{{containerClass}}form-group row {{formGroupPosition}}{{type}}{{required}} is-invalid" ' .
'class="{{containerClass}}row {{formGroupPosition}}{{type}}{{required}} is-invalid" ' .
'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}}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}}row {{formGroupPosition}}{{type}}{{required}} is-invalid" ' .
'role="group" aria-labelledby="{{groupId}}">{{content}}</div>',
'multicheckboxLabel' =>
'<label{{attrs}}>{{text}}{{tooltip}}</label>',
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -657,21 +662,34 @@ protected function _containerOptions(?string $fieldName, array $options): array
) {
$options['container'] = $this->injectClasses('form-floating', (array)($options['container'] ?? []));
}
$skipFormGroupClass = ($options['container']['formGroupClass'] ?? null) === false;

if (!isset($options['container'])) {
return $options;
if ($skipFormGroupClass) {
unset($options['container']['formGroupClass']);
if (empty($options['container'])) {
unset($options['container']);
}
}

$containerOptions = $options['container'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line will generate an undefined index error if the unset() on line 670 is executed. Test case for when $skipFormGroupClass ends up being true is needed.

P.S. I have fixed the test suite issues on upstream master, so you can rebase.

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;
}
Expand Down Expand Up @@ -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']) {
Expand Down
Loading