/**
  * Initialize the class. Read GET parameters
  *
  * @return void
  */
 protected function init()
 {
     if (isset($_GET['pid'])) {
         $id = intval($_GET['pid']);
     } else {
         $id = intval($_GET['id']);
     }
     $this->componentManager = GeneralUtility::makeInstance(\Typoheads\Formhandler\Component\Manager::class);
     \Typoheads\Formhandler\Utility\GeneralUtility::initializeTSFE($id);
     $elementUID = intval($_GET['uid']);
     $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=' . $elementUID . $GLOBALS['TSFE']->cObj->enableFields('tt_content'));
     if (!empty($row)) {
         $GLOBALS['TSFE']->cObj->data = $row;
         $GLOBALS['TSFE']->cObj->current = 'tt_content_' . $elementUID;
     }
     Globals::setCObj($GLOBALS['TSFE']->cObj);
     $randomID = htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('randomID'));
     Globals::setRandomID($randomID);
     Globals::setAjaxMode(TRUE);
     if (!Globals::getSession()) {
         $ts = $GLOBALS['TSFE']->tmpl->setup['plugin.']['Tx_Formhandler.']['settings.'];
         $sessionClass = \Typoheads\Formhandler\Utility\GeneralUtility::getPreparedClassName($ts['session.'], 'Session\\PHP');
         Globals::setSession($this->componentManager->getComponent($sessionClass));
     }
     $this->settings = Globals::getSession()->get('settings');
     //init ajax
     if ($this->settings['ajax.']) {
         $class = \Typoheads\Formhandler\Utility\GeneralUtility::getPreparedClassName($this->settings['ajax.'], 'AjaxHandler\\JQuery');
         $ajaxHandler = $this->componentManager->getComponent($class);
         Globals::setAjaxHandler($ajaxHandler);
         $ajaxHandler->init($this->settings['ajax.']['config.']);
         $ajaxHandler->initAjax();
     }
 }
 /**
  * Main method of the class.
  *
  * @return string The HTML list of remaining files to be displayed in the form
  */
 public function main()
 {
     $this->init();
     $field = htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('field'));
     if ($field) {
         $randomID = htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('randomID'));
         \Typoheads\Formhandler\Utility\Globals::setCObj($GLOBALS['TSFE']->cObj);
         \Typoheads\Formhandler\Utility\Globals::setRandomID($randomID);
         if (!\Typoheads\Formhandler\Utility\Globals::getSession()) {
             $ts = $GLOBALS['TSFE']->tmpl->setup['plugin.']['Tx_Formhandler.']['settings.'];
             $sessionClass = \Typoheads\Formhandler\Utility\GeneralUtility::getPreparedClassName($ts['session.'], 'Session\\PHP');
             \Typoheads\Formhandler\Utility\Globals::setSession($this->componentManager->getComponent($sessionClass));
         }
         $this->settings = \Typoheads\Formhandler\Utility\Globals::getSession()->get('settings');
         \Typoheads\Formhandler\Utility\Globals::setFormValuesPrefix(\Typoheads\Formhandler\Utility\GeneralUtility::getSingle($this->settings, 'formValuesPrefix'));
         $gp = \Typoheads\Formhandler\Utility\GeneralUtility::getMergedGP();
         $validator = $this->componentManager->getComponent('\\Typoheads\\Formhandler\\Validator\\Ajax');
         $errors = [];
         $valid = $validator->validateAjax($field, $gp, $errors);
         if ($valid) {
             $content = \Typoheads\Formhandler\Utility\GeneralUtility::getSingle($this->settings['ajax.']['config.'], 'ok');
             if (strlen($content) === 0) {
                 $content = '<img src="' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('formhandler') . 'Resources/Public/Images/ok.png' . '" />';
             } else {
                 $gp = [$_GET['field'] => $_GET['value']];
                 $view = $this->initView($content);
                 $content = $view->render($gp, $errors);
             }
             $content = sprintf($this->templates['spanSuccess'], $content);
         } else {
             $content = \Typoheads\Formhandler\Utility\GeneralUtility::getSingle($this->settings['ajax.']['config.'], 'notOk');
             if (strlen($content) === 0) {
                 $content = '<img src="' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('formhandler') . 'Resources/Public/Images/notok.png' . '" />';
             } else {
                 $view = $this->initView($content);
                 $gp = [$_GET['field'] => $_GET['value']];
                 $content = $view->render($gp, $errors);
             }
             $content = sprintf($this->templates['spanError'], $content);
         }
         print $content;
     }
 }