[TASK] Fluidification of NewContentElementController 08/49808/7
authorMarc Willmann <mw@f7.de>
Sun, 4 Sep 2016 12:36:14 +0000 (14:36 +0200)
committerJan Helke <typo3@helke.de>
Fri, 7 Oct 2016 08:10:08 +0000 (10:10 +0200)
Additionally an unused variable was removed and some
variables have been renamed to a more speaking name.

Resolves: #77801
Releases: master
Change-Id: I242a9f32c80c8702097a2b20ed577db44766902b
Reviewed-on: https://review.typo3.org/49808
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Alexander Stehlik <alexander.stehlik@gmail.com>
Reviewed-by: Philipp Gampe <philipp.gampe@typo3.org>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Markus Sommer <markussom@posteo.de>
Tested-by: Markus Sommer <markussom@posteo.de>
Reviewed-by: Michael Oehlhof <typo3@oehlhof.de>
Tested-by: Michael Oehlhof <typo3@oehlhof.de>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
typo3/sysext/backend/Classes/Controller/ContentElement/NewContentElementController.php
typo3/sysext/backend/Resources/Private/Templates/NewContentElement/Main.html [new file with mode: 0644]
typo3/sysext/backend/Resources/Private/Templates/NewContentElement/MenuItem.html [new file with mode: 0644]

index 5168c14..4f7c159 100644 (file)
@@ -22,10 +22,10 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Backend\View\BackendLayoutView;
 use TYPO3\CMS\Backend\Wizard\NewContentElementWizardHookInterface;
 use TYPO3\CMS\Core\Imaging\Icon;
-use TYPO3\CMS\Core\Imaging\IconRegistry;
 use TYPO3\CMS\Core\Service\DependencyOrderingService;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Fluid\View\StandaloneView;
 
 /**
  * Script Class for the New Content element wizard
@@ -106,11 +106,6 @@ class NewContentElementController extends AbstractModule
     protected $pageInfo;
 
     /**
-     * @var array
-     */
-    protected $elementWrapper;
-
-    /**
      * @var string
      */
     protected $onClickEvent;
@@ -121,12 +116,24 @@ class NewContentElementController extends AbstractModule
     protected $MCONF;
 
     /**
+     * @var StandaloneView
+     */
+    protected $view;
+
+    /**
+     * @var StandaloneView
+     */
+    protected $menuItemView;
+
+    /**
      * Constructor
      */
     public function __construct()
     {
         parent::__construct();
         $GLOBALS['SOBE'] = $this;
+        $this->view = $this->getFluidTemplateObject();
+        $this->menuItemView = $this->getFluidTemplateObject('MenuItem.html');
         $this->init();
     }
 
@@ -189,9 +196,9 @@ class NewContentElementController extends AbstractModule
      */
     public function main()
     {
-        $lang = $this->getLanguageService();
-        $this->content .= '<form action="" name="editForm" id="NewContentElementController"><input type="hidden" name="defValues" value="" />';
+        $hasAccess = true;
         if ($this->id && $this->access) {
+
             // Init position map object:
             $posMap = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\View\ContentCreationPagePositionMap::class);
             $posMap->cur_sys_language = $this->sys_language;
@@ -216,11 +223,9 @@ class NewContentElementController extends AbstractModule
             // ***************************
             // Creating content
             // ***************************
-            $this->content .= '<h1>' . $lang->getLL('newContentElement') . '</h1>';
             // Wizard
             $wizardItems = $this->wizardArray();
             // Wrapper for wizards
-            $this->elementWrapper['section'] = ['', ''];
             // Hook for manipulating wizardItems, wrapper, onClickEvent etc.
             if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms']['db_new_content_el']['wizardItemsHook'])) {
                 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms']['db_new_content_el']['wizardItemsHook'] as $classData) {
@@ -243,69 +248,54 @@ class NewContentElementController extends AbstractModule
                                }'
             );
 
-            $iconRegistry = GeneralUtility::makeInstance(IconRegistry::class);
-
             // Traverse items for the wizard.
             // An item is either a header or an item rendered with a radio button and title/description and icon:
             $cc = ($key = 0);
             $menuItems = [];
-            foreach ($wizardItems as $k => $wInfo) {
+
+            $this->view->assign('onClickEvent', $this->onClickEvent);
+
+            foreach ($wizardItems as $wizardKey => $wInfo) {
+                $wizardOnClick = '';
                 if ($wInfo['header']) {
                     $menuItems[] = [
                         'label' => htmlspecialchars($wInfo['header']),
-                        'content' => $this->elementWrapper['section'][0]
+                        'content' => ''
                     ];
                     $key = count($menuItems) - 1;
                 } else {
-                    $content = '';
-
                     if (!$this->onClickEvent) {
                         // Radio button:
-                        $oC = 'document.editForm.defValues.value=unescape(' . GeneralUtility::quoteJSvalue(rawurlencode($wInfo['params'])) . ');goToalt_doc();' . (!$this->onClickEvent ? 'window.location.hash=\'#sel2\';' : '');
-                        $content .= '<div class="media-left"><input type="radio" name="tempB" value="' . htmlspecialchars($k) . '" onclick="' . htmlspecialchars($oC) . '" /></div>';
+                        $wizardOnClick = 'document.editForm.defValues.value=unescape(' . GeneralUtility::quoteJSvalue(rawurlencode($wInfo['params'])) . ');goToalt_doc();' . (!$this->onClickEvent ? 'window.location.hash=\'#sel2\';' : '');
                         // Onclick action for icon/title:
-                        $aOnClick = 'document.getElementsByName(\'tempB\')[' . $cc . '].checked=1;' . $oC . 'return false;';
+                        $aOnClick = 'document.getElementsByName(\'tempB\')[' . $cc . '].checked=1;' . $wizardOnClick . 'return false;';
                     } else {
                         $aOnClick = "document.editForm.defValues.value=unescape('" . rawurlencode($wInfo['params']) . "');goToalt_doc();" . (!$this->onClickEvent?"window.location.hash='#sel2';":'');
                     }
 
                     $icon = $this->moduleTemplate->getIconFactory()->getIcon($wInfo['iconIdentifier'])->render();
-                    $menuItems[$key]['content'] .= '
-                                               <div class="media">
-                                                       <a href="#" onclick="' . htmlspecialchars($aOnClick) . '">
-                                                               ' . $content . '
-                                                               <div class="media-left">
-                                                                       ' . $icon . '
-                                                               </div>
-                                                               <div class="media-body">
-                                                                       <strong>' . htmlspecialchars($wInfo['title']) . '</strong>' .
-                                    '<br />' .
-                                    nl2br(htmlspecialchars(trim($wInfo['description']))) .
-                                '</div>
-                                                       </a>
-                                               </div>';
+
+                    $this->menuItemView->assignMultiple([
+                            'onClickEvent' => $this->onClickEvent,
+                            'aOnClick' => $aOnClick,
+                            'wizardInformation' => $wInfo,
+                            'icon' => $icon,
+                            'wizardOnClick' => $wizardOnClick,
+                            'wizardKey' => $wizardKey
+                        ]
+                    );
+                    $menuItems[$key]['content'] .= $this->menuItemView->render();
                     $cc++;
                 }
             }
-            // Add closing section-tag
-            foreach ($menuItems as $key => $val) {
-                $menuItems[$key]['content'] .= $this->elementWrapper['section'][1];
-            }
-            // Add the wizard table to the content, wrapped in tabs
-            $code = '<p>' . htmlspecialchars($lang->getLL('sel1')) . '</p>' . $this->moduleTemplate->getDynamicTabMenu(
+
+            $this->view->assign('renderedTabs', $this->moduleTemplate->getDynamicTabMenu(
                 $menuItems,
                 'new-content-element-wizard'
-            );
-
-            $this->content .= !$this->onClickEvent ? '<h2>' . htmlspecialchars($lang->getLL('1_selectType')) . '</h2>' : '';
-            $this->content .= '<div>' . $code . '</div>';
+            ));
 
             // If the user must also select a column:
             if (!$this->onClickEvent) {
-                // Add anchor "sel2"
-                $this->content .= '<div><a name="sel2"></a></div>';
-                // Select position
-                $code = '<p>' . htmlspecialchars($lang->getLL('sel2')) . '</p>';
 
                 // Load SHARED page-TSconfig settings and retrieve column list from there, if applicable:
                 $colPosArray = GeneralUtility::callUserFunction(
@@ -317,15 +307,15 @@ class NewContentElementController extends AbstractModule
                 // Removing duplicates, if any
                 $colPosList = implode(',', array_unique(array_map('intval', $colPosIds)));
                 // Finally, add the content of the column selector to the content:
-                $code .= $posMap->printContentElementColumns($this->id, 0, $colPosList, 1, $this->R_URI);
-                $this->content .= '<h2>' . htmlspecialchars($lang->getLL('2_selectPosition')) . '</h2><div>' . $code . '</div>';
+                $this->view->assign('posMap', $posMap->printContentElementColumns($this->id, 0, $colPosList, 1, $this->R_URI));
             }
         } else {
             // In case of no access:
-            $this->content = '';
-            $this->content .= '<h1>' . $lang->getLL('newContentElement') . '</h1>';
+            $hasAccess = false;
         }
-        $this->content .= '</form>';
+        $this->view->assign('hasAccess', $hasAccess);
+
+        $this->content = $this->view->render();
         // Setting up the buttons and markers for docheader
         $this->getButtons();
     }
@@ -579,4 +569,19 @@ class NewContentElementController extends AbstractModule
     {
         return $GLOBALS['BE_USER'];
     }
+
+    /**
+     * returns a new standalone view, shorthand function
+     *
+     * @param string $filename
+     * @return StandaloneView
+     */
+    protected function getFluidTemplateObject(string $filename = 'Main.html'):StandaloneView
+    {
+        /** @var StandaloneView $view */
+        $view = GeneralUtility::makeInstance(StandaloneView::class);
+        $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/NewContentElement/' . $filename));
+        $view->getRequest()->setControllerExtensionName('Backend');
+        return $view;
+    }
 }
diff --git a/typo3/sysext/backend/Resources/Private/Templates/NewContentElement/Main.html b/typo3/sysext/backend/Resources/Private/Templates/NewContentElement/Main.html
new file mode 100644 (file)
index 0000000..9090db7
--- /dev/null
@@ -0,0 +1,30 @@
+<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
+<f:if condition="{hasAccess}">
+       <f:then>
+               <f:form action="" name="editForm" id="NewContentElementController">
+                       <f:form.hidden name="defValues" value=""/>
+                       <h1>{f:translate(key: 'LLL:EXT:lang/locallang_misc.xlf:newContentElement')}</h1>
+                       <f:if condition="{onClickEvent} == ''">
+                               <h2>{f:translate(key: 'LLL:EXT:lang/locallang_misc.xlf:1_selectType')}</h2>
+                       </f:if>
+                       <div>
+                               <p>{f:translate(key: 'LLL:EXT:backend/Resources/Private/Language/locallang_db_new_content_el.xlf:sel1')}</p>
+                               {renderedTabs -> f:format.raw()}
+                       </div>
+
+                       <f:if condition="{onClickEvent} == ''">
+                               <div><a name="sel2"></a></div>
+                               <h2>{f:translate(key: 'LLL:EXT:lang/locallang_misc.xlf:2_selectPosition') -> f:format.htmlspecialchars()}</h2>
+                               <div>
+                                       <p>{f:translate(key: 'LLL:EXT:backend/Resources/Private/Language/locallang_db_new_content_el.xlf:sel2') ->
+                                               f:format.htmlspecialchars()}</p>
+                                       {posMap -> f:format.raw()}
+                               </div>
+                       </f:if>
+               </f:form>
+       </f:then>
+       <f:else>
+               <h1>{f:translate(key: 'LLL:EXT:lang/locallang_misc.xlf:newContentElement')}</h1>
+       </f:else>
+</f:if>
+</html>
diff --git a/typo3/sysext/backend/Resources/Private/Templates/NewContentElement/MenuItem.html b/typo3/sysext/backend/Resources/Private/Templates/NewContentElement/MenuItem.html
new file mode 100644 (file)
index 0000000..71bbaa8
--- /dev/null
@@ -0,0 +1,20 @@
+<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
+<div class="media">
+       <a href="#" onclick="{aOnClick -> f:format.htmlspecialchars()}">
+               <f:if condition="{onClickEvent} == ''">
+                       <div class="media-left">
+                               <input type="radio" name="tempB" value="{wizardKey -> f:format.htmlspecialchars()}" onclick="{wizardOnClick -> f:format.htmlspecialchars()}"/>
+                       </div>
+               </f:if>
+               {content -> f:format.raw()}
+               <div class="media-left">
+                       {icon -> f:format.raw()}
+               </div>
+               <div class="media-body">
+                       <strong>{wizardInformation.title -> f:format.htmlspecialchars()}</strong>
+                       <br />
+                       {wizardInformation.description -> f:format.nl2br() -> f:format.htmlspecialchars()}
+               </div>
+       </a>
+</div>
+</html>