[TASK] Improve TS Template module information on root level list 56/57856/6
authorJoerg Kummer <typo3@enobe.de>
Sat, 4 Aug 2018 13:52:09 +0000 (15:52 +0200)
committerMathias Brodala <mbrodala@pagemachine.de>
Tue, 14 Aug 2018 14:44:23 +0000 (16:44 +0200)
The template tool on root level, which displays an overview of pages
including templates, now displays instead of the count of templates
all related templates of a page with several informations like:
- title
- state (by icon)
- is root or extend
- direct link to edit (with ID ans site-title as link title)
Pages in rootline, which do not includes templates itself are no longer
linked to the template modul.
Database query has been streamlined, and all render logic of
Html specific output has been moved to FLUID templating.
This offers the possibility to add filter or search to this view.
An issue with page sorting in page tree, when rootline pages does not
contain TS templates has been fixed.

Resolves: #81430
Releases: master, 8.7
Change-Id: I5250c53df1acc4a1a29839ce4a472f3e863ae992
Reviewed-on: https://review.typo3.org/57856
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Tested-by: Mathias Brodala <mbrodala@pagemachine.de>
typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateModuleController.php
typo3/sysext/tstemplate/Resources/Private/Templates/PageZero.html

index 3143861..1675ae1 100644 (file)
@@ -211,27 +211,29 @@ class TypoScriptTemplateModuleController extends BaseScriptClass
                 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
                 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
 
-            $result = $queryBuilder->select('pages.uid')
-                ->addSelectLiteral(
-                    $queryBuilder->expr()->count('*', 'count'),
-                    $queryBuilder->expr()->max('sys_template.root', 'root_max_val'),
-                    $queryBuilder->expr()->min('sys_template.root', 'root_min_val')
+            $result = $queryBuilder->select('sys_template.uid')
+                ->addSelect(
+                    'sys_template.pid',
+                    'sys_template.title',
+                    'sys_template.sitetitle',
+                    'sys_template.root',
+                    'sys_template.hidden',
+                    'sys_template.starttime',
+                    'sys_template.endtime'
                 )
-                ->from('pages')
                 ->from('sys_template')
-                ->where($queryBuilder->expr()->eq('pages.uid', $queryBuilder->quoteIdentifier('sys_template.pid')))
-                ->groupBy('pages.uid', 'pages.pid', 'pages.sorting')
-                ->orderBy('pages.pid')
-                ->addOrderBy('pages.sorting')
+                ->orderBy('sys_template.pid')
+                ->addOrderBy('sys_template.sorting')
                 ->execute();
-
             $pArray = [];
             while ($record = $result->fetch()) {
-                $this->setInPageArray($pArray, BackendUtility::BEgetRootLine($record['uid'], 'AND 1=1'), $record);
+                $additionalFieldsForRootline = ['sorting', 'hidden', 'fe_group', 'starttime', 'endtime', 'shortcut', 'nav_hide', 'module', 'content_from_pid'];
+                $rootline = BackendUtility::BEgetRootLine($record['pid'], '', true, $additionalFieldsForRootline);
+                $this->setInPageArray($pArray, $rootline, $record);
             }
 
             $view->getRenderingContext()->setControllerAction('PageZero');
-            $view->assign('templateList', $this->renderList($pArray));
+            $view->assign('pageTree', $pArray);
 
             // RENDER LIST of pages with templates, END
             // Setting up the buttons and markers for docheader
@@ -572,13 +574,13 @@ page.10.value = HELLO WORLD!
         return $tce->substNEWwithIDs['NEW'];
     }
 
-    // RENDER LIST of pages with templates, BEGIN
     /**
      * Set page in array
+     * To render list of page tree with templates
      *
-     * @param array $pArray
-     * @param array $rlArr
-     * @param array $row
+     * @param array $pArray Multidimensional array of page tree with template records
+     * @param array $rlArr Rootline array
+     * @param array $row Record of sys_template
      */
     public function setInPageArray(&$pArray, $rlArr, $row)
     {
@@ -588,18 +590,29 @@ page.10.value = HELLO WORLD!
             array_shift($rlArr);
         }
         $cEl = current($rlArr);
-        $pArray[$cEl['uid']] = $cEl['title'];
+        if (empty($pArray[$cEl['uid']])) {
+            $pArray[$cEl['uid']] = $cEl;
+        }
         array_shift($rlArr);
+        $pArray[$cEl['uid']]['_linkModul'] = GeneralUtility::linkThisScript(['id' => (int)$cEl['uid']]);
+        $pArray[$cEl['uid']]['_icon'] = $this->moduleTemplate->getIconFactory()
+            ->getIconForRecord(
+                'pages',
+                BackendUtility::getRecordWSOL('pages', $cEl['uid']),
+                Icon::SIZE_SMALL
+            )->render();
         if (!empty($rlArr)) {
-            $key = $cEl['uid'] . '.';
-            if (empty($pArray[$key])) {
-                $pArray[$key] = [];
+            if (empty($pArray[$cEl['uid']]['_nodes'])) {
+                $pArray[$cEl['uid']]['_nodes'] = [];
             }
-            $this->setInPageArray($pArray[$key], $rlArr, $row);
+            $this->setInPageArray($pArray[$cEl['uid']]['_nodes'], $rlArr, $row);
         } else {
-            $key = $cEl['uid'] . '_';
-            $pArray[$key] = $row;
+            $row['_linkModul'] = GeneralUtility::linkThisScript(['id' => (int)$cEl['uid'], 'SET[templatesOnPage]' => $row['uid']]);
+            $pArray[$cEl['uid']]['_templates'][] = $row;
         }
+        uasort($pArray, function ($a, $b) {
+            return $a['sorting'] - $b['sorting'];
+        });
     }
 
     /**
index aa5c4f1..fbd3da4 100644 (file)
@@ -1,3 +1,4 @@
+<html xmlns:core="http://typo3.org/ns/TYPO3/CMS/Core/ViewHelpers" data-namespace-typo3-fluid="true">
 <h1><f:translate key="moduleTitle" /></h1>
 <div>
     <p class="lead"><f:translate key="overview" /></p>
@@ -12,8 +13,8 @@
             </tr>
         </thead>
         <tbody>
-            <f:for each="{templateList}" as="line">
-                <f:render section="PageZeroTableRow" arguments="{line: line}" />
+            <f:for each="{pageTree}" as="page">
+                <f:render section="PageZeroTableRow" arguments="{page: page, level: 0, template: page._templates.0}" />
             </f:for>
         </tbody>
         </table>
 </div>
 
 <f:section name="PageZeroTableRow">
-    <tr class="{line.class}">
+    <f:variable name="maxCharacters" value="30" />
+    <tr class="{f:if(condition: page.hidden, then: 'inactive')}">
         <td class="nowrap">
-            <span style="width: 1px; height: 1px; display:inline-block; margin-left: {line.marginLeft}px"></span>
-            <a href="{line.href}" title="{line.title}">
-                <f:format.raw>{line.icon}</f:format.raw>
-                {line.pageTitle}
-            </a>
+            <span style="width: 1px; height: 1px; display:inline-block; margin-left: {level * 20}px"></span>
+            <f:if condition="{page}">
+                <f:then>
+                    <f:if condition="{page._templates}">
+                        <f:then>
+                            <a href="{page._linkModul}"
+                               title="ID: {page.uid}">
+                                <f:format.raw>{page._icon}</f:format.raw>
+                                {page.title -> f:format.crop(maxCharacters: maxCharacters)}
+                            </a>
+                        </f:then>
+                        <f:else>
+                            <span title="ID: {page.uid}">
+                                <f:format.raw>{page._icon}</f:format.raw>
+                                {page.title -> f:format.crop(maxCharacters: maxCharacters)}
+                            </span>
+                        </f:else>
+                    </f:if>
+                </f:then>
+                <f:else>
+                    &nbsp;
+                </f:else>
+            </f:if>
+        </td>
+        <td>
+            <f:if condition="{template}">
+                <f:then>
+                    <a href="{template._linkModul}"
+                       title="ID: {template.uid} {template.sitetitle}">
+                        <core:iconForRecord table="sys_template" row="{template}" />
+                        {template.title -> f:format.crop(maxCharacters: maxCharacters)}
+                    </a>
+                </f:then>
+                <f:else>
+                    &nbsp;
+                </f:else>
+            </f:if>
+        </td>
+        <td>
+            <f:if condition="{template}">
+                {f:if(condition: "{template.root}", then: "{core:icon(identifier: 'status-status-checked')}" )}
+            </f:if>
+        </td>
+        <td>
+            <f:if condition="{template}">
+                {f:if(condition: "!{template.root}", then: "{core:icon(identifier: 'status-status-checked')}" )}
+            </f:if>
         </td>
-        <td>{line.count}</td>
-        <td><f:format.raw>{line.root_max_val}</f:format.raw></td>
-        <td><f:format.raw>{line.root_min_val}</f:format.raw></td>
     </tr>
+    <f:if condition="{page}">
+        <!-- Additional templates -->
+        <f:if condition="{f:count({page._templates})}">
+            <f:for each="{page._templates}" as="template" iteration="i">
+                <f:if condition="{i.index} > 0">
+                    <f:render section="PageZeroTableRow" arguments="{page: 0, level: level, template: template}" />
+                </f:if>
+            </f:for>
+        </f:if>
+        <!-- Subpages -->
+        <f:if condition="{f:count({page._nodes})}">
+            <f:for each="{page._nodes}" as="page">
+                <f:render section="PageZeroTableRow" arguments="{page: page, level: '{level + 1}', template: page._templates.0}" />
+            </f:for>
+        </f:if>
+    </f:if>
 </f:section>
+</html>
\ No newline at end of file