Example #1
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return array_merge(parent::behaviors(), ['sluggable' => ['class' => SluggableBehavior::className(), 'attribute' => 'name', 'ensureUnique' => true], 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => false], 'files' => ['class' => FilesBehavior::className(), 'attributes' => ['uploadedImage' => ['filesystem' => 'local', 'path' => '/categories', 'fileName' => '{model.slug}.{file.extension}', 'relation' => 'image', 'deleteOnUnlink' => true, 'on beforeSave' => function (FileInterface $file) {
         $image = ImageManagerStatic::make($file->getPath());
         $image->resize(300, null, function (Constraint $constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         });
         $image->save($file->getPath(), 100);
     }]]], 'relations' => ['class' => RelationsBehavior::className(), 'settings' => ['image' => ['deleteOnUnlink' => true]], 'relations' => ['imageRelation' => $this->hasOne(ProductCategoryFile::className(), ['id' => 'image_id'])]]]);
 }