2 declare(strict_types = 1);
18 use Doctrine\DBAL\Connection;
19 use Psr\Http\Message\ResponseInterface;
20 use Psr\Http\Message\ServerRequestInterface;
51 'getLabelForTableColumn' =>
'Using ElementInformationController::getLabelForTableColumn() is deprecated and will not be possible anymore in TYPO3 v10.0.',
60 'table' =>
'Using $table of class ElementInformationController from the outside is discouraged, as this variable is only used for internal storage.',
61 'uid' =>
'Using $uid of class ElementInformationController from the outside is discouraged, as this variable is only used for internal storage.',
62 'access' =>
'Using $access of class ElementInformationController from the outside is discouraged, as this variable is only used for internal storage.',
63 'type' =>
'Using $type of class ElementInformationController from the outside is discouraged, as this variable is only used for internal storage.',
64 'pageInfo' =>
'Using $pageInfo of class ElementInformationController from the outside is discouraged, as this variable is only used for internal storage.',
140 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
146 $this->
init($request);
156 public function mainAction(ServerRequestInterface $request): ResponseInterface
158 $this->
main($request);
159 return new HtmlResponse($this->moduleTemplate->renderContent());
168 public function init(ServerRequestInterface $request =
null): void
170 if ($request ===
null) {
175 trigger_error(
'ElementInformationController->init() will be set to protected in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
179 $queryParams = $request->getQueryParams();
181 $this->table = $queryParams[
'table'] ??
null;
182 $this->uid = $queryParams[
'uid'] ??
null;
185 $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
186 $this->moduleTemplate->getDocHeaderComponent()->disable();
188 if (isset(
$GLOBALS[
'TCA'][$this->table])) {
190 } elseif ($this->table ===
'_FILE' || $this->table ===
'_FOLDER' || $this->table ===
'sys_file') {
201 $this->uid = (int)$this->uid;
205 if ((
string)$this->table ===
'pages') {
207 $this->access = is_array($this->pageInfo);
213 if (!empty($this->row[
't3ver_oid'])) {
219 $this->access = is_array($this->pageInfo);
232 if ($fileOrFolderObject instanceof Folder) {
233 $this->folderObject = $fileOrFolderObject;
235 $this->type =
'folder';
236 } elseif ($fileOrFolderObject instanceof File) {
237 $this->fileObject = $fileOrFolderObject;
238 $this->access = $this->fileObject->checkActionPermission(
'read');
239 $this->type =
'file';
240 $this->table =
'sys_file';
256 public function main(ServerRequestInterface $request =
null): void
258 if ($request ===
null) {
261 trigger_error(
'ElementInformationController->main() will be set to protected in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
268 $view = GeneralUtility::makeInstance(StandaloneView::class);
269 $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName(
'EXT:backend/Resources/Private/Templates')]);
270 $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName(
'EXT:backend/Resources/Private/Partials')]);
271 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
272 'EXT:backend/Resources/Private/Templates/ContentElement/ElementInformation.html'
277 $typeRendered =
false;
278 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
'typo3/show_item.php'][
'typeRendering'] ?? [] as $className) {
279 $typeRenderObj = GeneralUtility::makeInstance($className);
280 if (is_object($typeRenderObj) && method_exists($typeRenderObj,
'isValid') && method_exists($typeRenderObj,
'render')) {
281 if ($typeRenderObj->isValid($this->type, $this)) {
282 $content .= $typeRenderObj->render($this->type, $this);
283 $typeRendered =
true;
289 if (!$typeRendered) {
290 $view->assign(
'accessAllowed',
true);
295 $view->assign(
'returnUrl', GeneralUtility::sanitizeLocalUrl($request->getQueryParams()[
'returnUrl']));
297 $content .= $view->render();
300 $content .= $view->render();
303 $this->moduleTemplate->setContent($content);
316 if ($this->type ===
'folder') {
317 $pageTitle[
'table'] = $this->
getLanguageService()->
sL(
'LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:folder');
318 $pageTitle[
'icon'] = $this->iconFactory->getIconForResource($this->folderObject,
Icon::SIZE_SMALL)->render();
319 } elseif ($this->type ===
'file') {
321 $pageTitle[
'icon'] = $this->iconFactory->getIconForResource($this->fileObject,
Icon::SIZE_SMALL)->render();
324 $pageTitle[
'icon'] = $this->iconFactory->getIconForRecord($this->table, $this->row,
Icon::SIZE_SMALL);
326 $this->moduleTemplate->setTitle($pageTitle[
'table'] .
': ' . $pageTitle[
'title']);
339 if (!$this->fileObject) {
344 if ($this->fileObject->isMissing()) {
345 $preview[
'missingFile'] = $this->fileObject->getName();
350 $fileExtension = $this->fileObject->getExtension();
351 $preview[
'url'] = $this->fileObject->getPublicUrl(
true);
357 if ($fileRenderer !==
null) {
358 $preview[
'fileRenderer'] = $fileRenderer->render(
367 } elseif (GeneralUtility::inList(
$GLOBALS[
'TYPO3_CONF_VARS'][
'GFX'][
'imagefile_ext'], $fileExtension)) {
369 $preview[
'width'] = $width;
370 $preview[
'heigth'] = $heigth;
383 $propertiesForTable = [];
387 'uid' => htmlspecialchars($lang->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:show_item.php.uid'))
390 if (in_array($this->type, [
'folder',
'file'],
true)) {
391 if ($this->type ===
'file') {
392 $extraFields[
'creation_date'] = htmlspecialchars($lang->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.creationDate'));
393 $extraFields[
'modification_date'] = htmlspecialchars($lang->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.timestamp'));
395 $extraFields[
'width'] = htmlspecialchars($lang->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.width'));
396 $extraFields[
'height'] = htmlspecialchars($lang->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.height'));
399 $extraFields[
'storage'] = htmlspecialchars($lang->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_tca.xlf:sys_file.storage'));
400 $extraFields[
'folder'] = htmlspecialchars($lang->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:folder'));
402 $extraFields[
'crdate'] = htmlspecialchars($lang->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.creationDate'));
403 $extraFields[
'cruser_id'] = htmlspecialchars($lang->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.creationUserId'));
404 $extraFields[
'tstamp'] = htmlspecialchars($lang->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.timestamp'));
407 foreach ($extraFields as $fieldName => $fieldLabel) {
408 if (isset(
$GLOBALS[
'TCA'][$this->table][
'ctrl'][$fieldName])) {
410 } elseif ($fieldName !==
'uid') {
411 unset($extraFields[$fieldName]);
416 foreach ($extraFields as $name => $fieldLabel) {
419 if (!isset($this->row[$name])) {
421 if ($name ===
'storage') {
423 } elseif ($name ===
'folder') {
424 $rowValue = $resourceObject->getParentFolder()->getReadablePath();
425 } elseif ($name ===
'width') {
426 $rowValue = $this->fileObject->getProperty(
'width') .
'px';
427 } elseif ($name ===
'height') {
428 $rowValue = $this->fileObject->getProperty(
'height') .
'px';
430 } elseif ($name ===
'creation_date' || $name ===
'modification_date' || $name ===
'tstamp' || $name ===
'crdate') {
435 $thisRow[
'value'] = $rowValue;
436 $thisRow[
'fieldLabel'] = rtrim($fieldLabel,
':');
438 if ($name ===
'cruser_id' && $rowValue) {
440 if ($creatorRecord) {
442 $avatar = GeneralUtility::makeInstance(Avatar::class);
443 $creatorRecord[
'icon'] = $avatar->render($creatorRecord);
444 $thisRow[
'creatorRecord'] = $creatorRecord;
445 $thisRow[
'value'] =
'';
448 $propertiesForTable[
'extraFields'][] = $thisRow;
452 $fieldList = GeneralUtility::trimExplode(
',',
$GLOBALS[
'TCA'][$this->table][
'interface'][
'showRecordFieldList'],
true);
453 foreach ($fieldList as $name) {
456 $uid = $this->row[
'uid'];
458 if (!isset(
$GLOBALS[
'TCA'][$this->table][
'columns'][$name])) {
463 if ($this->type ===
'file' && $name ===
'storage') {
468 if ($this->type ===
'file' && $name ===
'size') {
469 $this->row[$name] = GeneralUtility::formatSize($this->row[$name], htmlspecialchars($this->
getLanguageService()->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:byteSizeUnits')));
479 $propertiesForTable[
'fields'][] = $thisRow;
481 return $propertiesForTable;
490 protected function getReferences(ServerRequestInterface $request): array
493 switch ($this->type) {
495 $references[
'refLines'] = $this->
makeRef($this->table, $this->row[
'uid'], $request);
496 $references[
'refFromLines'] = $this->
makeRefFrom($this->table, $this->row[
'uid'], $request);
501 if ($this->fileObject && $this->fileObject->isIndexed()) {
502 $references[
'refLines'] = $this->
makeRef(
'_FILE', $this->fileObject, $request);
519 if (
$GLOBALS[
'TCA'][$tableName][
'columns'][$fieldName][
'label'] !==
null) {
521 if (trim($field) ===
'') {
552 'returnUrl' => $request->getAttribute(
'normalizedParams')->getRequestUri()
555 $uriBuilder = GeneralUtility::makeInstance(\
TYPO3\CMS\Backend\Routing\UriBuilder::class);
556 $actions[
'recordEditUrl'] = (string)$uriBuilder->buildUriFromRoute(
'record_edit', $urlParameters);
561 'returnUrl' => $request->getAttribute(
'normalizedParams')->getRequestUri()
563 $actions[
'recordHistoryUrl'] = (string)$uriBuilder->buildUriFromRoute(
'record_history', $urlParameters);
567 $actions[
'webListUrl'] = (string)$uriBuilder->buildUriFromRoute(
'web_list', [
'id' =>
$uid,
'returnUrl' => $request->getAttribute(
'normalizedParams')->getRequestUri()]);
584 protected function makeRef(
$table, $ref, ServerRequestInterface $request)
590 $selectTable =
'sys_file';
591 $selectUid = $ref->getUid();
597 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
598 ->getQueryBuilderForTable(
'sys_refindex');
601 $queryBuilder->expr()->eq(
603 $queryBuilder->createNamedParameter($selectTable, \PDO::PARAM_STR)
605 $queryBuilder->expr()->eq(
607 $queryBuilder->createNamedParameter($selectUid, \PDO::PARAM_INT)
609 $queryBuilder->expr()->eq(
611 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
616 if (!$backendUser->isAdmin()) {
617 $allowedSelectTables = GeneralUtility::trimExplode(
',', $backendUser->groupData[
'tables_select']);
618 $predicates[] = $queryBuilder->expr()->in(
620 $queryBuilder->createNamedParameter($allowedSelectTables, Connection::PARAM_STR_ARRAY)
624 $rows = $queryBuilder
626 ->from(
'sys_refindex')
627 ->where(...$predicates)
632 foreach ($rows as
$row) {
633 if (
$row[
'tablename'] ===
'sys_file_reference') {
635 if (
$row[
'tablename'] ===
null ||
$row[
'recuid'] ===
null) {
648 $parentRecordTitle = is_array($parentRecord)
653 $row[
'tablename'] => [
654 $row[
'recuid'] =>
'edit'
657 'returnUrl' => $request->getAttribute(
'normalizedParams')->getRequestUri()
660 $uriBuilder = GeneralUtility::makeInstance(\
TYPO3\CMS\Backend\Routing\UriBuilder::class);
661 $url = (string)$uriBuilder->buildUriFromRoute(
'record_edit', $urlParameters);
663 $line[
'icon'] = $this->iconFactory->getIconForRecord(
$row[
'tablename'], $record,
Icon::SIZE_SMALL)->render();
664 $line[
'row'] =
$row;
665 $line[
'record'] = $record;
667 $line[
'parentRecordTitle'] = $parentRecordTitle;
668 $line[
'title'] = $lang->sL(
$GLOBALS[
'TCA'][
$row[
'tablename']][
'ctrl'][
'title']);
673 $line[
'row'] =
$row;
674 $line[
'title'] = $lang->sL(
$GLOBALS[
'TCA'][
$row[
'tablename']][
'ctrl'][
'title']) ?:
$row[
'tablename'];
696 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
697 ->getQueryBuilderForTable(
'sys_refindex');
700 $queryBuilder->expr()->eq(
702 $queryBuilder->createNamedParameter(
$table, \PDO::PARAM_STR)
704 $queryBuilder->expr()->eq(
706 $queryBuilder->createNamedParameter($ref, \PDO::PARAM_INT)
711 if (!$backendUser->isAdmin()) {
712 $allowedSelectTables = GeneralUtility::trimExplode(
',', $backendUser->groupData[
'tables_select']);
713 $predicates[] = $queryBuilder->expr()->in(
715 $queryBuilder->createNamedParameter($allowedSelectTables, Connection::PARAM_STR_ARRAY)
719 $rows = $queryBuilder
721 ->from(
'sys_refindex')
722 ->where(...$predicates)
727 foreach ($rows as
$row) {
737 $row[
'ref_table'] => [
738 $row[
'ref_uid'] =>
'edit'
741 'returnUrl' => $request->getAttribute(
'normalizedParams')->getRequestUri()
744 $uriBuilder = GeneralUtility::makeInstance(\
TYPO3\CMS\Backend\Routing\UriBuilder::class);
745 $url = (string)$uriBuilder->buildUriFromRoute(
'record_edit', $urlParameters);
747 $line[
'icon'] = $this->iconFactory->getIconForRecord(
$row[
'tablename'], $record,
Icon::SIZE_SMALL)->render();
748 $line[
'row'] =
$row;
749 $line[
'record'] = $record;
751 $line[
'title'] = $lang->sL(
$GLOBALS[
'TCA'][
$row[
'ref_table']][
'ctrl'][
'title']);
757 $line[
'title'] = $lang->sL(
$GLOBALS[
'TCA'][
$row[
'ref_table']][
'ctrl'][
'title']);
760 $refFromLines[] = $line;
762 return $refFromLines;
774 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
775 ->getQueryBuilderForTable(
'sys_file_reference');
776 $queryBuilder->getRestrictions()->removeAll();
777 $fileReference = $queryBuilder
779 ->from(
'sys_file_reference')
781 $queryBuilder->expr()->eq(
783 $queryBuilder->createNamedParameter($referenceRecord[
'recuid'], \PDO::PARAM_INT)
790 'recuid' => $fileReference[
'uid_foreign'],
791 'tablename' => $fileReference[
'tablenames'],
792 'field' => $fileReference[
'fieldname'],
795 'sorting' => $fileReference[
'sorting_foreign']
804 protected function canAccessPage(
string $tableName, array $record): bool
806 $recordPid = (int)($tableName ===
'pages' ? $record[
'uid'] : $record[
'pid']);
808 || $recordPid === 0 && !empty(
$GLOBALS[
'TCA'][$tableName][
'ctrl'][
'security'][
'ignoreRootLevelRestriction']);