From 3a265cbf1c59e47bf0e8e80b51a398afc7349e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCder?= Date: Sun, 13 Feb 2022 22:24:12 +0100 Subject: [PATCH] Fixed TCA and Flexform --- Classes/TcaFormElement/PredefinedForm.php | 94 ++++++++++ Classes/TcaFormElement/PredefinedJs.php | 35 ++++ Classes/TcaFormElement/SubmittedValues.php | 53 ++++++ Classes/Utility/TcaUtility.php | 196 --------------------- Configuration/FlexForms/flexform_ds.xml | 20 ++- Configuration/TCA/tx_formhandler_log.php | 6 +- ext_localconf.php | 12 ++ 7 files changed, 213 insertions(+), 203 deletions(-) create mode 100644 Classes/TcaFormElement/PredefinedForm.php create mode 100644 Classes/TcaFormElement/PredefinedJs.php create mode 100644 Classes/TcaFormElement/SubmittedValues.php delete mode 100644 Classes/Utility/TcaUtility.php diff --git a/Classes/TcaFormElement/PredefinedForm.php b/Classes/TcaFormElement/PredefinedForm.php new file mode 100644 index 00000000..d9419f35 --- /dev/null +++ b/Classes/TcaFormElement/PredefinedForm.php @@ -0,0 +1,94 @@ +loadTS($params['flexParentDatabaseRow']['pid']); + + // Check if forms are available + if ( + !is_array($ts['plugin.'] ?? null) || + !is_array($ts['plugin.']['tx_formhandler_pi1.'] ?? null) || + !is_array($ts['plugin.']['tx_formhandler_pi1.']['settings.'] ?? null) || + !is_array($ts['plugin.']['tx_formhandler_pi1.']['settings.']['predef.'] ?? null) || + count($ts['plugin.']['tx_formhandler_pi1.']['settings.']['predef.']) === 0 + ) { + $params['items'][] = [ + 0 => $GLOBALS['LANG']->sL('LLL:EXT:formhandler/Resources/Private/Language/locallang_db.xlf:be_missing_config'), + 1 => '', + ]; + return; + } + + $predef = []; + + // Parse all forms + foreach ($ts['plugin.']['tx_formhandler_pi1.']['settings.']['predef.'] as $key => $form) { + + // Check if form has a name + if (!is_array($form) || !isset($form['name'])){ + continue; + } + + $beName = $form['name']; + + // Check if form name can be translated + $data = explode(':', $form['name']); + if (strtolower($data[0]) === 'lll') { + array_shift($data); + $langFileAndKey = implode(':', $data); + $beName = $GLOBALS['LANG']->sL('LLL:' . $langFileAndKey); + } + $predef[] = [$beName, $key]; + } + + if (count($predef) ==0){ + $params['items'][] = [ + 0 => $GLOBALS['LANG']->sL('LLL:EXT:formhandler/Resources/Private/Language/locallang_db.xlf:be_missing_config'), + 1 => '', + ]; + return; + } + + // Add label + $params['items'][] = [ + 0 => $GLOBALS['LANG']->sL('LLL:EXT:formhandler/Resources/Private/Language/locallang_db.xlf:be_please_select'), + 1 => '', + ]; + + // add to list + $params['items'] = array_merge($params['items'], $predef); + } + + /** + * Loads the TypoScript for the given page id + * + * @param int $pageUid + * @return array The TypoScript setup + */ + private function loadTS(int $pageUid): array + { + /** @var RootlineUtility $rootLine */ + $rootLine = GeneralUtility::makeInstance(RootlineUtility::class, $pageUid)->get(); + + /** @var ExtendedTemplateService $TSObj */ + $TSObj = GeneralUtility::makeInstance(ExtendedTemplateService::class); + $TSObj->tt_track = false; + $TSObj->runThroughTemplates($rootLine); + $TSObj->generateConfig(); + + return $TSObj->setup; + } +} diff --git a/Classes/TcaFormElement/PredefinedJs.php b/Classes/TcaFormElement/PredefinedJs.php new file mode 100644 index 00000000..322a3eaa --- /dev/null +++ b/Classes/TcaFormElement/PredefinedJs.php @@ -0,0 +1,35 @@ +data['tabAndInlineStack'][0][1]; + $newRecord = ($this->data['command']=='new'); + + if ($this->data['vanillaUid'] >0) { + $uid = $this->data['vanillaUid']; + } + + $js = "\n"; + + $result = $this->initializeResultArray(); + $result['html'] = $js; + return $result; + } +} diff --git a/Classes/TcaFormElement/SubmittedValues.php b/Classes/TcaFormElement/SubmittedValues.php new file mode 100644 index 00000000..2622ed21 --- /dev/null +++ b/Classes/TcaFormElement/SubmittedValues.php @@ -0,0 +1,53 @@ +data['parameterArray']; + + $fieldInformationResult = $this->renderFieldInformation(); + $fieldInformationHtml = $fieldInformationResult['html']; + $resultArray = $this->mergeChildReturnIntoExistingResult($this->initializeResultArray(), $fieldInformationResult, false); + + $fieldId = StringUtility::getUniqueId('formengine-textarea-'); + + $attributes = [ + 'id' => $fieldId, + 'name' => htmlspecialchars($parameterArray['itemFormElName']), + 'size' => 30, + 'data-formengine-input-name' => htmlspecialchars($parameterArray['itemFormElName']) + ]; + + $classes = [ + 'form-control', + 't3js-formengine-textarea', + 'formengine-textarea', + ]; + $itemValue = $parameterArray['itemFormElValue']; + $attributes['class'] = implode(' ', $classes); + + $html = []; + $html[] = '
'; + $html[] = $fieldInformationHtml; + $html[] = '
'; + $html[] = '
'; + $html[] = '
'; + $html[] = ''; + $html[] = '
'; + $html[] = '
'; + $html[] = '
'; + $html[] = '
'; + $resultArray['html'] = implode(LF, $html); + + return $resultArray; + } +} diff --git a/Classes/Utility/TcaUtility.php b/Classes/Utility/TcaUtility.php deleted file mode 100644 index 3e21b52a..00000000 --- a/Classes/Utility/TcaUtility.php +++ /dev/null @@ -1,196 +0,0 @@ - - '; - $output .= DebugUtility::viewArray($params); - return $output; - } - - /** - * Adds onchange listener on the drop down menu "predefined". - * If the event is fired and old value was ".default", then empty some fields. - * - * @param array $config - * @return string the javascript - * @author Fabien Udriot - */ - public function addFields_predefinedJS($config) - { - $newRecord = 'true'; - /** @var ServerRequest $request */ - $request = $GLOBALS['TYPO3_REQUEST']; - $editConf = $request->getQueryParams()['edit']['tt_content']; - - if (is_array($editConf) && reset($editConf) === 'edit') { - $newRecord = 'false'; - } - - $uid = null; - if (is_array($editConf)) { - $uid = key($editConf); - } - if ($uid < 0 || empty($uid) || !strstr($uid, 'NEW')) { - $uid = $GLOBALS['SOBE']->elementsData[0]['uid']; - } - - $js = "\n"; - return $js; - } - - /** - * Sets the items for the "Predefined" dropdown. - * - * @param array $config - * @return array The config including the items for the dropdown - */ - public function addFields_predefined($config) - { - $pid = false; - - /** @var ServerRequest $request */ - $request = $GLOBALS['TYPO3_REQUEST']; - $editConf = $request->getQueryParams()['edit']['tt_content']; - - if (is_array($editConf) && reset($editConf) === 'new') { - $pid = key($editConf); - - //Formhandler inserted after existing content element - if ((int)$pid < 0) { - $conn = GeneralUtility::makeInstance(ConnectionPool::class) - ->getConnectionForTable('tt_content'); - $pid = $conn->select(['pid'], 'tt_content', ['uid' => abs($pid)])->fetchColumn(0); - } - } - - $contentUid = $config['row']['uid'] ?: 0; - if (!$pid) { - $conn = GeneralUtility::makeInstance(ConnectionPool::class) - ->getConnectionForTable('tt_content'); - $row = $conn->select(['pid'], 'tt_content', ['uid' => $contentUid])->fetch(); - if ($row) { - $pid = $row['pid']; - } - } - $ts = $this->loadTS($pid); - - $predef = []; - - // no config available - if (!is_array($ts['plugin.']['Tx_Formhandler.']['settings.']['predef.']) || count($ts['plugin.']['Tx_Formhandler.']['settings.']['predef.']) === 0) { - $optionList[] = [ - 0 => $GLOBALS['LANG']->sL('LLL:EXT:formhandler/Resources/Private/Language/locallang_db.xlf:be_missing_config'), - 1 => '', - ]; - return $config['items'] = array_merge($config['items'], $optionList); - } - - // for each view - foreach ($ts['plugin.']['Tx_Formhandler.']['settings.']['predef.'] as $key => $view) { - if (is_array($view)) { - $beName = $view['name']; - if (isset($view['name.']['data'])) { - $data = explode(':', $view['name.']['data']); - if (strtolower($data[0]) === 'lll') { - array_shift($data); - } - $langFileAndKey = implode(':', $data); - $beName = $GLOBALS['LANG']->sL('LLL:' . $langFileAndKey); - } - if (!$predef[$key]) { - $predef[$key] = $beName; - } - } - } - - $optionList = [ - [ - 0 => $GLOBALS['LANG']->sL('LLL:EXT:formhandler/Resources/Private/Language/locallang_db.xlf:be_please_select'), - 1 => '', - ], - ]; - foreach ($predef as $k => $v) { - $optionList[] = [ - 0 => $v, - 1 => $k, - ]; - } - $config['items'] = array_merge($config['items'], $optionList); - return $config; - } - - /** - * Loads the TypoScript for the current page - * - * @param int $pageUid - * @return array The TypoScript setup - */ - public function loadTS($pageUid) - { - $rootLine = GeneralUtility::makeInstance(RootlineUtility::class, $pageUid)->get(); - $TSObj = GeneralUtility::makeInstance(ExtendedTemplateService::class); - $TSObj->tt_track = false; - $TSObj->runThroughTemplates($rootLine); - $TSObj->generateConfig(); - return $TSObj->setup; - } -} diff --git a/Configuration/FlexForms/flexform_ds.xml b/Configuration/FlexForms/flexform_ds.xml index 72364b28..ba5d940d 100644 --- a/Configuration/FlexForms/flexform_ds.xml +++ b/Configuration/FlexForms/flexform_ds.xml @@ -20,13 +20,17 @@ group - folder - tmpl,html,htm + db + sys_file 500 0 1 1 Width:180px + + file + tmpl,html,htm + @@ -37,12 +41,16 @@ group - folder - php,xml + db + sys_file 500 0 1 1 + + file + php,xml + @@ -54,7 +62,7 @@ select selectSingle - Typoheads\Formhandler\Utility\TcaUtility->addFields_predefined + Typoheads\Formhandler\TcaFormElement\PredefinedForm->addItems 1 1 0 @@ -65,7 +73,7 @@ user - Typoheads\Formhandler\Utility\TcaUtility->addFields_predefinedJS + predefinedJs diff --git a/Configuration/TCA/tx_formhandler_log.php b/Configuration/TCA/tx_formhandler_log.php index 27530b4e..f70b8fc8 100644 --- a/Configuration/TCA/tx_formhandler_log.php +++ b/Configuration/TCA/tx_formhandler_log.php @@ -16,6 +16,7 @@ 'exclude' => 1, 'label' => 'LLL:EXT:formhandler/Resources/Private/Language/locallang_db.xlf:tx_formhandler_log.submission_date', 'config' => [ + 'readOnly' => true, 'type' => 'input', 'size' => '10', 'eval' => 'datetime', @@ -27,6 +28,7 @@ 'ip' => [ 'label' => 'LLL:EXT:formhandler/Resources/Private/Language/locallang_db.xlf:tx_formhandler_log.ip', 'config' => [ + 'readOnly' => true, 'type' => 'input', ], ], @@ -34,14 +36,16 @@ 'exclude' => 1, 'label' => 'LLL:EXT:formhandler/Resources/Private/Language/locallang_db.xlf:tx_formhandler_log.params', 'config' => [ + 'readOnly' => true, 'type' => 'user', - 'userFunc' => 'Typoheads\Formhandler\Utility\TcaUtility->getParams', + 'renderType' => 'submittedValues', ], ], 'is_spam' => [ 'exclude' => 1, 'label' => 'LLL:EXT:formhandler/Resources/Private/Language/locallang_db.xlf:tx_formhandler_log.is_spam', 'config' => [ + 'readOnly' => true, 'type' => 'check', ], ], diff --git a/ext_localconf.php b/ext_localconf.php index 613e97ed..7eef80aa 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -23,6 +23,18 @@ ]; } +$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][1638437365] = [ + 'nodeName' => 'predefinedJs', + 'priority' => 40, + 'class' => \Typoheads\Formhandler\TcaFormElement\PredefinedJs::class, +]; + +$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][1638582370] = [ + 'nodeName' => 'submittedValues', + 'priority' => 40, + 'class' => \Typoheads\Formhandler\TcaFormElement\SubmittedValues::class, +]; + $iconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( \TYPO3\CMS\Core\Imaging\IconRegistry::class );