/** * @inheritdoc */ public function beforeValidate() { /** @var BaseActiveRecord $model */ $model = $this->owner; if (empty($this->crop_field)) { $this->crop_value = $model->getAttribute($this->attribute); $this->crop_changed = !empty($this->crop_value); } else { $this->crop_value = $model->getAttribute($this->crop_field); $this->crop_changed = $model->isAttributeChanged($this->crop_field); } parent::beforeValidate(); }
/** * @inheritdoc */ public function beforeValidate() { /** @var BaseActiveRecord $model */ $model = $this->owner; if (in_array($model->scenario, $this->scenarios) && ($crops = $model->getAttribute($this->attribute)) && is_array($crops)) { $image_changed = !$model->getOldAttribute($this->attribute) && $crops['file'] || $model->getOldAttribute($this->attribute) != $crops['file']; $this->getConfigurations(); foreach ($this->crops_internal as $ind => &$crop) { $crop['value'] = $crops[$ind]; if ($crops[$ind] == '-') { $crops[$ind] = ''; } if (empty($crop['crop_field'])) { $crop['_changed'] = !empty($crops[$ind]); } else { $crop['_changed'] = $crops[$ind] != $model->getAttribute($crop['crop_field']); $model->setAttribute($crop['crop_field'], $crops[$ind]); } if ($image_changed) { $crop['_changed'] = true; } else { if ($model->getOldAttribute($this->attribute) == null) { $crop['_changed'] = false; } } } $model->setAttribute($this->attribute, $crops['file']); } parent::beforeValidate(); }