From c9c5c61f7683a6f33e366e3c9cdb2d6dc0e3031f Mon Sep 17 00:00:00 2001 From: Skeptic Spriggan Date: Thu, 18 Jan 2024 16:30:22 +0100 Subject: [PATCH 1/3] Fix error summary always visible with CSP header (#19691) --- framework/CHANGELOG.md | 1 + framework/helpers/BaseHtml.php | 8 +++++++- tests/framework/helpers/HtmlTest.php | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 7296c02cd3d..58e84e4f92d 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -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) - 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) diff --git a/framework/helpers/BaseHtml.php b/framework/helpers/BaseHtml.php index 45812e4165b..82262b8a96b 100644 --- a/framework/helpers/BaseHtml.php +++ b/framework/helpers/BaseHtml.php @@ -1260,6 +1260,7 @@ public static function activeHint($model, $attribute, $options = []) * - 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. * @@ -1271,12 +1272,17 @@ public static function errorSummary($models, $options = []) $footer = ArrayHelper::remove($options, 'footer', ''); $encode = ArrayHelper::remove($options, 'encode', true); $showAllErrors = ArrayHelper::remove($options, 'showAllErrors', false); + $emptyClass = ArrayHelper::remove($options, 'emptyClass', null); unset($options['header']); $lines = self::collectErrors($models, $encode, $showAllErrors); if (empty($lines)) { // still render the placeholder for client-side validation use $content = ''; - $options['style'] = isset($options['style']) ? rtrim($options['style'], ';') . '; display:none' : 'display:none'; + if($emptyClass !== null) { + $options['class'] = $emptyClass; + } else { + $options['style'] = isset($options['style']) ? rtrim($options['style'], ';') . '; display:none' : 'display:none'; + } } else { $content = ''; } diff --git a/tests/framework/helpers/HtmlTest.php b/tests/framework/helpers/HtmlTest.php index 12e8869d2d8..eef2f84bf7f 100644 --- a/tests/framework/helpers/HtmlTest.php +++ b/tests/framework/helpers/HtmlTest.php @@ -1672,6 +1672,11 @@ function ($model) { $model->addError('name', 'Error message. Here are even more chars: ""'); }, ], + [ + 'empty_class', + ['emptyClass' => 'd-none'], + '

Please fix the following errors:

', + ], ]; } From 018fcb5d9662722fa99e6d3b2c6bfdaf8a07a5e2 Mon Sep 17 00:00:00 2001 From: skepticspriggan <91023755+skepticspriggan@users.noreply.github.com> Date: Thu, 18 Jan 2024 18:14:51 +0100 Subject: [PATCH 2/3] Fix error summary always visible with CSP header (#19691) Co-authored-by: Alexander Makarov --- framework/helpers/BaseHtml.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/helpers/BaseHtml.php b/framework/helpers/BaseHtml.php index 82262b8a96b..4f17fa670ea 100644 --- a/framework/helpers/BaseHtml.php +++ b/framework/helpers/BaseHtml.php @@ -1278,7 +1278,7 @@ public static function errorSummary($models, $options = []) if (empty($lines)) { // still render the placeholder for client-side validation use $content = ''; - if($emptyClass !== null) { + if ($emptyClass !== null) { $options['class'] = $emptyClass; } else { $options['style'] = isset($options['style']) ? rtrim($options['style'], ';') . '; display:none' : 'display:none'; From 32a20f9338a96120a2be51a5cf55036d32c98f4d Mon Sep 17 00:00:00 2001 From: skepticspriggan <91023755+skepticspriggan@users.noreply.github.com> Date: Thu, 18 Jan 2024 18:23:38 +0100 Subject: [PATCH 3/3] Fix error summary always visible with CSP header (#19691) Co-authored-by: Alexander Makarov --- framework/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 58e84e4f92d..a4dd74dfcb8 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -7,7 +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) +- Bug #19691: Allow using custom class to style error summary (skepticspriggan) - 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)