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