Example #1
0
 protected function successCallback()
 {
     if ($this->delete && $this->defaultValue) {
         $this->storage->delete($this->defaultValue);
         $this->defaultValue = NULL;
     }
     if ($this->value instanceof FileUpload && $this->value->isOk()) {
         // Upload
         $image = $this->value->toImage();
         foreach (array_merge($this->onBeforeSave, $this->onUpload) as $callback) {
             Callback::check($callback);
             $image = $callback($image);
             if (!$image instanceof Image) {
                 throw new ImageStorageException('Callback must return value instance of Nette\\Utils\\Image');
             }
         }
         $this->uploadedImage = $this->value = $this->storage->saveImage($image, $this->value->getSanitizedName(), $this->namespace, function ($image) {
             foreach ($this->onSave as $callback) {
                 Callback::check($callback);
                 $callback($image);
             }
         });
     } else {
         $this->value = $this->defaultValue;
     }
     $this->checkbox->setImageName($this->value);
 }