protected function compile()
 {
     $this->Template->headline = $this->headline;
     $this->Template->hl = $this->hl;
     $this->Template->wrapperClass = $this->strWrapperClass;
     $this->Template->wrapperId = $this->strWrapperId;
     $this->strFormId = $this->formHybridDataContainer . '_' . $this->id;
     // Do not change this order (see #6191)
     $this->Template->style = !empty($this->arrStyle) ? implode(' ', $this->arrStyle) : '';
     $this->Template->class = trim('mod_' . $this->type . ' ' . $this->cssID[1]);
     $this->Template->cssID = $this->cssID[0] != '' ? ' id="' . $this->cssID[0] . '"' : '';
     $this->Template->inColumn = $this->strColumn;
     if ($this->Template->headline == '') {
         $this->Template->headline = $this->headline;
     }
     if ($this->Template->hl == '') {
         $this->Template->hl = $this->hl;
     }
     if (!empty($this->objModel->classes) && is_array($this->objModel->classes)) {
         $this->Template->class .= ' ' . implode(' ', $this->objModel->classes);
     }
     if ($this->intId && !is_numeric($this->intId)) {
         $strItemClass = \Model::getClassFromTable($this->formHybridDataContainer);
         $strAliasField = $this->aliasField ?: 'id';
         if (($objItem = $strItemClass::findOneBy($strAliasField, $this->intId)) !== null && (!$this->addShareCol || !FormHybridList::shareTokenExpiredOrEmpty($objItem, time()))) {
             $this->intId = $objItem->id;
         }
     }
     if (!$this->intId) {
         if (!$this->blnSilentMode) {
             StatusMessage::addError($GLOBALS['TL_LANG']['formhybrid_list']['noIdFound'], $this->id, 'noidfound');
         }
         $this->Template->invalid = true;
     } else {
         if (!$this->checkEntityExists($this->intId)) {
             if (!$this->blnSilentMode) {
                 StatusMessage::addError($GLOBALS['TL_LANG']['formhybrid_list']['notExisting'], $this->id, 'noentity');
             }
             $this->Template->invalid = true;
         } else {
             if ($this->checkPermission($this->intId)) {
                 $strItemClass = \Model::getClassFromTable($this->formHybridDataContainer);
                 if (($objItem = $strItemClass::findByPk($this->intId)) !== null) {
                     if ($this->blnUseBlob && $objItem->formHybridBlob) {
                         $arrBlob = deserialize($objItem->formHybridBlob, true);
                         foreach ($arrBlob as $strField => $varValue) {
                             if ($strField == 'formHybridBlob') {
                                 continue;
                             }
                             $objItem->{$strField} = $varValue;
                         }
                         $objItem->formHybridBlob = null;
                     }
                     // redirect on specific field value
                     //						DC_Hybrid::doFieldDependentRedirect($this, $objItem);
                     // page title
                     if ($this->setPageTitle) {
                         global $objPage;
                         $objPage->pageTitle = $objItem->{$this->pageTitleField};
                         if ($this->pageTitlePattern) {
                             $objPage->pageTitle = preg_replace_callback('@%([^%]+)%@i', function ($arrMatches) use($objItem) {
                                 return $objItem->{$arrMatches[1]};
                             }, $this->pageTitlePattern);
                         }
                     }
                     // comments
                     if ($this->noComments || !in_array('comments', \ModuleLoader::getActive()) || !\Database::getInstance()->fieldExists('pid', $this->formHybridDataContainer)) {
                         $this->Template->allowComments = false;
                     } else {
                         $objArchive = $objItem->getRelated('pid');
                         $this->Template->allowComments = $objArchive->allowComments;
                         if ($objArchive->allowComments) {
                             // Adjust the comments headline level
                             $intHl = min(intval(str_replace('h', '', $this->hl)), 5);
                             $this->Template->hlc = 'h' . ($intHl + 1);
                             $objComments = \System::importStatic('HeimrichHannot\\FormHybridList\\Comments');
                             $arrNotifies = array();
                             // Notify the system administrator
                             if ($objArchive->notify != 'notify_author') {
                                 $arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL'];
                             }
                             // Notify the author
                             if ($objArchive->notify != 'notify_admin') {
                                 if (($objAuthor = $objItem->getRelated('memberAuthor')) !== null && $objAuthor->email != '') {
                                     $arrNotifies[] = $objAuthor->email;
                                 }
                             }
                             $objConfig = new \stdClass();
                             $objConfig->perPage = $objArchive->perPage;
                             $objConfig->order = $objArchive->sortOrder;
                             $objConfig->template = $this->com_template;
                             $objConfig->requireLogin = $objArchive->requireLogin;
                             $objConfig->disableCaptcha = $objArchive->disableCaptcha;
                             $objConfig->bbcode = $objArchive->bbcode;
                             $objConfig->moderate = $objArchive->moderate;
                             $objComments->addCommentsToTemplate($this->Template, $objConfig, $this->formHybridDataContainer, $objItem->id, $arrNotifies);
                         }
                     }
                     $strItem = $this->replaceInsertTags($this->parseItem($objItem));
                     if (\Environment::get('isAjaxRequest') && \Input::get('scope') == 'modal' || $this->useModalWrapperSync) {
                         if (\Input::post('FORM_SUBMIT') == 'com_' . $this->formHybridDataContainer . '_' . $objItem->id) {
                             if (\Input::post('reload')) {
                                 die;
                             } else {
                                 $this->Template->item = $strItem;
                                 die($this->Template->parse());
                             }
                         } else {
                             $objModalWrapper = new \FrontendTemplate($this->modalTpl ?: 'formhybrid_reader_modal_bootstrap');
                             $objModalWrapper->setData($objItem->row() + $this->arrData);
                             $this->Template->item = $strItem;
                             $objModalWrapper->item = $this->Template->parse();
                             // active modal from synchronous request
                             if (!$this->useModalWrapperSync) {
                                 $objModalWrapper->active = true;
                                 die($objModalWrapper->parse());
                             }
                             $this->Template->item = $objModalWrapper->parse();
                         }
                     } else {
                         $this->Template->item = $strItem;
                     }
                 }
             } else {
                 if (!$this->blnSilentMode) {
                     StatusMessage::addError($GLOBALS['TL_LANG']['formhybrid_list']['noPermission'], $this->id, 'nopermission');
                 }
                 $this->Template->invalid = true;
             }
         }
     }
 }
 protected function compile()
 {
     $this->Template->headline = $this->headline;
     $this->Template->hl = $this->hl;
     $this->Template->wrapperClass = $this->strWrapperClass;
     $this->Template->wrapperId = $this->strWrapperId;
     $this->strFormId = $this->formHybridDataContainer . '_' . $this->id;
     $strAction = $this->defaultAction ?: \Input::get('act');
     $this->arrEditable = deserialize($this->formHybridEditable, true);
     $this->strToken = $this->strToken ?: \Input::get('token');
     // Do not change this order (see #6191)
     $this->Template->style = !empty($this->arrStyle) ? implode(' ', $this->arrStyle) : '';
     $this->Template->class = trim('mod_' . $this->type . ' ' . $this->cssID[1]);
     $this->Template->cssID = $this->cssID[0] != '' ? ' id="' . $this->cssID[0] . '"' : '';
     $this->Template->inColumn = $this->strColumn;
     if ($this->Template->headline == '') {
         $this->Template->headline = $this->headline;
     }
     if ($this->Template->hl == '') {
         $this->Template->hl = $this->hl;
     }
     if (!empty($this->classes) && is_array($this->classes)) {
         $this->Template->class .= ' ' . implode(' ', $this->classes);
     }
     $this->addDefaultArchive();
     // at first check for the correct request token to be set
     if (!$this->deactivateTokens && !\RequestToken::validate($this->strToken)) {
         if (!$this->blnSilentMode) {
             StatusMessage::addError(sprintf($GLOBALS['TL_LANG']['frontendedit']['requestTokenExpired'], Url::replaceParameterInUri(Url::getUrl(), 'token', \RequestToken::get())), $this->id, 'requestTokenExpired');
         }
         return;
     }
     if ($this->formHybridAllowIdAsGetParameter) {
         $intId = \Input::get($this->formHybridIdGetParameter);
         if (is_numeric($intId)) {
             $this->intId = $intId;
         }
     }
     $strItemClass = \Model::getClassFromTable($this->formHybridDataContainer);
     // get id from share
     if ($strShare = \Input::get('share')) {
         if (($objItem = $strItemClass::findByShareToken($strShare)) !== null && !FormHybridList::shareTokenExpiredOrEmpty($objItem, time())) {
             $this->intId = $objItem->id;
         }
     }
     if (!$this->intId) {
         if (isset($GLOBALS['TL_HOOKS']['frontendEditAddNoIdBehavior']) && is_array($GLOBALS['TL_HOOKS']['frontendEditAddNoIdBehavior'])) {
             foreach ($GLOBALS['TL_HOOKS']['frontendEditAddNoIdBehavior'] as $arrCallback) {
                 $this->import($arrCallback[0]);
                 if ($this->{$arrCallback}[0]->{$arrCallback}[1]($this) === false) {
                     return;
                 }
             }
         }
         if ($this->noIdBehavior == 'error') {
             if (!$this->blnSilentMode) {
                 StatusMessage::addError($GLOBALS['TL_LANG']['frontendedit']['noIdFound'], $this->id, 'noidfound');
             }
             return;
         } elseif ($this->noIdBehavior == 'redirect' || $this->noIdBehavior == 'create_until') {
             $arrConditions = deserialize($this->existanceConditions, true);
             if ($this->existanceConditions && !empty($arrConditions)) {
                 $arrColumns = array();
                 $arrValues = array();
                 foreach ($arrConditions as $arrCondition) {
                     if (!$arrCondition['field']) {
                         continue;
                     }
                     $arrColumns[] = $arrCondition['field'] . '=?';
                     $arrValues[] = $this->replaceInsertTags($arrCondition['value']);
                 }
                 if (!empty($arrColumns) && ($objItem = $strItemClass::findOneBy($arrColumns, $arrValues)) !== null) {
                     $this->intId = $objItem->id;
                 }
             }
         }
         if (!$this->intId) {
             if ($this->noIdBehavior == 'redirect') {
                 if (!$this->blnSilentMode) {
                     StatusMessage::addError($GLOBALS['TL_LANG']['frontendedit']['noIdFound'], $this->id, 'noidfound');
                 }
                 return;
             } else {
                 $strFormId = FormHelper::getFormId($this->formHybridDataContainer, $this->id);
                 // get id from FormSession
                 if ($_POST) {
                     if ($intId = FormSession::getSubmissionId($strFormId)) {
                         $this->intId = $intId;
                     }
                 }
                 if (!$this->intId) {
                     // if no id is given a new instance is initiated
                     $objConfiguration = new FormConfiguration($this->arrData);
                     // ajax handling, required in this manor, as we have no real ajax controller in contao and ajax request not related to this module
                     // might trigger this module beforhand and new submission will be created after the submission was transfered to the user and id wont match any more
                     if (Ajax::isRelated(Form::FORMHYBRID_NAME) !== null) {
                         if ($intId = FormSession::getSubmissionId($strFormId)) {
                             $this->intId = $intId;
                         } else {
                             $objConfiguration->forceCreate = true;
                         }
                     }
                     $this->objForm = new $this->strFormClass($objConfiguration, $this->arrSubmitCallbacks, $this->intId ?: 0, $this);
                     if ($intId = $this->objForm->getId()) {
                         $this->intId = $intId;
                     }
                 }
             }
         }
     }
     // intId is set at this point!
     if (!$this->checkEntityExists($this->intId)) {
         if (!$this->blnSilentMode) {
             StatusMessage::addError($GLOBALS['TL_LANG']['formhybrid_list']['noPermission'], $this->id, 'nopermission');
         }
         if (Ajax::isRelated(Form::FORMHYBRID_NAME)) {
             $objResponse = new ResponseError();
             $objResponse->setResult(StatusMessage::generate($this->id));
             $objResponse->output();
         }
         return;
     }
     // page title
     if ($this->setPageTitle) {
         global $objPage;
         if (($objItem = General::getModelInstance($this->formHybridDataContainer, $this->intId)) !== null) {
             $objPage->pageTitle = $objItem->{$this->pageTitleField};
         }
     }
     if ($strAction == FRONTENDEDIT_ACT_DELETE) {
         if ($this->checkDeletePermission($this->intId)) {
             $blnResult = $this->deleteItem($this->intId);
             if (\Environment::get('isAjaxRequest')) {
                 die($blnResult);
             }
             // return to the list
             \Controller::redirect(Url::removeQueryString(array('act', 'id', 'token'), Url::getUrl()));
         } else {
             if (!$this->blnSilentMode) {
                 StatusMessage::addError($GLOBALS['TL_LANG']['formhybrid_list']['noPermission'], $this->id, 'nopermission');
             }
             return;
         }
     } else {
         if ($this->checkUpdatePermission($this->intId)) {
             // create a new lock if necessary
             if (in_array('entity_lock', \ModuleLoader::getActive()) && $this->addEntityLock) {
                 if (\HeimrichHannot\EntityLock\EntityLockModel::isLocked($this->formHybridDataContainer, $this->intId, $this)) {
                     $objLock = \HeimrichHannot\EntityLock\EntityLockModel::findActiveLock($this->formHybridDataContainer, $this->intId, $this);
                     $objItem = General::getModelInstance($this->formHybridDataContainer, $this->intId);
                     if (!$this->blnSilentMode) {
                         $strMessage = \HeimrichHannot\EntityLock\EntityLock::generateErrorMessage($this->formHybridDataContainer, $this->intId, $this);
                         if ($this->allowLockDeletion) {
                             $strUnlockForm = $this->generateUnlockForm($objItem, $objLock);
                             $strMessage .= $strUnlockForm;
                         }
                         StatusMessage::addError($strMessage, $this->id, 'locked');
                     }
                     if ($this->readOnlyOnLocked) {
                         $this->formHybridViewMode = FORMHYBRID_VIEW_MODE_READONLY;
                         $this->formHybridReadonlyTemplate = 'formhybridreadonly_default';
                     } else {
                         return;
                     }
                 } else {
                     \HeimrichHannot\EntityLock\EntityLockModel::create($this->formHybridDataContainer, $this->intId, $this);
                 }
             }
             if ($this->objForm === null) {
                 $this->objForm = new $this->strFormClass(new FormConfiguration($this->arrData), $this->arrSubmitCallbacks, $this->intId, $this);
             }
             $this->Template->form = $this->objForm->generate();
             $this->Template->item = $this->objForm->activeRecord;
             if (\Environment::get('isAjaxRequest') && \Input::get('scope') == 'modal') {
                 $objItem = General::getModelInstance($this->formHybridDataContainer, $this->intId);
                 $objModalWrapper = new \FrontendTemplate($this->modalTpl ?: 'formhybrid_reader_modal_bootstrap');
                 if ($objItem !== null) {
                     $objModalWrapper->setData($objItem->row());
                 }
                 $objModalWrapper->module = Arrays::arrayToObject($this->arrData);
                 $objModalWrapper->item = $this->replaceInsertTags($this->Template->parse());
                 die($objModalWrapper->parse());
             }
         } else {
             if (!$this->blnSilentMode) {
                 StatusMessage::addError($GLOBALS['TL_LANG']['formhybrid_list']['noPermission'], $this->id, 'nopermission');
             }
             return;
         }
     }
 }
 protected function compile()
 {
     $strAct = \Input::get('act');
     if ($strAct == FormHybridList::ACT_SHARE && $this->addShareCol) {
         $strUrl = \Input::get('url');
         $intId = \Input::get($this->formHybridIdGetParameter);
         $strModelClass = \Model::getClassFromTable($this->formHybridDataContainer);
         if (($objEntity = $strModelClass::findByPk($intId)) !== null) {
             $intNow = time();
             if (FormHybridList::shareTokenExpiredOrEmpty($objEntity, $intNow)) {
                 $strShareToken = str_replace('.', '', uniqid('', true));
                 $objEntity->shareToken = $strShareToken;
                 $objEntity->shareTokenTime = $intNow;
                 $objEntity->save();
             }
             if ($this->shareAutoItem) {
                 $strShareUrl = $strUrl . '/' . $objEntity->shareToken;
             } else {
                 $strShareUrl = Url::addQueryString('share=' . $objEntity->shareToken, $strUrl);
             }
             die($strShareUrl);
         }
     }
     $this->Template->headline = $this->headline;
     $this->Template->hl = $this->hl;
     $this->Template->wrapperClass = $this->strWrapperClass;
     $this->Template->wrapperId = $this->strWrapperId;
     $this->Template->addInfiniteScroll = $this->addInfiniteScroll;
     $this->arrSkipInstances = deserialize($this->skipInstances, true);
     $this->arrTableFields = deserialize($this->tableFields, true);
     $this->addDefaultValues = $this->formHybridAddDefaultValues;
     $this->arrDefaultValues = deserialize($this->formHybridDefaultValues, true);
     $this->arrConjunctiveMultipleFields = deserialize($this->conjunctiveMultipleFields, true);
     if ($this->addDisjunctiveFieldGroups) {
         $arrResult = array();
         foreach (deserialize($this->disjunctiveFieldGroups, true) as $intGroup => $arrGroup) {
             $arrResult[$intGroup] = $arrGroup['fields'];
         }
         $this->arrDisjunctionFieldGroups = $arrResult;
     }
     $this->Template->currentSorting = $this->getCurrentSorting();
     global $objPage;
     $this->listUrl = \Controller::generateFrontendUrl($objPage->row());
     if ($this->useModal) {
         $objModalWrapper = new \FrontendTemplate($this->modalWrapperTpl ?: 'formhybrid_reader_modal_wrapper_bootstrap');
         $objModalWrapper->setData($this->arrData);
         $this->Template->modalWrapper = $objModalWrapper->parse();
     }
     $this->addColumns();
     // set initial filters
     $this->initInitialFilters();
     // set default filter values
     if ($this->addDefaultValues) {
         $this->applyDefaultFilters();
     }
     if ($this->hasHeader) {
         $this->Template->header = $this->getHeader();
     }
     if (!$this->hideFilter) {
         $this->objFilterForm = new ListFilterForm($this);
         $this->Template->filterForm = $this->objFilterForm->generate();
     }
     if (!$this->hideFilter && $this->objFilterForm->isSubmitted() && !$this->objFilterForm->doNotSubmit()) {
         // submission ain't formatted
         list($objItems, $this->Template->count) = $this->getItems($this->objFilterForm->getSubmission(false));
         $this->Template->isSubmitted = $this->objFilterForm->isSubmitted();
     } elseif ($this->showInitialResults) {
         list($objItems, $this->Template->count) = $this->getItems();
     }
     // Add the items
     if ($objItems !== null) {
         $this->Template->items = $this->parseItems($objItems);
     }
 }