[TASK] Use ModuleTemplate API for RecordList 57/43757/4
authorMathias Schreiber <mathias.schreiber@wmdb.de>
Sat, 3 Oct 2015 13:16:04 +0000 (15:16 +0200)
committerFrank Nägler <frank.naegler@typo3.org>
Mon, 12 Oct 2015 09:24:51 +0000 (11:24 +0200)
Releases: master
Resolves: #69884
Change-Id: I4127b5f49deb4ea749da0e854ad27bbba07f9221
Reviewed-on: http://review.typo3.org/43757
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
Tested-by: Frank Nägler <frank.naegler@typo3.org>
Reviewed-by: Markus Sommer <markussom@posteo.de>
Tested-by: Markus Sommer <markussom@posteo.de>
typo3/sysext/backend/Classes/Template/ModuleTemplate.php
typo3/sysext/recordlist/Classes/RecordList.php
typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php

index 0f60921..caf12a4 100644 (file)
@@ -877,4 +877,46 @@ class ModuleTemplate
         }
         return '';
     }
+
+    /**
+     * Returns JavaScript variables setting the returnUrl and thisScript location for use by JavaScript on the page.
+     * Used in fx. db_list.php (Web>List)
+     *
+     * @param string $thisLocation URL to "this location" / current script
+     * @return string Urls are returned as JavaScript variables T3_RETURN_URL and T3_THIS_LOCATION
+     * @see typo3/db_list.php
+     * @internal
+     */
+    public function redirectUrls($thisLocation = '')
+    {
+        $thisLocation = $thisLocation ? $thisLocation : GeneralUtility::linkThisScript(array(
+            'CB' => '',
+            'SET' => '',
+            'cmd' => '',
+            'popViewId' => ''
+        ));
+        $out = '
+       var T3_RETURN_URL = ' . GeneralUtility::quoteJSvalue(str_replace('%20', '', rawurlencode(GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'))))) . ';
+       var T3_THIS_LOCATION = ' . GeneralUtility::quoteJSvalue(str_replace('%20', '', rawurlencode($thisLocation))) . '
+               ';
+        return $out;
+    }
+
+    /**
+     * Returns the header-bar in the top of most backend modules
+     * Closes section if open.
+     *
+     * @param string $text The text string for the header
+     * @return string HTML content
+     * @internal
+     */
+    public function header($text)
+    {
+        $str = '
+
+       <!-- MAIN Header in page top -->
+       <h1 class="t3js-title-inlineedit">' . htmlspecialchars($text) . '</h1>
+';
+        return $this->sectionEnd() . $str;
+    }
 }
index 133b7f5..9f1d762 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Recordlist;
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Backend\Clipboard\Clipboard;
+use TYPO3\CMS\Backend\Module\AbstractModule;
 use TYPO3\CMS\Backend\Template\DocumentTemplate;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
@@ -35,7 +36,7 @@ use TYPO3\CMS\Lang\LanguageService;
 /**
  * Script Class for the Web > List module; rendering the listing of records on a page
  */
-class RecordList
+class RecordList extends AbstractModule
 {
     /**
      * Page Id for which to make the listing
@@ -198,11 +199,11 @@ class RecordList
      */
     public function __construct()
     {
+        parent::__construct();
         $this->getLanguageService()->includeLLFile('EXT:lang/locallang_mod_web_list.xlf');
-        $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
-        $this->pageRenderer->loadJquery();
-        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Recordlist/FieldSelectBox');
-        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Recordlist/Recordlist');
+        $this->moduleTemplate->getPageRenderer()->loadJquery();
+        $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Recordlist/FieldSelectBox');
+        $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Recordlist/Recordlist');
     }
 
     /**
@@ -285,8 +286,9 @@ class RecordList
         $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
         $access = is_array($this->pageinfo) ? 1 : 0;
         // Start document template object:
+        // We need to keep this due to deeply nested dependencies
         $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
-        $this->doc->setModuleTemplate('EXT:recordlist/Resources/Private/Templates/db_list.html');
+
         $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/AjaxDataHandler');
         $calcPerms = $backendUser->calcPerms($this->pageinfo);
         $userCanEditPage = $calcPerms & Permission::PAGE_EDIT && !empty($this->id) && ($backendUser->isAdmin() || (int)$this->pageinfo['editlock'] === 0);
@@ -403,13 +405,16 @@ class RecordList
             $dblist->setDispFields();
             // Render versioning selector:
             if (ExtensionManagementUtility::isLoaded('version')) {
-                $dblist->HTMLcode .= $this->doc->getVersionSelector($this->id);
+                $dblist->HTMLcode .= $this->moduleTemplate->getVersionSelector($this->id);
             }
             // Render the list of tables:
             $dblist->generateList();
             $listUrl = $dblist->listURL();
             // Add JavaScript functions to the page:
-            $this->doc->JScode = $this->doc->wrapScriptTags('
+
+            $this->moduleTemplate->addJavaScriptCode(
+                'RecordListInlineJS',
+                '
                                function jumpExt(URL,anchor) {  //
                                        var anc = anchor?anchor:"";
                                        window.location.href = URL+(T3_THIS_LOCATION?"&returnUrl="+T3_THIS_LOCATION:"")+anc;
@@ -428,7 +433,7 @@ class RecordList
                                                top.content.nav_frame.refresh_nav();
                                        }
                                }
-                               ' . $this->doc->redirectUrls($listUrl) . '
+                               ' . $this->moduleTemplate->redirectUrls($listUrl) . '
                                ' . $dblist->CBfunctions() . '
                                function editRecords(table,idList,addParams,CBflag) {   //
                                        window.location.href="' . BackendUtility::getModuleUrl('record_edit', array('returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'))) . '&edit["+table+"]["+idList+"]=edit"+addParams;
@@ -454,16 +459,18 @@ class RecordList
                                }
 
                                if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
-                       ');
+                       '
+            );
+
             // Setting up the context sensitive menu:
-            $this->doc->getContextMenuCode();
+            $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu');
         }
         // access
         // Begin to compile the whole page, starting out with page header:
         if (!$this->id) {
-            $this->body = $this->doc->header($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
+            $this->body = $this->moduleTemplate->header($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
         } else {
-            $this->body = $this->doc->header($this->pageinfo['title']);
+            $this->body = $this->moduleTemplate->header($this->pageinfo['title']);
         }
 
         if (!empty($dblist->HTMLcode)) {
@@ -543,25 +550,24 @@ class RecordList
                 $this->body .= GeneralUtility::callUserFunction($hook, $params, $this);
             }
         }
-        // Setting up the buttons and markers for docheader
-        $docHeaderButtons = $dblist->getButtons();
-        $markers = array(
-            'CSH' => $docHeaderButtons['csh'],
-            'CONTENT' => $this->body,
-            'EXTRACONTAINERCLASS' => $this->table ? 'singletable' : '',
-            'BUTTONLIST_ADDITIONAL' => '',
-            'SEARCHBOX' => '',
-        );
+        // Setting up the buttons for docheader
+        $dblist->getDocHeaderButtons($this->moduleTemplate);
         // searchbox toolbar
         if (!$this->modTSconfig['properties']['disableSearchBox'] && ($dblist->HTMLcode || !empty($dblist->searchString))) {
-            $markers['SEARCHBOX'] = $dblist->getSearchBox();
-            $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ToggleSearchToolbox');
-            $markers['BUTTONLIST_ADDITIONAL'] = '<a href="#" class="t3js-toggle-search-toolbox" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.title.searchIcon', true) . '">' . $this->iconFactory->getIcon('actions-search', Icon::SIZE_SMALL) . '</a>';
+            $this->content = $dblist->getSearchBox();
+            $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ToggleSearchToolbox');
         }
+        $searchButton = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar()->makeLinkButton();
+        $searchButton
+            ->setHref('#')
+            ->setClasses('t3js-toggle-search-toolbox')
+            ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.title.searchIcon', true))
+            ->setIcon($this->iconFactory->getIcon('actions-search', Icon::SIZE_SMALL));
+        $this->moduleTemplate->getDocHeaderComponent()->getButtonBar()->addButton($searchButton);
+
+        $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
         // Build the <body> for the module
-        $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
-        // Renders the module page
-        $this->content = $this->doc->render('DB list', $this->content);
+        $this->content .= $this->body;
     }
 
     /**
@@ -579,8 +585,8 @@ class RecordList
         $this->init();
         $this->clearCache();
         $this->main();
-
-        $response->getBody()->write($this->content);
+        $this->moduleTemplate->setContent($this->content);
+        $response->getBody()->write($this->moduleTemplate->renderContent());
         return $response;
     }
 
index 0b26b0d..047ed42 100644 (file)
@@ -16,7 +16,9 @@ namespace TYPO3\CMS\Recordlist\RecordList;
 
 use TYPO3\CMS\Backend\Module\BaseScriptClass;
 use TYPO3\CMS\Backend\RecordList\RecordListGetTableHookInterface;
+use TYPO3\CMS\Backend\Template\Components\ButtonBar;
 use TYPO3\CMS\Backend\Template\DocumentTemplate;
+use TYPO3\CMS\Backend\Template\ModuleTemplate;
 use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
@@ -333,6 +335,140 @@ class DatabaseRecordList extends AbstractDatabaseRecordList
     }
 
     /**
+     * Create the panel of buttons for submitting the form or otherwise perform
+     * operations.
+     *
+     * @param ModuleTemplate $moduleTemplate
+     */
+    public function getDocHeaderButtons(ModuleTemplate $moduleTemplate)
+    {
+        $buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();
+        $module = $this->getModule();
+        $backendUser = $this->getBackendUserAuthentication();
+        $lang = $this->getLanguageService();
+        // Get users permissions for this page record:
+        $localCalcPerms = $backendUser->calcPerms($this->pageRow);
+        // CSH
+        $cshButton = $buttonBar->makeFullyRenderedButton();
+        if ((string)$this->id === '') {
+            $cshButton->setHtmlSource(BackendUtility::cshItem('xMOD_csh_corebe', 'list_module_noId'));
+        } elseif (!$this->id) {
+            $cshButton->setHtmlSource(BackendUtility::cshItem('xMOD_csh_corebe', 'list_module_root'));
+        } else {
+            $cshButton->setHtmlSource(BackendUtility::cshItem('xMOD_csh_corebe', 'list_module'));
+        }
+        $buttonBar->addButton($cshButton);
+        if (isset($this->id)) {
+            // View Exclude doktypes 254,255 Configuration:
+            // mod.web_list.noViewWithDokTypes = 254,255
+            if (isset($module->modTSconfig['properties']['noViewWithDokTypes'])) {
+                $noViewDokTypes = GeneralUtility::trimExplode(',', $module->modTSconfig['properties']['noViewWithDokTypes'], true);
+            } else {
+                //default exclusion: doktype 254 (folder), 255 (recycler)
+                $noViewDokTypes = array(
+                    PageRepository::DOKTYPE_SYSFOLDER,
+                    PageRepository::DOKTYPE_RECYCLER
+                );
+            }
+            // New record on pages that are not locked by editlock
+            if (!$module->modTSconfig['properties']['noCreateRecordsLink'] && $this->editLockPermissions()) {
+                $onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('db_new', ['id' => $this->id])) . ');';
+                $newRecordButton = $buttonBar->makeLinkButton()
+                    ->setHref('#')
+                    ->setOnClick($onClick)
+                    ->setTitle($lang->getLL('newRecordGeneral', true))
+                    ->setIcon($this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL));
+                $buttonBar->addButton($newRecordButton);
+            }
+            if (!in_array($this->pageRow['doktype'], $noViewDokTypes)) {
+                $onClick = BackendUtility::viewOnClick($this->id, '', BackendUtility::BEgetRootLine($this->id));
+                $viewButton = $buttonBar->makeLinkButton()
+                    ->setHref('#')
+                    ->setOnClick($onClick)
+                    ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', true))
+                    ->setIcon($this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL));
+                $buttonBar->addButton($viewButton);
+            }
+            // If edit permissions are set, see
+            // \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
+            if ($localCalcPerms & Permission::PAGE_EDIT && !empty($this->id) && $this->editLockPermissions()) {
+                // Edit
+                $params = '&edit[pages][' . $this->pageRow['uid'] . ']=edit';
+                $onClick = BackendUtility::editOnClick($params, '', -1);
+                $editButton = $buttonBar->makeLinkButton()
+                    ->setHref('#')
+                    ->setOnClick($onClick)
+                    ->setTitle($lang->getLL('editPage', true))
+                    ->setIcon($this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL));
+                $buttonBar->addButton($editButton);
+            }
+            // Paste
+            if (($localCalcPerms & Permission::PAGE_NEW || $localCalcPerms & Permission::CONTENT_EDIT) && $this->editLockPermissions()) {
+                $elFromTable = $this->clipObj->elFromTable('');
+                if (!empty($elFromTable)) {
+                    $onClick = 'return ' . $this->clipObj->confirmMsg('pages', $this->pageRow, 'into', $elFromTable);
+                    $pasteButton = $buttonBar->makeLinkButton()
+                        ->setHref($this->clipObj->pasteUrl('', $this->id))
+                        ->setOnClick($onClick)
+                        ->setTitle($lang->getLL('clip_paste', true))
+                        ->setIcon($this->iconFactory->getIcon('actions-document-paste-after', Icon::SIZE_SMALL));
+                    $buttonBar->addButton($pasteButton);
+                }
+            }
+            // Cache
+            $clearCacheButton = $buttonBar->makeLinkButton()
+                ->setHref($this->listURL() . '&clear_cache=1')
+                ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.clear_cache', true))
+                ->setIcon($this->iconFactory->getIcon('actions-system-cache-clear', Icon::SIZE_SMALL));
+            $buttonBar->addButton($clearCacheButton, ButtonBar::BUTTON_POSITION_RIGHT);
+            if (
+                $this->table && (!isset($module->modTSconfig['properties']['noExportRecordsLinks'])
+                || (isset($module->modTSconfig['properties']['noExportRecordsLinks'])
+                    && !$module->modTSconfig['properties']['noExportRecordsLinks']))
+            ) {
+                // CSV
+                $csvButton = $buttonBar->makeLinkButton()
+                    ->setHref($this->listURL() . '&csv=1')
+                    ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.csv', true))
+                    ->setIcon($this->iconFactory->getIcon('actions-document-export-csv', Icon::SIZE_SMALL));
+                $buttonBar->addButton($csvButton);
+                // Export
+                if (ExtensionManagementUtility::isLoaded('impexp')) {
+                    $url = BackendUtility::getModuleUrl('xMOD_tximpexp', array('tx_impexp[action]' => 'export'));
+                    $exportButton = $buttonBar->makeLinkButton()
+                        ->setHref($url . '&tx_impexp[list][]=' . rawurlencode($this->table . ':' . $this->id))
+                        ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.export', true))
+                        ->setIcon($this->iconFactory->getIcon('actions-document-export-t3d', Icon::SIZE_SMALL));
+                    $buttonBar->addButton($exportButton);
+                }
+            }
+            // Reload
+            $reloadButton = $buttonBar->makeLinkButton()
+                ->setHref($this->listURL())
+                ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.reload', true))
+                ->setIcon($this->iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL));
+            $buttonBar->addButton($reloadButton, ButtonBar::BUTTON_POSITION_RIGHT);
+            // Shortcut
+            if ($backendUser->mayMakeShortcut()) {
+                $shortCutButton = $buttonBar->makeFullyRenderedButton()
+                    ->setHtmlSource($moduleTemplate->makeShortcutIcon(
+                        'id, imagemode, pointer, table, search_field, search_levels, showLimit, sortField, sortRev',
+                        implode(',', array_keys($this->MOD_MENU)),
+                        'web_list'
+                    ));
+                $buttonBar->addButton($shortCutButton, ButtonBar::BUTTON_POSITION_RIGHT);
+            }
+            // Back
+            if ($this->returnUrl) {
+                $href = htmlspecialchars(GeneralUtility::linkThisUrl($this->returnUrl, array('id' => $this->id)));
+                $buttons['back'] = '<a href="' . $href . '" class="typo3-goBack" title="'
+                    . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', true) . '">'
+                    . $this->iconFactory->getIcon('actions-view-go-back', Icon::SIZE_SMALL) . '</a>';
+            }
+        }
+    }
+
+    /**
      * Creates the listing of records from a single table
      *
      * @param string $table Table name
@@ -845,7 +981,7 @@ class DatabaseRecordList extends AbstractDatabaseRecordList
         ) {
             $theData['parent'] = $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']];
         }
-        $rowOutput .= $this->addelement(1, $theIcon, $theData, $row_bgColor);
+        $rowOutput .= $this->addElement(1, $theIcon, $theData, $row_bgColor);
         // Finally, return table row element:
         return $rowOutput;
     }
@@ -1098,7 +1234,7 @@ class DatabaseRecordList extends AbstractDatabaseRecordList
 
 
         // Create and return header table row:
-        return '<thead>' . $this->addelement(1, $icon, $theData, '', '', '', 'th') . '</thead>';
+        return '<thead>' . $this->addElement(1, $icon, $theData, '', '', '', 'th') . '</thead>';
     }
 
     /**
@@ -1736,7 +1872,7 @@ class DatabaseRecordList extends AbstractDatabaseRecordList
                 ? rtrim($lang->sL($GLOBALS['TCA'][$table]['columns'][$fieldName]['label']), ':')
                 : '';
             $checkboxes[] = '<tr><td class="col-checkbox"><input type="checkbox" id="check-' . $fieldName . '" name="displayFields['
-                . $table . '][]" value="' . $fieldName . '"' . $checked
+                . $table . '][]" value="' . $fieldName . '" ' . $checked
                 . ($fieldName === $this->fieldArray[0] ? ' disabled="disabled"' : '') . '></td><td class="col-title">'
                 . '<label class="label-block" for="check-' . $fieldName . '">' . htmlspecialchars($fieldLabel) . ' <span class="text-muted text-monospace">[' . htmlspecialchars($fieldName) . ']</span></label></td></tr>';
         }
@@ -1796,7 +1932,7 @@ class DatabaseRecordList extends AbstractDatabaseRecordList
      */
     public function clipNumPane()
     {
-        return in_Array('_CLIPBOARD_', $this->fieldArray) && $this->clipObj->current != 'normal';
+        return in_array('_CLIPBOARD_', $this->fieldArray) && $this->clipObj->current != 'normal';
     }
 
     /**