From 4e649d716f62463009e5c8fd07b1ce8581d76902 Mon Sep 17 00:00:00 2001
From: Torsten Oppermann <torsten@sgalinski.de>
Date: Fri, 8 Mar 2019 12:36:14 +0100
Subject: [PATCH] [TASK] Editing of namespaces

---
 Classes/Controller/ConfigurationController.php     | 14 +++++++++-----
 Classes/Service/RegisterService.php                | 11 ++---------
 Resources/Private/Language/de.locallang.xlf        |  6 +++++-
 Resources/Private/Language/locallang.xlf           |  5 ++++-
 .../Private/Templates/Configuration/Index.html     |  5 +++++
 5 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/Classes/Controller/ConfigurationController.php b/Classes/Controller/ConfigurationController.php
index 4706262c..f16f33f7 100644
--- a/Classes/Controller/ConfigurationController.php
+++ b/Classes/Controller/ConfigurationController.php
@@ -48,7 +48,7 @@ use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
  * Controller for the configuration mode of the backend module
  */
 class ConfigurationController extends ActionController {
-	const DEFAULT_EXTENSION_KEY = 'sg_mail';
+	public const DEFAULT_EXTENSION_KEY = 'sg_mail';
 
 	/**
 	 * DocHeaderComponent
@@ -88,6 +88,7 @@ class ConfigurationController extends ActionController {
 			}
 		}
 
+		$this->view->assign('extensionKey', self::DEFAULT_EXTENSION_KEY);
 		$this->view->assign('mode', $mode);
 		if ($mode === 'edit') {
 			$templateToEdit = $registerArray[$selectedExtension][$selectedTemplate];
@@ -100,6 +101,7 @@ class ConfigurationController extends ActionController {
 
 			}
 			$this->view->assign('csv', $csv);
+			$this->view->assign('extensionKey', $selectedExtension);
 			$this->view->assign('description', $templateToEdit['description']);
 			$this->view->assign('editMode', 1);
 		}
@@ -142,6 +144,7 @@ class ConfigurationController extends ActionController {
 		$configuration = $this->request->getArgument('configuration');
 
 		$templateName = $configuration['templateName'];
+		$extensionKey = $configuration['extensionKey'];
 		$csv = str_replace("\r", '', $configuration['csv']);
 		$subject = $configuration['subject'];
 		$description = $configuration['description'];
@@ -163,7 +166,7 @@ class ConfigurationController extends ActionController {
 
 		$registerService = $this->objectManager->get(RegisterService::class);
 		$registerService->writeRegisterFile(
-			$templateName, self::DEFAULT_EXTENSION_KEY, $markers, $subject, $description
+			$templateName, $extensionKey, $markers, $subject, $description
 		);
 
 		$registerService->clearCaches();
@@ -189,8 +192,8 @@ class ConfigurationController extends ActionController {
 	 *
 	 * @throws StopActionException
 	 * @throws UnsupportedRequestTypeException
-	 * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
 	 * @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException
+	 * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
 	 */
 	public function editAction(): void {
 		if (!$this->request->hasArgument('configuration')) {
@@ -205,6 +208,7 @@ class ConfigurationController extends ActionController {
 
 		$templateName = $configuration['templateName'];
 		$extensionKey = $configuration['extensionKey'];
+		$oldTemplateName = $configuration['oldTemplateName'];
 		$csv = str_replace("\r", '', $configuration['csv']);
 		$subject = $configuration['subject'];
 		$description = $configuration['description'];
@@ -224,9 +228,9 @@ class ConfigurationController extends ActionController {
 			];
 		}
 		$registerService = $this->objectManager->get(RegisterService::class);
-		$registerService->deleteRegisterFile($templateName);
+		$registerService->deleteRegisterFile($oldTemplateName);
 		$registerService->writeRegisterFile(
-			$templateName, self::DEFAULT_EXTENSION_KEY, $markers, $subject, $description
+			$templateName, $extensionKey, $markers, $subject, $description
 		);
 
 		$registerService->clearCaches();
diff --git a/Classes/Service/RegisterService.php b/Classes/Service/RegisterService.php
index 99d22dd1..2425c6fb 100644
--- a/Classes/Service/RegisterService.php
+++ b/Classes/Service/RegisterService.php
@@ -160,13 +160,10 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
 	) {
 		// template_path means where to find the mail body content (usually it's set directly in the registration
 		// as template_content)
+		$templatePath = '';
 		if ($configArray['template_path']) {
 			$templatePath = $configArray['template_path'];
-		} else {
-			if (!ExtensionManagementUtility::isLoaded($extensionKey)) {
-				return;
-			}
-
+		} elseif (ExtensionManagementUtility::isLoaded($extensionKey)) {
 			// transform template directory name: your_templates => YourTemplates/
 			$templateDirectoryParts = GeneralUtility::trimExplode('_', $templateKey);
 			$templateDirectory = '';
@@ -179,10 +176,6 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
 				self::DEFAULT_TEMPLATE_PATH . $templateDirectory;
 		}
 
-		if (!\is_dir($templatePath)) {
-			$templatePath = '';
-		}
-
 		$description = $configArray['description'];
 		$subject = $configArray['subject'];
 		$marker = $configArray['markers'];
diff --git a/Resources/Private/Language/de.locallang.xlf b/Resources/Private/Language/de.locallang.xlf
index 35d5714a..1c313426 100644
--- a/Resources/Private/Language/de.locallang.xlf
+++ b/Resources/Private/Language/de.locallang.xlf
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
 <xliff version="1.0">
-	<file source-language="en" target-language="de" datatype="plaintext" original="messages" date="2019-03-08T04:55:34Z">
+	<file source-language="en" target-language="de" datatype="plaintext" original="messages" date="2019-03-08T07:38:45Z">
 		<header>
 			<type>module</type>
 			<description>Language labels for the backend module belonging to extension 'sg_csv_importer'</description>
@@ -65,6 +65,10 @@
 				<source><![CDATA[Description]]></source>
 				<target><![CDATA[Beschreibung]]></target>
 			</trans-unit>
+			<trans-unit id="backend.create.extensionKey" approved="yes">
+				<source><![CDATA[Namespace]]></source>
+				<target><![CDATA[Namespace]]></target>
+			</trans-unit>
 			<trans-unit id="backend.create.info" approved="yes">
 				<source><![CDATA[Please insert the template marker in the following format: markerName; exampleValue; description <br><br>Whitespaces in marker names are ignored. <br />If you have multiple markers, seperate them with a new line: markerName1; exampleValue1; description1<br />markerName2; exampleValue2; description2 <br /><br />Example: first_name; Max; The first name of the client <br />last_name; Mustermann; The last name of the client]]></source>
 				<target><![CDATA[Bitte geben Sie die Template Marker im folgenden Format ein: markerName; beispiel; beschreibung <br><br>Leerzeichen in Markernamen werden ignoriert. <br /><br />Mehrere Marker werden mit der Eingabetaste getrennt: markerName1; beispiel1; beschreibung1<br />markerName2; beispiel2; beschreibung2 <br /><br />Beispiel: first_name; Max; Der Vorname des Kunden<br /> last_name; Mustermann; Der Nachname des Kunden]]></target>
diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf
index cebc15e0..0c6e8fd5 100644
--- a/Resources/Private/Language/locallang.xlf
+++ b/Resources/Private/Language/locallang.xlf
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
 <xliff version="1.0">
-	<file source-language="en" datatype="plaintext" original="messages" date="2019-03-08T04:55:34Z">
+	<file source-language="en" datatype="plaintext" original="messages" date="2019-03-08T07:38:45Z">
 		<header>
 			<type>module</type>
 			<description>Language labels for the backend module belonging to extension 'sg_csv_importer'</description>
@@ -54,6 +54,9 @@
 			<trans-unit id="backend.create.description">
 				<source><![CDATA[Description]]></source>
 			</trans-unit>
+			<trans-unit id="backend.create.extensionKey">
+				<source><![CDATA[Namespace]]></source>
+			</trans-unit>
 			<trans-unit id="backend.create.info">
 				<source><![CDATA[Please insert the template marker in the following format: markerName; exampleValue; description <br><br>Whitespaces in marker names are ignored. <br />If you have multiple markers, seperate them with a new line: markerName1; exampleValue1; description1<br />markerName2; exampleValue2; description2 <br /><br />Example: first_name; Max; The first name of the client <br />last_name; Mustermann; The last name of the client]]></source>
 			</trans-unit>
diff --git a/Resources/Private/Templates/Configuration/Index.html b/Resources/Private/Templates/Configuration/Index.html
index 3493a391..27cd6c96 100644
--- a/Resources/Private/Templates/Configuration/Index.html
+++ b/Resources/Private/Templates/Configuration/Index.html
@@ -27,6 +27,11 @@
 		<div class="row">
 			<div class="col-xs-12 col-md-10 col-md-offset-1">
 				<f:form.hidden name="extensionKey" value="{selectedExtensionKey}"/>
+				<f:form.hidden name="oldTemplateName" property="oldTemplateName" value="{templateName}"/>
+				<div class="form-group">
+					<label for="extensionKey"><f:translate key="backend.create.extensionKey" /></label>
+					<f:form.textfield class="form-control" property="extensionKey" id="extensionKey" required="TRUE" value="{extensionKey}" />
+				</div>
 				<div class="form-group">
 					<label for="templateName"><f:translate key="backend.create.templateName" /></label>
 					<f:form.textfield class="form-control" property="templateName" id="templateName" required="TRUE" value="{templateName}" />
-- 
GitLab