title = $slider->title; $this->tagline = $slider->tagline; $this->url = $slider->url; $this->sort = $slider->sort; } parent::__construct($config); } public function rules(): array { $imageValidator = new ImageValidator(); $maxSize = $imageValidator->getSizeLimit() < 20*1024*1024 ? $imageValidator->getSizeLimit() : 20*1024*1024; return [ [['title', 'image'], 'required', 'on' => Slider::SCENARIO_CREATE], [['title'], 'required', 'on' => Slider::SCENARIO_UPDATE], [['sort'], 'integer'], [['title'], 'string', 'max' => 128], [['tagline', 'url'], 'string', 'max' => 255], [['image'], 'image', 'extensions' => 'jpg,png,gif', 'skipOnEmpty' => true, 'maxSize' => $maxSize], ]; } public function attributeLabels() { return [ 'title' => Yii::t('slider', 'Title'), 'tagline' => Yii::t('slider', 'Tagline'), 'image' => Yii::t('slider', 'Image'), 'url' => Yii::t('slider', 'URL'), 'sort' => Yii::t('slider', 'Sort'), ]; } public function beforeValidate(): bool { if (parent::beforeValidate()) { $this->image = UploadedFile::getInstance($this, 'image'); return true; } return false; } }