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

Fix error summary always visible with CSP header (#19691) #20105

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Yii Framework 2 Change Log
- Bug #17181: Improved `BaseUrl::isRelative($url)` performance (sammousa, bizley, rob006)
- Bug #17191: Fixed `BaseUrl::isRelative($url)` method in `yii\helpers\BaseUrl` (ggh2e3)
- Bug #18469: Fixed `Link::serialize(array $links)` method in `yii\web\Link` (ggh2e3)
- Bug #19691: Fix error summary always visible with CSP header (skepticspriggan)
skepticspriggan marked this conversation as resolved.
Show resolved Hide resolved
- Bug #20040: Fix type `boolean` in `MSSQL` (terabytesoftw)
- Bug #20005: Fix `yii\console\controllers\ServeController` to specify the router script (terabytesoftw)
- Bug #19060: Fix `yii\widgets\Menu` bug when using Closure for active item and adding additional tests in `tests\framework\widgets\MenuTest` (atrandafir)
Expand Down
8 changes: 7 additions & 1 deletion framework/helpers/BaseHtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,7 @@
* - showAllErrors: boolean, if set to true every error message for each attribute will be shown otherwise
* only the first error message for each attribute will be shown. Defaults to `false`.
* Option is available since 2.0.10.
* - emptyClass: string, the class name that is added to an empty summary.
*
* The rest of the options will be rendered as the attributes of the container tag.
*
Expand All @@ -1271,12 +1272,17 @@
$footer = ArrayHelper::remove($options, 'footer', '');
$encode = ArrayHelper::remove($options, 'encode', true);
$showAllErrors = ArrayHelper::remove($options, 'showAllErrors', false);
$emptyClass = ArrayHelper::remove($options, 'emptyClass', null);

Check warning on line 1275 in framework/helpers/BaseHtml.php

View check run for this annotation

Codecov / codecov/patch

framework/helpers/BaseHtml.php#L1275

Added line #L1275 was not covered by tests
unset($options['header']);
$lines = self::collectErrors($models, $encode, $showAllErrors);
if (empty($lines)) {
// still render the placeholder for client-side validation use
$content = '<ul></ul>';
$options['style'] = isset($options['style']) ? rtrim($options['style'], ';') . '; display:none' : 'display:none';
if($emptyClass !== null) {
skepticspriggan marked this conversation as resolved.
Show resolved Hide resolved
$options['class'] = $emptyClass;

Check warning on line 1282 in framework/helpers/BaseHtml.php

View check run for this annotation

Codecov / codecov/patch

framework/helpers/BaseHtml.php#L1281-L1282

Added lines #L1281 - L1282 were not covered by tests
} else {
$options['style'] = isset($options['style']) ? rtrim($options['style'], ';') . '; display:none' : 'display:none';

Check warning on line 1284 in framework/helpers/BaseHtml.php

View check run for this annotation

Codecov / codecov/patch

framework/helpers/BaseHtml.php#L1284

Added line #L1284 was not covered by tests
}
} else {
$content = '<ul><li>' . implode("</li>\n<li>", $lines) . '</li></ul>';
}
Expand Down
5 changes: 5 additions & 0 deletions tests/framework/helpers/HtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,11 @@ function ($model) {
$model->addError('name', 'Error message. Here are even more chars: ""');
},
],
[
'empty_class',
['emptyClass' => 'd-none'],
'<div class="d-none"><p>Please fix the following errors:</p><ul></ul></div>',
],
];
}

Expand Down
Loading