[TASK] Fluidification of Info PageTSConfig 86/46986/2
authorMichael Oehlhof <typo3@oehlhof.de>
Tue, 1 Mar 2016 20:25:24 +0000 (21:25 +0100)
committerJan Helke <typo3@helke.de>
Thu, 3 Mar 2016 17:24:20 +0000 (18:24 +0100)
Moved all HTML code from the PHP code to an own Fluid template.

Resolves: #73723
Releases: master
Change-Id: I5b67d14d1c525db9cb38769c3860dc2c3e9bb730
Reviewed-on: https://review.typo3.org/46986
Reviewed-by: Daniel Maier <dani-maier@gmx.de>
Tested-by: Daniel Maier <dani-maier@gmx.de>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
typo3/sysext/info_pagetsconfig/Classes/Controller/InfoPageTyposcriptConfigController.php
typo3/sysext/info_pagetsconfig/Resources/Private/Partials/EditIcon.html [new file with mode: 0644]
typo3/sysext/info_pagetsconfig/Resources/Private/Partials/Menu.html [new file with mode: 0644]
typo3/sysext/info_pagetsconfig/Resources/Private/Partials/Page.html [new file with mode: 0644]
typo3/sysext/info_pagetsconfig/Resources/Private/Partials/PageZero.html [new file with mode: 0644]
typo3/sysext/info_pagetsconfig/Resources/Private/Partials/PageZeroTableRow.html [new file with mode: 0644]
typo3/sysext/info_pagetsconfig/Resources/Private/Templates/Main.html [new file with mode: 0644]

index ae42487..b577d45 100644 (file)
@@ -19,6 +19,7 @@ use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Fluid\View\StandaloneView;
 
 /**
  * Page TSconfig viewer
@@ -31,12 +32,19 @@ class InfoPageTyposcriptConfigController extends \TYPO3\CMS\Backend\Module\Abstr
     protected $iconFactory;
 
     /**
+     * @var StandaloneView
+     */
+    protected $view;
+
+    /**
      * Constructor
      */
     public function __construct()
     {
         $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
         $this->getLanguageService()->includeLLFile('EXT:info_pagetsconfig/Resources/Private/Language/locallang.xlf');
+
+        $this->view = $this->getFluidTemplateObject();
     }
 
     /**
@@ -80,40 +88,27 @@ class InfoPageTyposcriptConfigController extends \TYPO3\CMS\Backend\Module\Abstr
      */
     public function main()
     {
-        if ((int)(GeneralUtility::_GP('id')) === 0) {
-            $lang = $this->getLanguageService();
-            return '<div class="nowrap"><div class="table-fit"><table class="table table-striped table-hover" id="tsconfig-overview">' .
-                '<thead>' .
-                '<tr>' .
-                '<th>' . $lang->getLL('pagetitle') . '</th>' .
-                '<th>' . $lang->getLL('included_tsconfig_files') . '</th>' .
-                '<th>' . $lang->getLL('written_tsconfig_lines') . '</th>' .
-                '</tr>' .
-                '</thead>' .
-                '<tbody>' . implode('', $this->getOverviewOfPagesUsingTSConfig()) . '</tbody>' .
-                '</table></div>';
-        } else {
-            $menu = '<div class="form-inline form-inline-spaced">';
-            $menu .= BackendUtility::getDropdownMenu($this->pObj->id, 'SET[tsconf_parts]', $this->pObj->MOD_SETTINGS['tsconf_parts'], $this->pObj->MOD_MENU['tsconf_parts']);
-            $menu .= '<div class="checkbox"><label for="checkTsconf_alphaSort">' . BackendUtility::getFuncCheck($this->pObj->id, 'SET[tsconf_alphaSort]', $this->pObj->MOD_SETTINGS['tsconf_alphaSort'], '', '', 'id="checkTsconf_alphaSort"') . ' ' . $this->getLanguageService()->getLL('sort_alphabetic', true) . '</label></div>';
-            $menu .= '</div>';
-            $theOutput = '<h1>' . htmlspecialchars($this->getLanguageService()->getLL('tsconf_title')) . '</h1>';
+        $pageId = (int)(GeneralUtility::_GP('id'));
 
+        if ($pageId === 0) {
+            $this->view->assign('pageZero', 1);
+            $this->view->assign('overviewOfPagesUsingTSConfig', $this->getOverviewOfPagesUsingTSConfig());
+        } else {
             if ($this->pObj->MOD_SETTINGS['tsconf_parts'] == 99) {
                 $TSparts = BackendUtility::getPagesTSconfig($this->pObj->id, null, true);
                 $lines = array();
                 $pUids = array();
+
                 foreach ($TSparts as $k => $v) {
                     if ($k != 'uid_0') {
+                        $line = array();
                         if ($k == 'defaultPageTSconfig') {
-                            $pTitle = '<strong>' . $this->getLanguageService()->getLL('editTSconfig_default', true) . '</strong>';
-                            $editIcon = '';
+                            $line['defaultPageTSconfig'] = 1;
                         } else {
                             $pUids[] = substr($k, 4);
                             $row = BackendUtility::getRecordWSOL('pages', substr($k, 4));
 
                             $icon = $this->iconFactory->getIconForRecord('pages', $row, Icon::SIZE_SMALL);
-                            $pTitle = BackendUtility::wrapClickMenuOnIcon($icon, 'pages', $row['uid']) . ' ' . htmlspecialchars(BackendUtility::getRecordTitle('pages', $row));
                             $editIdList = substr($k, 4);
                             $urlParameters = [
                                 'edit' => [
@@ -124,20 +119,18 @@ class InfoPageTyposcriptConfigController extends \TYPO3\CMS\Backend\Module\Abstr
                                 'columnsOnly' => 'TSconfig',
                                 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
                             ];
-                            $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
-                            $editIcon = '<a href="' . htmlspecialchars($url) . '" title="' . $this->getLanguageService()->getLL('editTSconfig', true) . '">' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
+                            $line['editIcon'] = BackendUtility::getModuleUrl('record_edit', $urlParameters);
+                            $line['editTitle'] = 'editTSconfig';
+                            $line['title'] = BackendUtility::wrapClickMenuOnIcon($icon, 'pages', $row['uid'])
+                                . ' ' . htmlspecialchars(BackendUtility::getRecordTitle('pages', $row));
                         }
-                        $TScontent = nl2br(htmlspecialchars(trim($v) . LF));
                         $tsparser = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::class);
                         $tsparser->lineNumberOffset = 0;
-                        $TScontent = $tsparser->doSyntaxHighlight(trim($v) . LF);
-                        $lines[] = '
-                                                       <tr><td nowrap="nowrap" class="bgColor5">' . $pTitle . '</td></tr>
-                                                       <tr><td nowrap="nowrap" class="bgColor4">' . $TScontent . $editIcon . '</td></tr>
-                                                       <tr><td>&nbsp;</td></tr>
-                                               ';
+                        $line['content'] = $tsparser->doSyntaxHighlight(trim($v) . LF);
+                        $lines[] = $line;
                     }
                 }
+
                 if (!empty($pUids)) {
                     $urlParameters = [
                         'edit' => [
@@ -149,16 +142,21 @@ class InfoPageTyposcriptConfigController extends \TYPO3\CMS\Backend\Module\Abstr
                         'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
                     ];
                     $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
-                    $editIcon = '<a href="' . htmlspecialchars($url) . '" title="' . $this->getLanguageService()->getLL('editTSconfig_all', true) . '">' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '<strong>' . $this->getLanguageService()->getLL('editTSconfig_all', true) . '</strong>' . '</a>';
+                    $editIcon = htmlspecialchars($url);
+                    $editTitle = 'editTSconfig_all';
+
                 } else {
                     $editIcon = '';
+                    $editTitle = '';
                 }
-                $theOutput .= '<div>';
-                $theOutput .= BackendUtility::cshItem('_MOD_web_info', 'tsconfig_edit', null, '<span class="btn btn-default btn-sm">|</span>') . $menu . '
-                                               <!-- Edit fields: -->
-                                               <table border="0" cellpadding="0" cellspacing="1">' . implode('', $lines) . '</table><br />' . $editIcon;
-                $theOutput .= '</div>';
+
+                $this->view->assign('tsconfParts99', 1);
+                $this->view->assign('csh', BackendUtility::cshItem('_MOD_web_info', 'tsconfig_edit', null, '|'));
+                $this->view->assign('lines', $lines);
+                $this->view->assign('editIcon', $editIcon);
+                $this->view->assign('editTitle', $editTitle);
             } else {
+                $this->view->assign('tsconfParts99', 0);
                 // Defined global here!
                 $tmpl = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService::class);
 
@@ -220,16 +218,13 @@ class InfoPageTyposcriptConfigController extends \TYPO3\CMS\Backend\Module\Abstr
                     $modTSconfig = array();
                 }
 
-                $csh = BackendUtility::cshItem('_MOD_web_info', 'tsconfig_hierarchy', null, '<span class="btn btn-default btn-sm">|</span>');
-                $tree = $tmpl->ext_getObjTree($modTSconfig, '', '', '', '', $this->pObj->MOD_SETTINGS['tsconf_alphaSort']);
-
-                $theOutput .= '<div>';
-                $theOutput .= $csh . $menu . '<div class="nowrap">' . $tree . '</div>';
-                $theOutput .= '</div>';
+                $this->view->assign('csh', BackendUtility::cshItem('_MOD_web_info', 'tsconfig_hierarchy', null, '|'));
+                $this->view->assign('tree', $tmpl->ext_getObjTree($modTSconfig, '', '', '', '', $this->pObj->MOD_SETTINGS['tsconf_alphaSort']));
             }
+            $this->view->assign('alphaSort', BackendUtility::getFuncCheck($this->pObj->id, 'SET[tsconf_alphaSort]', $this->pObj->MOD_SETTINGS['tsconf_alphaSort'], '', '', 'id="checkTsconf_alphaSort"'));
+            $this->view->assign('dropdownMenu', BackendUtility::getDropdownMenu($this->pObj->id, 'SET[tsconf_parts]', $this->pObj->MOD_SETTINGS['tsconf_parts'], $this->pObj->MOD_MENU['tsconf_parts']));
         }
-
-        return $theOutput;
+        return $this->view->render();
     }
 
     /**
@@ -250,7 +245,7 @@ class InfoPageTyposcriptConfigController extends \TYPO3\CMS\Backend\Module\Abstr
         while ($row = $db->sql_fetch_assoc($res)) {
             $this->setInPageArray($pageArray, BackendUtility::BEgetRootLine($row['uid'], 'AND 1=1'), $row);
         }
-        return $this->renderList($pageArray);
+        return $this->getList($pageArray);
     }
 
     /**
@@ -306,7 +301,7 @@ class InfoPageTyposcriptConfigController extends \TYPO3\CMS\Backend\Module\Abstr
     }
 
     /**
-     * Render the list of pages to show.
+     * Get the list of pages to show.
      * This function is called recursively
      *
      * @param array $pageArray The Page Array
@@ -314,9 +309,8 @@ class InfoPageTyposcriptConfigController extends \TYPO3\CMS\Backend\Module\Abstr
      * @param int $pageDepth The level of the current $pageArray being processed
      * @return array
      */
-    protected function renderList($pageArray, $lines = array(), $pageDepth = 0)
+    protected function getList($pageArray, $lines = array(), $pageDepth = 0)
     {
-        $cellStyle = 'padding-left: ' . ($pageDepth * 20) . 'px';
         if (!is_array($pageArray)) {
             return $lines;
         }
@@ -325,28 +319,25 @@ class InfoPageTyposcriptConfigController extends \TYPO3\CMS\Backend\Module\Abstr
             if (!MathUtility::canBeInterpretedAsInteger($identifier)) {
                 continue;
             }
+            $line = array();
+            $line['padding'] = ($pageDepth * 20);
             if (isset($pageArray[$identifier . '_'])) {
-                $lines[] = '
-                               <tr>
-                                       <td nowrap style="' . $cellStyle . '">
-                                               <a href="'
-                    . htmlspecialchars(GeneralUtility::linkThisScript(array('id' => $identifier)))
-                    . '" title="' . htmlspecialchars('ID: ' . $identifier) . '">'
-                    . $this->iconFactory->getIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $identifier), Icon::SIZE_SMALL)->render()
-                    . GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30) . '</a></td>
-                                       <td>' . ($pageArray[$identifier . '_']['includeLines'] === 0 ? '' : $pageArray[($identifier . '_')]['includeLines']) . '</td>
-                                       <td>' . ($pageArray[$identifier . '_']['writtenLines'] === 0 ? '' : $pageArray[$identifier . '_']['writtenLines']) . '</td>
-                                       </tr>';
+                $line['link'] = htmlspecialchars(GeneralUtility::linkThisScript(array('id' => $identifier)));
+                $line['icon'] = $this->iconFactory->getIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $identifier), Icon::SIZE_SMALL)->render();
+                $line['title'] = htmlspecialchars('ID: ' . $identifier);
+                $line['pageTitle'] = GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30);
+                $line['includedFiles'] = ($pageArray[$identifier . '_']['includeLines'] === 0 ? '' : $pageArray[($identifier . '_')]['includeLines']);
+                $line['lines'] = ($pageArray[$identifier . '_']['writtenLines'] === 0 ? '' : $pageArray[$identifier . '_']['writtenLines']);
             } else {
-                $lines[] = '<tr>
-                                       <td nowrap style="' . $cellStyle . '">'
-                    . $this->iconFactory->getIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $identifier), Icon::SIZE_SMALL)->render()
-                    . GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30) . '</td>
-                                       <td></td>
-                                       <td></td>
-                                       </tr>';
+                $line['link'] = '';
+                $line['icon'] = $this->iconFactory->getIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $identifier), Icon::SIZE_SMALL)->render();
+                $line['title'] = '';
+                $line['pageTitle'] = GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30);
+                $line['includedFiles'] = '';
+                $line['lines'] = '';
             }
-            $lines = $this->renderList($pageArray[$identifier . '.'], $lines, $pageDepth + 1);
+            $lines[] = $line;
+            $lines = $this->getList($pageArray[$identifier . '.'], $lines, $pageDepth + 1);
         }
         return $lines;
     }
@@ -370,4 +361,23 @@ class InfoPageTyposcriptConfigController extends \TYPO3\CMS\Backend\Module\Abstr
     {
         return $GLOBALS['BE_USER'];
     }
+
+    /**
+     * returns a new standalone view, shorthand function
+     *
+     * @return StandaloneView
+     */
+    protected function getFluidTemplateObject()
+    {
+        /** @var StandaloneView $view */
+        $view = GeneralUtility::makeInstance(StandaloneView::class);
+        $view->setLayoutRootPaths(array(GeneralUtility::getFileAbsFileName('EXT:info_pagetsconfig/Resources/Private/Layouts')));
+        $view->setPartialRootPaths(array(GeneralUtility::getFileAbsFileName('EXT:info_pagetsconfig/Resources/Private/Partials')));
+        $view->setTemplateRootPaths(array(GeneralUtility::getFileAbsFileName('EXT:info_pagetsconfig/Resources/Private/Templates')));
+
+        $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:info_pagetsconfig/Resources/Private/Templates/Main.html'));
+
+        $view->getRequest()->setControllerExtensionName('info_pagetsconfig');
+        return $view;
+    }
 }
diff --git a/typo3/sysext/info_pagetsconfig/Resources/Private/Partials/EditIcon.html b/typo3/sysext/info_pagetsconfig/Resources/Private/Partials/EditIcon.html
new file mode 100644 (file)
index 0000000..9bf5c52
--- /dev/null
@@ -0,0 +1,12 @@
+<f:if condition="{editIcon}">
+    <a href="<f:format.raw>{editIcon}</f:format.raw>" title="{f:translate(key: 'LLL:EXT:info_pagetsconfig/Resources/Private/Language/locallang.xlf:{editTitle}')}">
+        <span class="t3js-icon icon icon-size-small icon-state-default icon-actions-document-open" data-identifier="actions-document-open">
+            <span class="icon-markup">
+                <img width="16" height="16" src="/typo3/sysext/core/Resources/Public/Icons/T3Icons/actions/actions-document-open.svg">
+            </span>
+        </span>
+        <f:if condition="{editAll}">
+            <strong>{f:translate(key: 'LLL:EXT:info_pagetsconfig/Resources/Private/Language/locallang.xlf:editTSconfig_all')}</strong>
+        </f:if>
+    </a>
+</f:if>
diff --git a/typo3/sysext/info_pagetsconfig/Resources/Private/Partials/Menu.html b/typo3/sysext/info_pagetsconfig/Resources/Private/Partials/Menu.html
new file mode 100644 (file)
index 0000000..88cbb08
--- /dev/null
@@ -0,0 +1,7 @@
+<div class="form-inline form-inline-spaced">
+    <f:format.raw>{dropdownMenu}</f:format.raw>
+    <div class="checkbox">
+        <label for="checkTsconf_alphaSort"><f:format.raw>{alphaSort}</f:format.raw></label>
+        {f:translate(key: 'LLL:EXT:info_pagetsconfig/Resources/Private/Language/locallang.xlf:sort_alphabetic')}
+    </div>
+</div>
diff --git a/typo3/sysext/info_pagetsconfig/Resources/Private/Partials/Page.html b/typo3/sysext/info_pagetsconfig/Resources/Private/Partials/Page.html
new file mode 100644 (file)
index 0000000..cf7c156
--- /dev/null
@@ -0,0 +1,30 @@
+<h1>{f:translate(key: 'LLL:EXT:info_pagetsconfig/Resources/Private/Language/locallang.xlf:tsconf_title')}</h1>
+<span class="btn btn-default btn-sm"><f:format.raw>{csh}</f:format.raw></span>
+<f:render partial="Menu" arguments="{_all}" />
+<f:if condition="{tsconfParts99}">
+    <f:then>
+        <div>
+            <table border="0" cellpadding="0" cellspacing="1">
+                <f:for each="{lines}" as="line">
+                    <tr><td nowrap="nowrap" class="bgColor5">
+                        <f:if condition="{line.defaultPageTSconfig}">
+                            <f:then>
+                                <strong>{f:translate(key: 'LLL:EXT:info_pagetsconfig/Resources/Private/Language/locallang.xlf:editTSconfig_default')}</strong>
+                            </f:then>
+                            <f:else>
+                                <f:format.raw>{line.title}</f:format.raw>
+                            </f:else>
+                        </f:if></td></tr>
+                    <tr><td nowrap="nowrap" class="bgColor4"><f:format.raw>{line.content}</f:format.raw><f:render partial="EditIcon" arguments="{editIcon: line.editIcon, editTitle: line.editTitle}" /></td></tr>
+                    <tr><td>&nbsp;</td></tr>
+                </f:for>
+            </table><br />
+            <f:render partial="EditIcon" arguments="{editIcon: editIcon, editTitle: editTitle, editAll: 1}" />
+        </div>
+    </f:then>
+    <f:else>
+        <div class="nowrap">
+            <f:format.raw>{tree}</f:format.raw>
+        </div>
+    </f:else>
+</f:if>
diff --git a/typo3/sysext/info_pagetsconfig/Resources/Private/Partials/PageZero.html b/typo3/sysext/info_pagetsconfig/Resources/Private/Partials/PageZero.html
new file mode 100644 (file)
index 0000000..5ce6e45
--- /dev/null
@@ -0,0 +1,18 @@
+<div class="nowrap">
+    <div class="table-fit">
+        <table class="table table-striped table-hover" id="tsconfig-overview">
+            <thead>
+                <tr>
+                    <th>{f:translate(key: 'LLL:EXT:info_pagetsconfig/Resources/Private/Language/locallang.xlf:pagetitle')}</th>
+                    <th>{f:translate(key: 'LLL:EXT:info_pagetsconfig/Resources/Private/Language/locallang.xlf:included_tsconfig_files')}</th>
+                    <th>{f:translate(key: 'LLL:EXT:info_pagetsconfig/Resources/Private/Language/locallang.xlf:written_tsconfig_lines')}</th>
+                </tr>
+            </thead>
+            <tbody>
+                <f:for each="{overviewOfPagesUsingTSConfig}" as="line">
+                    <f:render partial="PageZeroTableRow" arguments="{line: line}" />
+                </f:for>
+            </tbody>
+        </table>
+    </div>
+</div>
\ No newline at end of file
diff --git a/typo3/sysext/info_pagetsconfig/Resources/Private/Partials/PageZeroTableRow.html b/typo3/sysext/info_pagetsconfig/Resources/Private/Partials/PageZeroTableRow.html
new file mode 100644 (file)
index 0000000..5a4ea9d
--- /dev/null
@@ -0,0 +1,18 @@
+<tr>
+    <td nowrap style="padding-left: {line.padding}px">
+        <f:if condition="{line.link}">
+            <f:then>
+                <a href="{line.link}" title="{line.title}">
+                    <f:format.raw>{line.icon}</f:format.raw>
+                    <f:format.raw>{line.pageTitle}</f:format.raw>
+                </a>
+            </f:then>
+            <f:else>
+                <f:format.raw>{line.icon}</f:format.raw>
+                <f:format.raw>{line.pageTitle}</f:format.raw>
+            </f:else>
+        </f:if>
+    </td>
+    <td>{line.includedFiles}</td>
+    <td>{line.lines}</td>
+</tr>
diff --git a/typo3/sysext/info_pagetsconfig/Resources/Private/Templates/Main.html b/typo3/sysext/info_pagetsconfig/Resources/Private/Templates/Main.html
new file mode 100644 (file)
index 0000000..ad585b8
--- /dev/null
@@ -0,0 +1,8 @@
+<f:if condition="{pageZero}">
+    <f:then>
+        <f:render partial="PageZero" arguments="{_all}" />
+    </f:then>
+    <f:else>
+        <f:render partial="Page" arguments="{_all}" />
+    </f:else>
+</f:if>