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); }
/** * This method will be called when the component (or component's parent) * becomes attached to a monitored object. Do not call this method yourself. * @param IComponent $form * @return void */ protected function attached($form) { parent::attached($form); if ($form instanceof IPresenter) { if (isset($form->imageStorage) && $form->imageStorage instanceof IImageStorage) { $this->storage = $form->imageStorage; } else { $this->storage = $form->context->getByType(IImageStorage::class); } $form = $this->getForm(); $htmlName = str_replace('[]', '', $this->getHtmlName()); foreach ($this->defaultValues as $i => $defaultValue) { $checkbox = new Checkbox(); $checkbox->setParent($form, $i); $checkbox->setPrepend($htmlName . $i); $checkbox->setStorage($this->storage); $checkbox->setImageName($defaultValue); $this->checkboxes[] = $checkbox; } if ($this->required && !$this->getCheckboxesFine()) { $this->addRule(Form::FILLED, $this->getRequiredMessage()); } } }