Conditions | 27 |
Paths | > 20000 |
Total Lines | 224 |
Code Lines | 176 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
123 | public function renderL10nTable(&$tree) |
||
124 | { |
||
125 | $lang = $this->getLanguageService(); |
||
126 | // System languages retrieved: |
||
127 | $languages = $this->getSystemLanguages(); |
||
128 | // Title length: |
||
129 | $titleLen = $this->getBackendUser()->uc['titleLen']; |
||
130 | // Put together the TREE: |
||
131 | $output = ''; |
||
132 | $newOL_js = []; |
||
133 | $langRecUids = []; |
||
134 | /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */ |
||
135 | $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class); |
||
136 | foreach ($tree->tree as $data) { |
||
137 | $tCells = []; |
||
138 | $langRecUids[0][] = $data['row']['uid']; |
||
139 | // Page icons / titles etc. |
||
140 | $tCells[] = '<td' . ($data['row']['_CSSCLASS'] ? ' class="' . $data['row']['_CSSCLASS'] . '"' : '') . '>' . |
||
141 | ($data['depthData'] ?: '') . |
||
142 | BackendUtility::wrapClickMenuOnIcon($data['HTML'], 'pages', $data['row']['uid']) . |
||
143 | '<a href="#" onclick="' . htmlspecialchars( |
||
144 | 'top.loadEditId(' . (int)$data['row']['uid'] . ',"&SET[language]=0"); return false;' |
||
145 | ) . '" title="' . $lang->sL('LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_editPage') . '">' . |
||
146 | htmlspecialchars(GeneralUtility::fixed_lgd_cs($data['row']['title'], $titleLen)) . |
||
147 | '</a>' . |
||
148 | ((string)$data['row']['nav_title'] !== '' ? ' [Nav: <em>' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($data['row']['nav_title'], $titleLen)) . '</em>]' : '') . |
||
149 | '</td>'; |
||
150 | // DEFAULT language: |
||
151 | // "View page" link is created: |
||
152 | $viewPageLink = '<a href="#" onclick="' . htmlspecialchars( |
||
153 | BackendUtility::viewOnClick( |
||
154 | $data['row']['uid'], |
||
155 | '', |
||
156 | null, |
||
157 | '', |
||
158 | '', |
||
159 | '&L=###LANG_UID###' |
||
160 | ) |
||
161 | ) . '" class="btn btn-default" title="' . $lang->sL('LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_viewPage') . '">' . |
||
162 | $this->iconFactory->getIcon('actions-view', Icon::SIZE_SMALL)->render() . '</a>'; |
||
163 | $status = GeneralUtility::hideIfDefaultLanguage($data['row']['l18n_cfg']) ? 'danger' : 'success'; |
||
164 | // Create links: |
||
165 | $editUrl = (string)$uriBuilder->buildUriFromRoute('record_edit', [ |
||
166 | 'edit' => [ |
||
167 | 'pages' => [ |
||
168 | $data['row']['uid'] => 'edit' |
||
169 | ] |
||
170 | ], |
||
171 | 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI') |
||
172 | ]); |
||
173 | $info = '<a href="#" onclick="' . htmlspecialchars( |
||
174 | BackendUtility::viewOnClick( |
||
175 | $data['row']['uid'], |
||
176 | '', |
||
177 | null, |
||
178 | '', |
||
179 | '', |
||
180 | '' |
||
181 | ) |
||
182 | ) . '" class="btn btn-default" title="' . $lang->sL('LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_viewPage') . '">' . |
||
183 | $this->iconFactory->getIcon('actions-view-page', Icon::SIZE_SMALL)->render() . '</a>'; |
||
184 | $info .= '<a href="' . htmlspecialchars($editUrl) |
||
185 | . '" class="btn btn-default" title="' . $lang->sL( |
||
186 | 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_editDefaultLanguagePage' |
||
187 | ) . '">' . $this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL)->render() . '</a>'; |
||
188 | $info .= ' '; |
||
189 | $info .= GeneralUtility::hideIfDefaultLanguage($data['row']['l18n_cfg']) ? '<span title="' . htmlspecialchars($lang->sL('LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.l18n_cfg.I.1')) . '">D</span>' : ' '; |
||
190 | $info .= GeneralUtility::hideIfNotTranslated($data['row']['l18n_cfg']) ? '<span title="' . htmlspecialchars($lang->sL('LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.l18n_cfg.I.2')) . '">N</span>' : ' '; |
||
191 | // Put into cell: |
||
192 | $tCells[] = '<td class="' . $status . ' col-border-left"><div class="btn-group">' . $info . '</div></td>'; |
||
193 | $tCells[] = '<td class="' . $status . '" title="' . $lang->sL( |
||
194 | 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_CEcount' |
||
195 | ) . '" align="center">' . $this->getContentElementCount($data['row']['uid'], 0) . '</td>'; |
||
196 | $modSharedTSconfig = BackendUtility::getModTSconfig($data['row']['uid'], 'mod.SHARED'); |
||
197 | $disableLanguages = isset($modSharedTSconfig['properties']['disableLanguages']) ? GeneralUtility::trimExplode(',', $modSharedTSconfig['properties']['disableLanguages'], true) : []; |
||
198 | // Traverse system languages: |
||
199 | foreach ($languages as $langRow) { |
||
200 | if ($this->pObj->MOD_SETTINGS['lang'] == 0 || (int)$this->pObj->MOD_SETTINGS['lang'] === (int)$langRow['uid']) { |
||
201 | $row = $this->getLangStatus($data['row']['uid'], $langRow['uid']); |
||
202 | $info = ''; |
||
203 | if (is_array($row)) { |
||
204 | $langRecUids[$langRow['uid']][] = $row['uid']; |
||
205 | $status = $row['_HIDDEN'] ? (GeneralUtility::hideIfNotTranslated($data['row']['l18n_cfg']) || GeneralUtility::hideIfDefaultLanguage($data['row']['l18n_cfg']) ? 'danger' : '') : 'success'; |
||
206 | $icon = $this->iconFactory->getIconForRecord('pages', $row, Icon::SIZE_SMALL)->render(); |
||
207 | $info = $icon . htmlspecialchars( |
||
208 | GeneralUtility::fixed_lgd_cs($row['title'], $titleLen) |
||
209 | ) . ((string)$row['nav_title'] !== '' ? ' [Nav: <em>' . htmlspecialchars( |
||
210 | GeneralUtility::fixed_lgd_cs($row['nav_title'], $titleLen) |
||
211 | ) . '</em>]' : '') . ($row['_COUNT'] > 1 ? '<div>' . $lang->sL( |
||
212 | 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_badThingThereAre' |
||
213 | ) . '</div>' : ''); |
||
214 | $tCells[] = '<td class="' . $status . ' col-border-left">' . |
||
215 | '<a href="#" onclick="' . htmlspecialchars( |
||
216 | 'top.loadEditId(' . (int)$data['row']['uid'] . ',"&SET[language]=' . $langRow['uid'] . '"); return false;' |
||
217 | ) . '" title="' . $lang->sL( |
||
218 | 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_editPageLang' |
||
219 | ) . '">' . $info . '</a></td>'; |
||
220 | // Edit whole record: |
||
221 | // Create links: |
||
222 | $editUrl = (string)$uriBuilder->buildUriFromRoute('record_edit', [ |
||
223 | 'edit' => [ |
||
224 | 'pages' => [ |
||
225 | $row['uid'] => 'edit' |
||
226 | ] |
||
227 | ], |
||
228 | 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI') |
||
229 | ]); |
||
230 | $info = str_replace('###LANG_UID###', $langRow['uid'], $viewPageLink); |
||
231 | $info .= '<a href="' . htmlspecialchars($editUrl) |
||
232 | . '" class="btn btn-default" title="' . $lang->sL( |
||
233 | 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_editLanguageOverlayRecord' |
||
234 | ) . '">' . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>'; |
||
235 | $tCells[] = '<td class="' . $status . '"><div class="btn-group">' . $info . '</div></td>'; |
||
236 | $tCells[] = '<td class="' . $status . '" title="' . $lang->sL( |
||
237 | 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_CEcount' |
||
238 | ) . '" align="center">' . $this->getContentElementCount($data['row']['uid'], $langRow['uid']) . '</td>'; |
||
239 | } else { |
||
240 | if (in_array($langRow['uid'], $disableLanguages)) { |
||
241 | // Language has been disabled for this page |
||
242 | $status = 'danger'; |
||
243 | $info = ''; |
||
244 | } else { |
||
245 | $status = GeneralUtility::hideIfNotTranslated($data['row']['l18n_cfg']) || GeneralUtility::hideIfDefaultLanguage($data['row']['l18n_cfg']) ? 'danger' : ''; |
||
246 | $info = '<div class="btn-group"><label class="btn btn-default btn-checkbox">'; |
||
247 | $info .= '<input type="checkbox" name="newOL[' . $langRow['uid'] . '][' . $data['row']['uid'] . ']" value="1" />'; |
||
248 | $info .= '<span class="t3-icon fa"></span></label></div>'; |
||
249 | $newOL_js[$langRow['uid']] .= ' |
||
250 | +(document.webinfoForm[' |
||
251 | . GeneralUtility::quoteJSvalue('newOL[' . $langRow['uid'] . '][' . $data['row']['uid'] . ']') |
||
252 | . '].checked ? ' |
||
253 | . GeneralUtility::quoteJSvalue('&edit[pages][' . $data['row']['uid'] . ']=new') |
||
254 | . ' : \'\') |
||
255 | '; |
||
256 | } |
||
257 | $tCells[] = '<td class="' . $status . ' col-border-left"> </td>'; |
||
258 | $tCells[] = '<td class="' . $status . '"> </td>'; |
||
259 | $tCells[] = '<td class="' . $status . '">' . $info . '</td>'; |
||
260 | } |
||
261 | } |
||
262 | } |
||
263 | $output .= ' |
||
264 | <tr> |
||
265 | ' . implode(' |
||
266 | ', $tCells) . ' |
||
267 | </tr>'; |
||
268 | } |
||
269 | // Put together HEADER: |
||
270 | $tCells = []; |
||
271 | $tCells[] = '<td>' . $lang->sL('LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_page') . ':</td>'; |
||
272 | if (is_array($langRecUids[0])) { |
||
273 | $editUrl = (string)$uriBuilder->buildUriFromRoute('record_edit', [ |
||
274 | 'edit' => [ |
||
275 | 'pages' => [ |
||
276 | implode(',', $langRecUids[0]) => 'edit' |
||
277 | ] |
||
278 | ], |
||
279 | 'columnsOnly' => 'title,nav_title,l18n_cfg,hidden', |
||
280 | 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI') |
||
281 | ]); |
||
282 | $editIco = '<a href="' . htmlspecialchars($editUrl) |
||
283 | . '" class="btn btn-default" title="' . $lang->sL( |
||
284 | 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_editPageProperties' |
||
285 | ) . '">' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>'; |
||
286 | } else { |
||
287 | $editIco = ''; |
||
288 | } |
||
289 | $tCells[] = '<td class="col-border-left" colspan="2">' . $lang->sL( |
||
290 | 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_default' |
||
291 | ) . ':' . $editIco . '</td>'; |
||
292 | foreach ($languages as $langRow) { |
||
293 | if ($this->pObj->MOD_SETTINGS['lang'] == 0 || (int)$this->pObj->MOD_SETTINGS['lang'] === (int)$langRow['uid']) { |
||
294 | // Title: |
||
295 | $tCells[] = '<td class="col-border-left">' . htmlspecialchars($langRow['title']) . '</td>'; |
||
296 | // Edit language overlay records: |
||
297 | if (is_array($langRecUids[$langRow['uid']])) { |
||
298 | $editUrl = (string)$uriBuilder->buildUriFromRoute('record_edit', [ |
||
299 | 'edit' => [ |
||
300 | 'pages' => [ |
||
301 | implode(',', $langRecUids[$langRow['uid']]) => 'edit' |
||
302 | ] |
||
303 | ], |
||
304 | 'columnsOnly' => 'title,nav_title,hidden', |
||
305 | 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI') |
||
306 | ]); |
||
307 | $editButton = '<a href="' . htmlspecialchars($editUrl) |
||
308 | . '" class="btn btn-default" title="' . $lang->sL( |
||
309 | 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_renderl10n_editLangOverlays' |
||
310 | ) . '">' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>'; |
||
311 | } else { |
||
312 | $editButton = ''; |
||
313 | } |
||
314 | // Create new overlay records: |
||
315 | $params = '&columnsOnly=title,hidden,sys_language_uid&overrideVals[pages][sys_language_uid]=' . $langRow['uid']; |
||
316 | $onClick = BackendUtility::editOnClick($params); |
||
317 | if (!empty($newOL_js[$langRow['uid']])) { |
||
318 | $onClickArray = explode('?', $onClick, 2); |
||
319 | $lastElement = array_pop($onClickArray); |
||
320 | $onClickArray[] = '\'' . $newOL_js[$langRow['uid']] . ' + \'&' . $lastElement; |
||
321 | $onClick = implode('?', $onClickArray); |
||
322 | } |
||
323 | $newButton = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($onClick) |
||
324 | . '" title="' . $lang->sL( |
||
325 | 'LLL:EXT:info/Resources/Private/Language/locallang_webinfo.xlf:lang_getlangsta_createNewTranslationHeaders' |
||
326 | ) . '">' . $this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL)->render() . '</a>'; |
||
327 | |||
328 | $tCells[] = '<td class="btn-group">' . $editButton . $newButton . '</td>'; |
||
329 | $tCells[] = '<td> </td>'; |
||
330 | } |
||
331 | } |
||
332 | |||
333 | $output = |
||
334 | '<div class="table-fit">' . |
||
335 | '<table class="table table-striped table-hover" id="langTable">' . |
||
336 | '<thead>' . |
||
337 | '<tr>' . |
||
338 | implode('', $tCells) . |
||
339 | '</tr>' . |
||
340 | '</thead>' . |
||
341 | '<tbody>' . |
||
342 | $output . |
||
343 | '</tbody>' . |
||
344 | '</table>' . |
||
345 | '</div>'; |
||
346 | return $output; |
||
347 | } |
||
480 |