/** * @inheritdoc */ public function beforeSave() { parent::beforeSave(); if ($this->crop_changed && !empty($this->cropped_field)) { $this->delete($this->cropped_field, true); /** @var BaseActiveRecord $model */ $model = $this->owner; $name = $model->getAttribute($this->attribute); if (empty($name)) { $model->setAttribute($this->attribute, $model->getOldAttribute($this->attribute)); } $model->setAttribute($this->cropped_field, $this->getCropFileName($model->getAttribute($this->attribute))); } }
/** * @inheritdoc */ public function beforeSave() { parent::beforeSave(); /** @var BaseActiveRecord $model */ $model = $this->owner; if (in_array($model->scenario, $this->scenarios)) { $original = $model->getAttribute($this->attribute); if (!$original) { $original = $model->getOldAttribute($this->attribute); } foreach ($this->getConfigurations() as $crop) { if (isset($crop['_changed']) && $crop['_changed'] && !empty($crop['cropped_field'])) { $this->delete($crop['cropped_field'], true); if (!empty($crop['cropped_field'])) { $model->setAttribute($crop['cropped_field'], $this->getCropFileName($original)); } } } } }