* @since 2.0 */ class DefaultValueValidator extends Validator { /** * @var mixed the default value to be set to the specified attributes. */ public $value; /** * @var boolean whether to set the default [[value]] only when the attribute is [[isEmpty|empty]]. * Defaults to true. If false, the attribute will always be assigned with the default [[value]], * no matter it is empty or not. */ public $setOnEmpty = true; /** * Validates the attribute of the object. * @param \yii\base\Model $object the object being validated * @param string $attribute the attribute being validated */ public function validateAttribute($object, $attribute) { if (!$this->setOnEmpty || $this->isEmpty($object->$attribute)) { $object->$attribute = $this->value; } } }