[CLEANUP] Use Permission constants consistently
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Be / TableListViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Be;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Type\Bitmask\Permission;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20
21 /**
22 * View helper which renders a record list as known from the TYPO3 list module
23 * Note: This feature is experimental!
24 *
25 * = Examples =
26 *
27 * <code title="Minimal">
28 * <f:be.tableList tableName="fe_users" />
29 * </code>
30 * <output>
31 * List of all "Website user" records stored in the configured storage PID.
32 * Records will be editable, if the current BE user has got edit rights for the table "fe_users".
33 * Only the title column (username) will be shown.
34 * Context menu is active.
35 * </output>
36 *
37 * <code title="Full">
38 * <f:be.tableList tableName="fe_users" fieldList="{0: 'name', 1: 'email'}" storagePid="1" levels="2" filter='foo' recordsPerPage="10" sortField="name" sortDescending="true" readOnly="true" enableClickMenu="false" clickTitleMode="info" />
39 * </code>
40 * <output>
41 * List of "Website user" records with a text property of "foo" stored on PID 1 and two levels down.
42 * Clicking on a username will open the TYPO3 info popup for the respective record
43 * </output>
44 */
45 class TableListViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper
46 {
47 /**
48 * As this ViewHelper renders HTML, the output must not be escaped.
49 *
50 * @var bool
51 */
52 protected $escapeOutput = false;
53
54 /**
55 * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
56 */
57 protected $configurationManager;
58
59 /**
60 * @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
61 */
62 public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
63 {
64 $this->configurationManager = $configurationManager;
65 }
66
67 /**
68 * Initialize arguments.
69 *
70 * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
71 */
72 public function initializeArguments()
73 {
74 parent::initializeArguments();
75 $this->registerArgument('tableName', 'string', 'name of the database table', true);
76 $this->registerArgument('fieldList', 'array', 'list of fields to be displayed. If empty, only the title column (configured in $TCA[$tableName][\'ctrl\'][\'title\']) is shown', false, []);
77 $this->registerArgument('storagePid', 'int', 'by default, records are fetched from the storage PID configured in persistence.storagePid. With this argument, the storage PID can be overwritten');
78 $this->registerArgument('levels', 'int', 'corresponds to the level selector of the TYPO3 list module. By default only records from the current storagePid are fetched', false, 0);
79 $this->registerArgument('filter', 'string', 'corresponds to the "Search String" textbox of the TYPO3 list module. If not empty, only records matching the string will be fetched', false, '');
80 $this->registerArgument('recordsPerPage', 'int', 'amount of records to be displayed at once. Defaults to $TCA[$tableName][\'interface\'][\'maxSingleDBListItems\'] or (if that\'s not set) to 100', false, 0);
81 $this->registerArgument('sortField', 'string', 'table field to sort the results by', false, '');
82 $this->registerArgument('sortDescending', 'bool', 'if TRUE records will be sorted in descending order', false, false);
83 $this->registerArgument('readOnly', 'bool', 'if TRUE, the edit icons won\'t be shown. Otherwise edit icons will be shown, if the current BE user has edit rights for the specified table!', false, false);
84 $this->registerArgument('enableClickMenu', 'bool', 'enables context menu', false, true);
85 $this->registerArgument('clickTitleMode', 'string', 'one of "edit", "show" (only pages, tt_content), "info');
86 }
87
88 /**
89 * Renders a record list as known from the TYPO3 list module
90 * Note: This feature is experimental!
91 *
92 * @return string the rendered record list
93 * @see \TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList
94 */
95 public function render()
96 {
97 $tableName = $this->arguments['tableName'];
98 $fieldList = $this->arguments['fieldList'];
99 $storagePid = $this->arguments['storagePid'];
100 $levels = $this->arguments['levels'];
101 $filter = $this->arguments['filter'];
102 $recordsPerPage = $this->arguments['recordsPerPage'];
103 $sortField = $this->arguments['sortField'];
104 $sortDescending = $this->arguments['sortDescending'];
105 $readOnly = $this->arguments['readOnly'];
106 $enableClickMenu = $this->arguments['enableClickMenu'];
107 $clickTitleMode = $this->arguments['clickTitleMode'];
108
109 $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Recordlist/Recordlist');
110
111 $pageinfo = BackendUtility::readPageAccess(GeneralUtility::_GP('id'), $GLOBALS['BE_USER']->getPagePermsClause(Permission::PAGE_SHOW));
112 /** @var $dblist \TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList */
113 $dblist = GeneralUtility::makeInstance(\TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList::class);
114 $dblist->pageRow = $pageinfo;
115 if ($readOnly === false) {
116 $dblist->calcPerms = $GLOBALS['BE_USER']->calcPerms($pageinfo);
117 }
118 $dblist->showClipboard = false;
119 $dblist->disableSingleTableView = true;
120 $dblist->clickTitleMode = $clickTitleMode;
121 $dblist->clickMenuEnabled = $enableClickMenu;
122 if ($storagePid === null) {
123 $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
124 $storagePid = $frameworkConfiguration['persistence']['storagePid'];
125 }
126 $dblist->start($storagePid, $tableName, (int)GeneralUtility::_GP('pointer'), $filter, $levels, $recordsPerPage);
127 $dblist->allFields = true;
128 $dblist->dontShowClipControlPanels = true;
129 $dblist->displayFields = false;
130 $dblist->setFields = [$tableName => $fieldList];
131 $dblist->noControlPanels = true;
132 $dblist->sortField = $sortField;
133 $dblist->sortRev = $sortDescending;
134 $dblist->script = $_SERVER['REQUEST_URI'];
135 $dblist->generateList();
136
137 $js = 'var T3_THIS_LOCATION = ' . GeneralUtility::quoteJSvalue(rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI')));
138 $html = GeneralUtility::wrapJS($js) . $dblist->HTMLcode;
139
140 return $html;
141 }
142 }