/** * set the value * * @param string $value value * @return \Ameos\AmeosForm\Elements\ElementAbstract this */ public function setValue($value) { if ($this->configuration['encrypt']) { Events::getInstance($this->form->getIdentifier())->registerEvent('form_is_valid', [$this, 'encryptPassword'], ['password' => $value]); } $this->valueSetted = true; $this->value = $value; if ($this->form !== false) { if ($this->form->getMode() == 'crud/extbase' && $value != '') { $method = 'set' . \Ameos\AmeosForm\Utility\StringUtility::camelCase($this->name); if (method_exists($this->form->getModel(), $method)) { $this->form->getModel()->{$method}($value); } } if ($this->form->getMode() == 'crud/classic' && $value != '') { if ($this->form->hasData($this->name)) { $this->form->setData($this->name, $value); } } } return $this; }
/** * return true if the form is valide * * @return bool true if is a valid form */ public function isValid() { if ($this->errorManager->isValid()) { Events::getInstance($this->getIdentifier())->trigger('form_is_valid'); } return $this->errorManager->isValid(); }
/** * set the value * * @todo : fal mode * @param string $value value * @return \Ameos\AmeosForm\Elements\ElementAbstract this */ public function setValue($value) { if (is_array($value)) { if (isset($value['upload']) && is_array($value['upload']) && $value['upload'][0]['name'] != '') { $this->value = $value; $this->determineErrors(); $currentValue = []; if ($this->isValid()) { foreach ($value['upload'] as $uploadFile) { $directory = $this->getUploadDirectory(); $filename = $this->getUploadFilename($uploadFile['name']); $temporaryFilepath = $this->getTemporaryUpdateFilepath($uploadFile['name']); GeneralUtility::upload_copy_move($uploadFile['tmp_name'], $temporaryFilepath); Events::getInstance($this->form->getIdentifier())->registerEvent('form_is_valid', [$this, 'moveTemporaryUploadedFile'], ['destinationFilepath' => $directory . $filename, 'temporaryFilepath' => $temporaryFilepath]); $this->uploadState = 'temporary-upload'; $currentValue[] = basename($temporaryFilepath); } parent::setValue($currentValue); } else { $this->value = null; } } elseif (isset($value['temporary'])) { $currentValue = []; foreach ($value['temporary'] as $uploadFile) { $directory = $this->getUploadDirectory(); $filename = $this->getUploadFilename($value['temporary']); Events::getInstance($this->form->getIdentifier())->registerEvent('form_is_valid', [$this, 'moveTemporaryUploadedFile'], ['destinationFilepath' => $directory . $filename, 'temporaryFilepath' => PATH_site . 'typo3temp/ameos_form/tempupload/' . $value['temporary']]); $this->uploadState = 'temporary-upload'; $currentValue[] = basename($temporaryFilepath); } parent::setValue($currentValue); } } else { if (is_string($this->value) && $this->value != '') { $value = $this->value . ',' . $value; } parent::setValue($value); } return $this; }