From 1d297039349ec8257dd1b37251d931bc90948400 Mon Sep 17 00:00:00 2001
From: Torsten Oppermann <torsten@sgalinski.de>
Date: Tue, 18 Sep 2018 14:18:22 +0200
Subject: [PATCH] [TASK] Fixing a bug with the file security hash

---
 Classes/XClass/Form/FormEditorController.php | 68 ++++++++++----------
 1 file changed, 33 insertions(+), 35 deletions(-)

diff --git a/Classes/XClass/Form/FormEditorController.php b/Classes/XClass/Form/FormEditorController.php
index e3a7791d..abf5e5c4 100644
--- a/Classes/XClass/Form/FormEditorController.php
+++ b/Classes/XClass/Form/FormEditorController.php
@@ -69,6 +69,8 @@ class FormEditorController extends \TYPO3\CMS\Form\Controller\FormEditorControll
 	 * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
 	 */
 	public function saveFormAction(string $formPersistenceIdentifier, FormDefinitionArray $formDefinition) {
+
+		$registrationService = $this->objectManager->get(RegisterService::class);
 		/** @noinspection PhpInternalEntityUsedInspection */
 		parent::saveFormAction($formPersistenceIdentifier, $formDefinition);
 
@@ -79,8 +81,6 @@ class FormEditorController extends \TYPO3\CMS\Form\Controller\FormEditorControll
 
 		/** @var array $finishers */
 		$finishers = $formDefinition['finishers'];
-		$extensionKey = '';
-		$templateKey = '';
 
 		foreach ($finishers as $finisher) {
 
@@ -95,51 +95,49 @@ class FormEditorController extends \TYPO3\CMS\Form\Controller\FormEditorControll
 
 			// retrieve the extension and template key and jump out of loop
 			$extensionKey = $finisher['options']['extension'];
-			$templateKey = $finisher['options']['template'];
-			break;
-		}
-
-		// if no template key was explicitly set, use the form identifier as template key
-		if ($templateKey === '') {
-			$templateKey = $formDefinition['identifier'];
-		}
+			$templateKey = str_replace('_', '-', $finisher['options']['template']);
 
-		// if there was no sg mail finisher or an missing key then simply exit the function
-		if ($extensionKey === '' || $templateKey === '') {
-			return;
-		}
+			// if no template key was explicitly set, use the form identifier as template key
+			if ($templateKey === '') {
+				$templateKey = $formDefinition['identifier'] . '-' . $finisher['identifier'];
+			}
 
-		// parse yaml for form fields
-		$absoluteFilePath = GeneralUtility::getFileAbsFileName($formPersistenceIdentifier);
-		$parsedYaml = Yaml::parse(file_get_contents($absoluteFilePath));
+			// if there was no sg mail finisher or an missing key then simply exit the function
+			if ($extensionKey === '' || $templateKey === '') {
+				return;
+			}
 
-		$renderables = [];
-		foreach ($parsedYaml['renderables'] as $formPage) {
-			if (\is_array($formPage['renderables'])) {
-				foreach ($formPage['renderables'] as $row) {
-					if (!\is_array($row) || !$row['type']) {
-						continue;
-					}
+			// parse yaml for form fields
+			$absoluteFilePath = GeneralUtility::getFileAbsFileName($formPersistenceIdentifier);
+			$parsedYaml = Yaml::parse(file_get_contents($absoluteFilePath));
 
-					if ($row['type'] === 'GridRow') {
-						foreach ($row['renderables'] as $renderableInsideGridrow) {
-							$renderables[] = $renderableInsideGridrow;
+			$renderables = [];
+			foreach ($parsedYaml['renderables'] as $formPage) {
+				if (\is_array($formPage['renderables'])) {
+					foreach ($formPage['renderables'] as $row) {
+						if (!\is_array($row) || !$row['type']) {
+							continue;
 						}
 
-					} elseif (!\in_array($row['type'], self::IGNORE_FIELDS, TRUE)) {
-						$renderables[] = $row;
+						if ($row['type'] === 'GridRow') {
+							foreach ($row['renderables'] as $renderableInsideGridrow) {
+								$renderables[] = $renderableInsideGridrow;
+							}
+
+						} elseif (!\in_array($row['type'], self::IGNORE_FIELDS, TRUE)) {
+							$renderables[] = $row;
+						}
 					}
+				} else {
+					return;
 				}
-			} else {
-				return;
 			}
+
+			// write the new Register.php file and add it to the registrationFiles array in the RegisterService
+			$this->writeRegisterFile($renderables, $extensionKey, $templateKey);
 		}
 
 		// call register function in register service class
-		$registrationService = $this->objectManager->get(RegisterService::class);
-
-		// write the new Register.php file and add it to the registrationFiles array in the RegisterService
-		$this->writeRegisterFile($renderables, $extensionKey, $templateKey);
 		$registrationService->getRegisterArray();
 
 		$this->clearCaches();
-- 
GitLab