public function __construct($arrAttributes = null) { // check against arrAttributes, as 'onsubmit_callback' => 'multifileupload_moveFiles' does not provide valid attributes if ($arrAttributes !== null && !$arrAttributes['uploadFolder']) { throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['noUploadFolderDeclared'], $this->name)); } $arrAttributes['uploadAction'] = static::$uploadAction; if (TL_MODE == 'FE') { $arrAttributes['uploadActionParams'] = http_build_query(AjaxAction::getParams(MultiFileUpload::NAME, static::$uploadAction)); } $arrAttributes['addRemoveLinks'] = isset($arrAttributes['addRemoveLinks']) ? $arrAttributes['addRemoveLinks'] : true; if (!is_array($arrAttributes['value']) && !Validator::isBinaryUuid($arrAttributes['value'])) { $arrAttributes['value'] = json_decode($arrAttributes['value']); } // bin to string -> never pass binary to the widget!! if ($arrAttributes['value']) { if (is_array($arrAttributes['value'])) { $arrAttributes['value'] = array_map(function ($val) { return \Validator::isBinaryUuid($val) ? \StringUtil::binToUuid($val) : $val; }, $arrAttributes['value']); } else { $arrAttributes['value'] = array(\Validator::isBinaryUuid($arrAttributes['value']) ? \StringUtil::binToUuid($arrAttributes['value']) : $arrAttributes['value']); } } parent::__construct($arrAttributes); $this->objUploader = new MultiFileUpload($arrAttributes); // add onsubmit_callback: move files after form submission $GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback']['multifileupload_moveFiles'] = array('HeimrichHannot\\MultiFileUpload\\FormMultiFileUpload', 'moveFiles'); Ajax::runActiveAction(MultiFileUpload::NAME, MultiFileUpload::ACTION_UPLOAD, $this); }
/** * Auto-generate a form to edit the current database record * * @param integer * @param integer * * @return string */ public function edit($intID = null, $ajaxId = null) { // render if ($this->renderStart) { $this->async = false; // async form submission for start/elements/stop not available yet $this->Template = new \FrontendTemplate($this->strTemplateStart); $this->generateStart(); return \Controller::replaceInsertTags($this->Template->parse(), false); } $this->Template = new \FrontendTemplate($this->strTemplate); if ($this->renderStop) { $this->Template = new \FrontendTemplate($this->strTemplateStop); } if (empty($this->dca)) { return false; } // run callbacks on ajax reload if (is_array($this->dca['config']['onreload_callback'])) { foreach ($this->dca['config']['onreload_callback'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($this); // reload model from database, maybe something has changed in callback if (!$this->saveToBlob) { $this->objActiveRecord->refresh(); } } } if (!$this->getFields()) { return false; } $blnAjax = $this->generateFields($ajaxId); if ($blnAjax) { $objTemplate = $this->generateSubpalette($ajaxId); return \Controller::replaceInsertTags($objTemplate->parse(), false); } if ($this->isSubmitted && $this->isDoNotSubmit()) { $this->runOnValidationError($this->arrInvalidFields); } $blnSubmittedBeforeReset = false; if ($this->isSubmitted && !$this->isDoNotSubmit()) { // run field callbacks, must be before save(), same as contao $this->runCallbacks(); // save for save_callbacks $this->save(); // process form $this->processForm(); // generate messages and remove them from the session automatically $this->Template->message = StatusMessage::generate($this->objModule->id); // single submission will not render form again after submission if ($this->singleSubmission) { $this->invalid = true; } else { if ($this->getReset()) { $this->reset(); $blnSubmittedBeforeReset = true; } } if (in_array('exporter', \ModuleLoader::getActive()) && $this->exportAfterSubmission) { $this->exportAfterSubmission(); } $this->redirectAfterSubmission(); } $this->generateStart(); $this->Template->fields = $this->arrFields; $this->Template->isSubmitted = $this->isSubmitted(); $this->Template->doNotSubmit = $this->isDoNotSubmit(); $this->Template->submission = $this->objActiveRecord; $this->Template->hidden = $this->generateHiddenFields(); $this->Template->invalid = $this->invalid; $this->Template->config = $this->objConfig; $this->compile(); $strBuffer = \Controller::replaceInsertTags($this->Template->parse(), false); Ajax::runActiveAction(Form::FORMHYBRID_NAME, 'asyncFormSubmit', new FormAjax($this, $strBuffer, $blnSubmittedBeforeReset)); Ajax::runActiveAction(Form::FORMHYBRID_NAME, 'reload', new FormAjax($this, $strBuffer)); return $strBuffer; }
/** * Hook upon PageRegular to register modal and render them * * @param $objPage * @param $objLayout * @param $objPageRegular * * @return void */ public function generatePageWithModal($objPage, $objLayout, &$objPageRegular) { // Do not handle the page if no modal item has been specified or page is no regular if (!\Input::get('modals') || $objPage->type != 'regular') { return; } $objModel = ModalModel::findPublishedByIdOrAliasWithoutLinkedPage(\Input::get('modals')); if ($objModel === null && $objPage->linkModal) { $objModel = ModalModel::findPublishedByIdOrAlias($objPage->modal); } $blnCheck = true; if ($objModel === null) { $blnCheck = false; } $objModel = $objModel->current(); $arrConfig = static::getModalConfig($objModel, $objLayout, $objPage); Ajax::runActiveAction(Modal::MODAL_NAME, 'redirect', new ModalAjax($objModel->current(), $arrConfig)); Ajax::runActiveAction(Modal::MODAL_NAME, 'show', new ModalAjax($objModel->current(), $arrConfig)); if (empty($arrConfig)) { $blnCheck = false; } if (!$blnCheck) { /** @var \PageError404 $objHandler */ $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($objPage->id); } $back = \Controller::generateFrontendUrl($objPage->row(), null, null, true); $objModal = new Modal($objModel, $arrConfig); $objModal->setBackLink($back); // render modal within main, as it is the most commonly used region and enabled within contao by default $strBuffer = $objModal->generate(); $objPageRegular->Template->main .= $strBuffer; }