[!!!][TASK] Trees do not use global SOBE anymore
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / RecordList / ElementBrowserRecordList.php
1 <?php
2 namespace TYPO3\CMS\Backend\RecordList;
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\Backend\Utility\IconUtility;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Recordlist\Browser\ElementBrowser;
21 use TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList;
22
23 /**
24 * Displays the page/file tree for browsing database records or files.
25 * Used from TCEFORMS an other elements
26 * In other words: This is the ELEMENT BROWSER!
27 */
28 class ElementBrowserRecordList extends DatabaseRecordList {
29
30 /**
31 * Table name of the field pointing to this element browser
32 *
33 * @var string
34 */
35 protected $relatingTable;
36
37 /**
38 * Field name of the field pointing to this element browser
39 *
40 * @var string
41 */
42 protected $relatingField;
43
44 /**
45 * Back-reference to ElementBrowser class
46 *
47 * @var ElementBrowser
48 */
49 protected $elementBrowser;
50
51 /**
52 * Initializes the script path
53 */
54 public function __construct() {
55 parent::__construct();
56 $this->determineScriptUrl();
57 }
58
59 /**
60 * @param ElementBrowser $elementBrowser
61 * @return void
62 */
63 public function setElementBrowser(ElementBrowser $elementBrowser) {
64 $this->elementBrowser = $elementBrowser;
65 }
66
67 /**
68 * Creates the URL for links
69 *
70 * @param mixed $altId If not blank string, this is used instead of $this->id as the id value.
71 * @param string $table If this is "-1" then $this->table is used, otherwise the value of the input variable.
72 * @param string $exclList Commalist of fields NOT to pass as parameters (currently "sortField" and "sortRev")
73 * @return string Query-string for URL
74 */
75 public function listURL($altId = '', $table = '-1', $exclList = '') {
76 return $this->getThisScript() . 'id=' . ($altId !== '' ? $altId : $this->id)
77 . '&table=' . rawurlencode((int)$table === -1 ? $this->table : $table)
78 . ($this->thumbs ? '&imagemode=' . $this->thumbs : '')
79 . ($this->searchString ? '&search_field=' . rawurlencode($this->searchString) : '')
80 . ($this->searchLevels ? '&search_levels=' . rawurlencode($this->searchLevels) : '')
81 . ((!$exclList || !GeneralUtility::inList($exclList, 'sortField')) && $this->sortField ? '&sortField=' . rawurlencode($this->sortField) : '')
82 . ((!$exclList || !GeneralUtility::inList($exclList, 'sortRev')) && $this->sortRev ? '&sortRev=' . rawurlencode($this->sortRev) : '')
83 . $this->ext_addP();
84 }
85
86 /**
87 * Returns additional, local GET parameters to include in the links of the record list.
88 *
89 * @return string
90 */
91 public function ext_addP() {
92 return '&act=' . $this->elementBrowser->act . '&mode=' . $this->elementBrowser->mode . '&expandPage=' . $this->elementBrowser->expandPage . '&bparams=' . rawurlencode($this->elementBrowser->bparams);
93 }
94
95 /**
96 * Returns the title (based on $code) of a record (from table $table) with the proper link around (that is for "pages"-records a link to the level of that record...)
97 *
98 * @param string $table Table name
99 * @param int $uid UID (not used here)
100 * @param string $code Title string
101 * @param array $row Records array (from table name)
102 * @return string
103 */
104 public function linkWrapItems($table, $uid, $code, $row) {
105 if (!$code) {
106 $code = '<i>[' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.no_title', TRUE) . ']</i>';
107 } else {
108 $code = BackendUtility::getRecordTitlePrep($code, $this->fixedL);
109 }
110 $title = BackendUtility::getRecordTitle($table, $row, FALSE, TRUE);
111 $ficon = IconUtility::getSpriteIconForRecord($table, $row);
112 $aOnClick = 'return insertElement(' . GeneralUtility::quoteJSvalue($table) . ', ' . GeneralUtility::quoteJSvalue($row['uid']) . ', \'db\', ' . GeneralUtility::quoteJSvalue($title) . ', \'\', \'\', ' . GeneralUtility::quoteJSvalue($ficon) . ');';
113 $ATag = '<a href="#" onclick="' . $aOnClick . '">';
114 $ATag_alt = substr($ATag, 0, -4) . ',\'\',1);">';
115 $ATag_e = '</a>';
116 return $ATag . IconUtility::getSpriteIcon('actions-edit-add', array('title' => $this->getLanguageService()->getLL('addToList', TRUE))) . $ATag_e . $ATag_alt . $code . $ATag_e;
117 }
118
119 /**
120 * Check if all row listing conditions are fulfilled.
121 *
122 * @param string $table String Table name
123 * @param array $row Array Record
124 * @return bool True, if all conditions are fulfilled.
125 */
126 protected function isRowListingConditionFulfilled($table, $row) {
127 $returnValue = TRUE;
128 if ($this->relatingField && $this->relatingTable) {
129 $tcaFieldConfig = $GLOBALS['TCA'][$this->relatingTable]['columns'][$this->relatingField]['config'];
130 if (is_array($tcaFieldConfig['filter'])) {
131 foreach ($tcaFieldConfig['filter'] as $filter) {
132 if (!$filter['userFunc']) {
133 continue;
134 }
135 $parameters = $filter['parameters'] ?: array();
136 $parameters['values'] = array($table . '_' . $row['uid']);
137 $parameters['tcaFieldConfig'] = $tcaFieldConfig;
138 $valueArray = GeneralUtility::callUserFunction($filter['userFunc'], $parameters, $this);
139 if (empty($valueArray)) {
140 $returnValue = FALSE;
141 }
142 }
143 }
144 }
145 return $returnValue;
146 }
147
148 /**
149 * Set which pointing field (in the TCEForm) we are currently rendering the element browser for
150 *
151 * @param string $tableName Table name
152 * @param string $fieldName Field name
153 */
154 public function setRelatingTableAndField($tableName, $fieldName) {
155 // Check validity of the input data and load TCA
156 if (isset($GLOBALS['TCA'][$tableName])) {
157 $this->relatingTable = $tableName;
158 if ($fieldName && isset($GLOBALS['TCA'][$tableName]['columns'][$fieldName])) {
159 $this->relatingField = $fieldName;
160 }
161 }
162 }
163
164 /**
165 * Local version that sets allFields to TRUE to support userFieldSelect
166 *
167 * @return void
168 * @see fieldSelectBox
169 */
170 public function generateList() {
171 $this->allFields = TRUE;
172 parent::generateList();
173 }
174
175 }