Merge pull request #15859 from FabrizioCaldarelli/15858-broken-basehtml-collecterrors-with-showallerrors-true

15858 broken basehtml collecterrors with showallerrors true
This commit is contained in:
Dmitry Naumenko
2018-03-10 18:44:10 +02:00
committed by GitHub
3 changed files with 26 additions and 2 deletions

View File

@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.14.2 under development 2.0.14.2 under development
------------------------ ------------------------
- Bug #15858: Fixed `Undefined offset` error calling `yii\helpers\Html::errorSummary()` with the same error messages for different model attributes (FabrizioCaldarelli, silverfire)
- Bug #15783: Regenerate CSRF token only when logging in directly (samdark) - Bug #15783: Regenerate CSRF token only when logging in directly (samdark)
- Bug #15801: Fixed `has-error` CSS class assignment in `yii\widgets\ActiveField` when attribute name is prefixed with tabular index (FabrizioCaldarelli) - Bug #15801: Fixed `has-error` CSS class assignment in `yii\widgets\ActiveField` when attribute name is prefixed with tabular index (FabrizioCaldarelli)
- Bug #15792: Added missing `yii\db\QueryBuilder::conditionClasses` setter (silverfire) - Bug #15792: Added missing `yii\db\QueryBuilder::conditionClasses` setter (silverfire)

View File

@ -1255,9 +1255,13 @@ class BaseHtml
$lines = array_unique(array_merge($lines, $model->getErrorSummary($showAllErrors))); $lines = array_unique(array_merge($lines, $model->getErrorSummary($showAllErrors)));
} }
// If there are the same error messages for different attributes, array_unique will leave gaps
// between sequential keys. Applying array_values to reorder array keys.
$lines = array_values($lines);
if ($encode) { if ($encode) {
for ($i = 0, $linesCount = count($lines); $i < $linesCount; $i++) { foreach ($lines as &$line) {
$lines[$i] = Html::encode($lines[$i]); $line = Html::encode($line);
} }
} }

View File

@ -1319,6 +1319,25 @@ EOD;
); );
} }
/**
* Test that attributes that output same errors, return unique message error
* @see https://github.com/yiisoft/yii2/pull/15859
*/
public function testCollectError()
{
$model = new DynamicModel(compact('attr1', 'attr2'));
$model->addError('attr1', 'error1');
$model->addError('attr1', 'error2');
$model->addError('attr2', 'error1');
$this->assertEquals(
'<div><p>Please fix the following errors:</p><ul><li>error1</li>
<li>error2</li></ul></div>',
Html::errorSummary($model, ['showAllErrors' => true])
);
}
/** /**
* Data provider for [[testActiveTextArea()]]. * Data provider for [[testActiveTextArea()]].
* @return array test data * @return array test data