Browse Source

Issue #15957: dropped deprecated UniqueValidator::$comboNotUnique (#15976)

See also PR #12305
tags/3.0.0-alpha1
Pavel Ivanov 7 years ago committed by Alexander Makarov
parent
commit
741a569695
  1. 17
      framework/validators/UniqueValidator.php
  2. 10
      tests/framework/validators/UniqueValidatorTest.php

17
framework/validators/UniqueValidator.php

@ -82,13 +82,6 @@ class UniqueValidator extends Validator
*/
public $message;
/**
* @var string
* @since 2.0.9
* @deprecated since version 2.0.10, to be removed in 2.1. Use [[message]] property
* to setup custom message for multiple target attributes.
*/
public $comboNotUnique;
/**
* @var string and|or define how target attributes are related
* @since 2.0.11
*/
@ -110,12 +103,7 @@ class UniqueValidator extends Validator
return;
}
if (is_array($this->targetAttribute) && count($this->targetAttribute) > 1) {
// fallback for deprecated `comboNotUnique` property - use it as message if is set
if ($this->comboNotUnique === null) {
$this->message = Yii::t('yii', 'The combination {values} of {attributes} has already been taken.');
} else {
$this->message = $this->comboNotUnique;
}
$this->message = Yii::t('yii', 'The combination {values} of {attributes} has already been taken.');
} else {
$this->message = Yii::t('yii', '{attribute} "{value}" has already been taken.');
}
@ -280,7 +268,8 @@ class UniqueValidator extends Validator
}
/**
* Builds and adds [[comboNotUnique]] error message to the specified model attribute.
* Builds and adds error message to the specified model attribute.
* Should be used when [[targetAttribute]] is an array (is a combination of attributes).
* @param \yii\base\Model $model the data model.
* @param string $attribute the name of the attribute.
*/

10
tests/framework/validators/UniqueValidatorTest.php

@ -61,16 +61,6 @@ abstract class UniqueValidatorTest extends DatabaseTestCase
$validator->validateAttribute($model, 'order_id');
$this->assertTrue($model->hasErrors('order_id'));
$this->assertEquals($customError, $model->getFirstError('order_id'));
// fallback for deprecated `comboNotUnique` - should be removed on 2.1.0
$validator = new UniqueValidator([
'targetAttribute' => ['order_id', 'item_id'],
'comboNotUnique' => 'Custom message for {attributes} with values {values}',
]);
$model->clearErrors();
$validator->validateAttribute($model, 'order_id');
$this->assertTrue($model->hasErrors('order_id'));
$this->assertEquals($customError, $model->getFirstError('order_id'));
}
public function testValidateInvalidAttribute()

Loading…
Cancel
Save