Skip to content
This repository was archived by the owner on Nov 4, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions Classes/TcaFormElement/PredefinedForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php
declare(strict_types = 1);
namespace Typoheads\Formhandler\TcaFormElement;

use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\RootlineUtility;

class PredefinedForm
{
/**
* Add predefined forms item list
*
* @param array $params
*/
public function addItems(array &$params): void
{
$ts = $this->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;
}
}
35 changes: 35 additions & 0 deletions Classes/TcaFormElement/PredefinedJs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
declare(strict_types = 1);
namespace Typoheads\Formhandler\TcaFormElement;

use TYPO3\CMS\Backend\Form\Element\AbstractFormElement;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

class PredefinedJs extends AbstractFormElement
{
public function render()
{
$uid = null;
$divId = $this->data['tabAndInlineStack'][0][1];
$newRecord = ($this->data['command']=='new');

if ($this->data['vanillaUid'] >0) {
$uid = $this->data['vanillaUid'];
}

$js = "<script>\n";
$js .= "/*<![CDATA[*/\n";


$js .= "var uid = '".$uid."'\n";
$js .= "var flexformBoxId = '".$divId."'\n";
$js .= 'var newRecord = '.$newRecord."\n";
$js .= file_get_contents(ExtensionManagementUtility::extPath('formhandler').'Resources/Public/JavaScript/addFields_predefinedJS.js');
$js .= "/*]]>*/\n";
$js .= "</script>\n";

$result = $this->initializeResultArray();
$result['html'] = $js;
return $result;
}
}
53 changes: 53 additions & 0 deletions Classes/TcaFormElement/SubmittedValues.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
declare(strict_types = 1);
namespace Typoheads\Formhandler\TcaFormElement;

use TYPO3\CMS\Backend\Form\Element\AbstractFormElement;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility;

class SubmittedValues extends AbstractFormElement
{
public function render():array
{
$parameterArray = $this->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[] = '<div class="formengine-field-item t3js-formengine-field-item" style="padding: 5px;">';
$html[] = $fieldInformationHtml;
$html[] = '<div class="form-wizards-wrap">';
$html[] = '<div class="form-wizards-element">';
$html[] = '<div class="form-control-wrap">';
$html[] = '<textarea readonly rows="15" '.GeneralUtility::implodeAttributes($attributes, true).' >';
$html[]= htmlspecialchars($itemValue, ENT_QUOTES);
$html[]= '</textarea>';
$html[] = '</div>';
$html[] = '</div>';
$html[] = '</div>';
$html[] = '</div>';
$resultArray['html'] = implode(LF, $html);

return $resultArray;
}
}
196 changes: 0 additions & 196 deletions Classes/Utility/TcaUtility.php

This file was deleted.

Loading