[TASK] Fluidification of SortPages Wizard 52/49952/5
authorMichael Oehlhof <typo3@oehlhof.de>
Fri, 16 Sep 2016 11:04:13 +0000 (13:04 +0200)
committerJan Helke <typo3@helke.de>
Thu, 6 Oct 2016 09:45:40 +0000 (11:45 +0200)
Resolves: #77971
Releases: master
Change-Id: I865196db43517a4f154b4e88e3459aee57f4850a
Reviewed-on: https://review.typo3.org/49952
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
typo3/sysext/wizard_sortpages/Classes/View/SortPagesWizardModuleFunction.php
typo3/sysext/wizard_sortpages/Resources/Private/Templates/SortPagesWizard.html [new file with mode: 0644]

index 4cb2db0..ea8fcc7 100644 (file)
@@ -15,12 +15,10 @@ namespace TYPO3\CMS\WizardSortpages\View;
  */
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
-use TYPO3\CMS\Core\Imaging\Icon;
-use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Messaging\FlashMessageService;
-use TYPO3\CMS\Core\Page\PageRenderer;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Fluid\View\StandaloneView;
 
 /**
  * Creates the "Sort pages" wizard
@@ -34,13 +32,10 @@ class SortPagesWizardModuleFunction extends \TYPO3\CMS\Backend\Module\AbstractFu
      */
     public function main()
     {
-        $lang = $this->getLanguageService();
-        $lang->includeLLFile('EXT:wizard_sortpages/Resources/Private/Language/locallang.xlf');
-        $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
-        $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
-        $out = '<h1>' . htmlspecialchars($lang->getLL('wiz_sort')) . '</h1>';
+        $assigns = [];
+        $assigns['LLPrefix'] = 'LLL:EXT:wizard_sortpages/Resources/Private/Language/locallang.xlf:';
+        $assigns['workspace'] = $this->getBackendUser()->workspace;
         if ($this->getBackendUser()->workspace === 0) {
-            $theCode = '';
             // Check if user has modify permissions to
             $sys_pages = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
             $sortByField = GeneralUtility::_GP('sortByField');
@@ -65,40 +60,71 @@ class SortPagesWizardModuleFunction extends \TYPO3\CMS\Backend\Module\AbstractFu
                 }
             }
             $menuItems = $sys_pages->getMenu($this->pObj->id, '*', 'sorting', '', false);
-
+            $assigns['menuItems'] = $menuItems;
             if (!empty($menuItems)) {
-                $lines = [];
-                $lines[] = '<thead><tr>';
-                $lines[] = '<th>' . $lang->getLL('wiz_changeOrder_title') . '</th>';
-                $lines[] = '<th>' . $lang->getLL('wiz_changeOrder_subtitle') . '</th>';
-                $lines[] = '<th>' . $lang->getLL('wiz_changeOrder_tChange') . '</th>';
-                $lines[] = '<th>' . $lang->getLL('wiz_changeOrder_tCreate') . '</th>';
-                $lines[] = '</tr></thead>';
-
-                $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
+                $dataLines = [];
                 foreach ($menuItems as $rec) {
                     $m_perms_clause = $this->getBackendUser()->getPagePermsClause(2);
                     // edit permissions for that page!
                     $pRec = BackendUtility::getRecord('pages', $rec['uid'], 'uid', ' AND ' . $m_perms_clause);
-                    $lines[] = '<tr><td nowrap="nowrap">' . $iconFactory->getIconForRecord('pages', $rec, Icon::SIZE_SMALL)->render() . (!is_array($pRec) ? '<strong class="text-danger">' . htmlspecialchars($lang->getLL('wiz_W')) . '</strong></span> ' : '') . htmlspecialchars(GeneralUtility::fixed_lgd_cs($rec['title'], $GLOBALS['BE_USER']->uc['titleLen'])) . '</td>
-                                       <td nowrap="nowrap">' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($rec['subtitle'], $this->getBackendUser()->uc['titleLen'])) . '</td>
-                                       <td nowrap="nowrap">' . BackendUtility::datetime($rec['tstamp']) . '</td>
-                                       <td nowrap="nowrap">' . BackendUtility::datetime($rec['crdate']) . '</td>
-                                       </tr>';
+                    $line = [];
+                    $line['rec'] = $rec;
+                    $line['danger'] = !is_array($pRec);
+                    $line['title'] = GeneralUtility::fixed_lgd_cs($rec['title'], $GLOBALS['BE_USER']->uc['titleLen']);
+                    $line['subtitle'] = GeneralUtility::fixed_lgd_cs($rec['subtitle'], $this->getBackendUser()->uc['titleLen']);
+                    $line['tstamp'] = BackendUtility::datetime($rec['tstamp']);
+                    $line['crdate'] = BackendUtility::datetime($rec['crdate']);
+                    $dataLines[] = $line;
                 }
-                $theCode .= '<h2>' . htmlspecialchars($lang->getLL('wiz_currentPageOrder')) . '</h2>';
-                $theCode .= '<div class="table-fit"><table class="table table-striped table-hover">' . implode('', $lines) . '</table></div>';
+                $assigns['lines'] = $dataLines;
 
                 // Menu:
-                $lines = [];
-                $lines[] = $this->wiz_linkOrder($lang->getLL('wiz_changeOrder_title'), 'title');
-                $lines[] = $this->wiz_linkOrder($lang->getLL('wiz_changeOrder_subtitle'), 'subtitle');
-                $lines[] = $this->wiz_linkOrder($lang->getLL('wiz_changeOrder_tChange'), 'tstamp');
-                $lines[] = $this->wiz_linkOrder($lang->getLL('wiz_changeOrder_tCreate'), 'crdate');
-                $lines[] = '';
-                $lines[] = $this->wiz_linkOrder($lang->getLL('wiz_changeOrder_REVERSE'), 'REV');
-                $theCode .= '<h4>' . $lang->getLL('wiz_changeOrder') . '</h4><p>' . implode(' ', $lines) . '</p>';
+                $dataLines = [];
+                $line = [];
+                $line['title'] = 'wiz_changeOrder_title';
+                $line['href'] = BackendUtility::getModuleUrl('web_func',
+                    [
+                        'id' => $GLOBALS['SOBE']->id,
+                        'sortByField' => 'title'
+                    ]
+                );
+                $dataLines[] = $line;
+                $line['title'] = 'wiz_changeOrder_subtitle';
+                $line['href'] = BackendUtility::getModuleUrl('web_func',
+                    [
+                        'id' => $GLOBALS['SOBE']->id,
+                        'sortByField' => 'subtitle'
+                    ]
+                );
+                $dataLines[] = $line;
+                $line['title'] = 'wiz_changeOrder_tChange';
+                $line['href'] = BackendUtility::getModuleUrl('web_func',
+                    [
+                        'id' => $GLOBALS['SOBE']->id,
+                        'sortByField' => 'tstamp'
+                    ]
+                );
+                $dataLines[] = $line;
+                $line['title'] = 'wiz_changeOrder_tCreate';
+                $line['href'] = BackendUtility::getModuleUrl('web_func',
+                    [
+                        'id' => $GLOBALS['SOBE']->id,
+                        'sortByField' => 'crdate'
+                    ]
+                );
+                $dataLines[] = $line;
+                $line['title'] = 'wiz_changeOrder_REVERSE';
+                $line['href'] = BackendUtility::getModuleUrl('web_func',
+                    [
+                        'id' => $GLOBALS['SOBE']->id,
+                        'sortByField' => 'REV'
+                    ]
+                );
+                $dataLines[] = $line;
+                $assigns['buttons'] = $dataLines;
             } else {
+                $lang = $this->getLanguageService();
+                $lang->includeLLFile('EXT:wizard_sortpages/Resources/Private/Language/locallang.xlf');
                 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $lang->getLL('no_subpages'), '', FlashMessage::NOTICE);
                 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
                 $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
@@ -107,35 +133,15 @@ class SortPagesWizardModuleFunction extends \TYPO3\CMS\Backend\Module\AbstractFu
                 $defaultFlashMessageQueue->enqueue($flashMessage);
             }
             // CSH:
-            $theCode .= BackendUtility::cshItem('_MOD_web_func', 'tx_wizardsortpages', null, '<span class="btn btn-default btn-sm">|</span>');
-            $out .= '<div>' . $theCode . '</div>';
-        } else {
-            $out .= '<div>' . htmlspecialchars($lang->getLL('not_available_in_draft_workspace')) . '</div>';
+            $assigns['cshItem'] = BackendUtility::cshItem('_MOD_web_func', 'tx_wizardsortpages');
         }
-        return $out;
-    }
-
-    /**
-     * Creates a link for the sorting order
-     *
-     * @param string $title Title of the link
-     * @param string $order Field to sort by
-     * @return string HTML string
-     */
-    protected function wiz_linkOrder($title, $order)
-    {
-        $href = BackendUtility::getModuleUrl('web_func',
-            [
-                'id' => $GLOBALS['SOBE']->id,
-                'sortByField' => $order
-            ]
-        );
-        return '<a class="btn btn-default t3js-modal-trigger" href="' . htmlspecialchars($href) . '" '
-            . ' data-severity="warning"'
-            . ' data-title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:pleaseConfirm')) . '"'
-            . ' data-button-close-text="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:cancel')) . '"'
-            . ' data-content="' . htmlspecialchars($this->getLanguageService()->getLL('wiz_changeOrder_msg1')) . '"'
-            . ' >' . htmlspecialchars($title) . '</a>';
+        // Rendering of the output via fluid
+        $view = GeneralUtility::makeInstance(StandaloneView::class);
+        $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
+            'EXT:wizard_sortpages/Resources/Private/Templates/SortPagesWizard.html'
+        ));
+        $view->assignMultiple($assigns);
+        return $view->render();
     }
 
     /**
diff --git a/typo3/sysext/wizard_sortpages/Resources/Private/Templates/SortPagesWizard.html b/typo3/sysext/wizard_sortpages/Resources/Private/Templates/SortPagesWizard.html
new file mode 100644 (file)
index 0000000..49a0d6e
--- /dev/null
@@ -0,0 +1,58 @@
+{namespace core=TYPO3\CMS\Core\ViewHelpers}
+
+<f:be.pageRenderer includeRequireJsModules="{0:'TYPO3/CMS/Backend/Modal'}" />
+<h1><f:translate key="{LLPrefix}wiz_sort"/></h1>
+
+<div>
+    <f:if condition="{workspace}">
+        <f:then>
+            <f:translate key="{LLPrefix}not_available_in_draft_workspace"/>
+        </f:then>
+        <f:else>
+            <f:if condition="{menuItems}">
+                <h2><f:translate key="{LLPrefix}wiz_currentPageOrder"/></h2>
+                <div class="table-fit">
+                    <table class="table table-striped table-hover">
+                        <thead><tr>
+                        <th><f:translate key="{LLPrefix}wiz_changeOrder_title"/></th>
+                        <th><f:translate key="{LLPrefix}wiz_changeOrder_subtitle"/></th>
+                        <th><f:translate key="{LLPrefix}wiz_changeOrder_tChange"/></th>
+                        <th><f:translate key="{LLPrefix}wiz_changeOrder_tCreate"/></th>
+                        </tr></thead>
+                        <f:for each="{lines}" as="line">
+                            <tr><td class="text-nowrap"><core:iconForRecord table="pages" row="{line.rec}" />
+                                <f:if condition="{line.danger}">
+                                    <strong class="text-danger"><f:translate key="{LLPrefix}wiz_W"/></strong>&nbsp;
+                                </f:if>
+                                {line.title}</td>
+                                <td class="text-nowrap">{line.subtitle}</td>
+                                <td class="text-nowrap">{line.tstamp}</td>
+                                <td class="text-nowrap">{line.crdate}</td>
+                            </tr>
+                        </f:for>
+                    </table>
+                </div>
+                <h4><f:translate key="{LLPrefix}wiz_changeOrder"/></h4>
+                <p>
+                    <f:for each="{buttons}" as="button">
+                        <f:render section="Button" arguments="{button: button, LLPrefix: LLPrefix}" />
+                    </f:for>
+                </p>
+            </f:if>
+        </f:else>
+    </f:if>
+
+    <f:if condition="{cshItem}">
+        <span class="btn btn-default btn-sm">{cshItem -> f:format.raw()}</span>
+    </f:if>
+</div>
+
+<f:section name="Button">
+    <a class="btn btn-default t3js-modal-trigger"
+        href="{button.href}"
+        data-severity="warning"
+        data-title="{f:translate(key: 'LLL:EXT:lang/locallang_common.xlf:pleaseConfirm')}"
+        data-button-close-text="{f:translate(key: 'LLL:EXT:lang/locallang_common.xlf:cancel')}"
+        data-content="{f:translate(key: '{LLPrefix}wiz_changeOrder_msg1')}" >
+        <f:translate key="{LLPrefix}{button.title}"/></a>
+</f:section>