OuterWrapContainer.php 7.57 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
namespace TYPO3\CMS\Backend\Form\Container;

/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

17
use TYPO3\CMS\Backend\Utility\BackendUtility;
18
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
19
20
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
21
use TYPO3\CMS\Core\Localization\LanguageService;
22
use TYPO3\CMS\Core\Type\Bitmask\Permission;
23
use TYPO3\CMS\Core\Utility\GeneralUtility;
24
use TYPO3\CMS\Fluid\View\StandaloneView;
25
26
27
28
29
30
31
32
33

/**
 * Render header and footer row.
 *
 * This is an entry container called from controllers.
 * It wraps the title and a footer around the main html.
 * It either calls a FullRecordContainer or ListOfFieldsContainer to render
 * a full record or only some fields from a full record.
 */
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class OuterWrapContainer extends AbstractContainer
{
    /**
     * Entry method
     *
     * @return array As defined in initializeResultArray() of AbstractNode
     */
    public function render()
    {
        $languageService = $this->getLanguageService();
        $backendUser = $this->getBackendUserAuthentication();

        $table = $this->data['tableName'];
        $row = $this->data['databaseRow'];

        $options = $this->data;
        if (empty($this->data['fieldListToRender'])) {
            $options['renderType'] = 'fullRecordContainer';
        } else {
            $options['renderType'] = 'listOfFieldsContainer';
        }
        $result = $this->nodeFactory->create($options)->render();

        $childHtml = $result['html'];

        $recordPath = '';
        // @todo: what is this >= 0 check for? wsol cases?!
        if ($this->data['effectivePid'] >= 0) {
62
            $permissionsClause = $backendUser->getPagePermsClause(Permission::PAGE_SHOW);
63
64
65
66
67
68
69
70
71
72
            $recordPath = BackendUtility::getRecordPath($this->data['effectivePid'], $permissionsClause, 15);
        }

        $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
        $icon = '<span title="' . htmlspecialchars($recordPath) . '">' . $iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render() . '</span>';

        // @todo: Could this be done in a more clever way? Does it work at all?
        $tableTitle = $languageService->sL($this->data['processedTca']['ctrl']['title']);

        if ($this->data['command'] === 'new') {
73
            $newOrUid = ' <span class="typo3-TCEforms-newToken">' . htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.new')) . '</span>';
74
75
76
77
78

            // @todo: There is quite some stuff do to for WS overlays ...
            $workspacedPageRecord = BackendUtility::getRecordWSOL('pages', $this->data['effectivePid'], 'title');
            $pageTitle = BackendUtility::getRecordTitle('pages', $workspacedPageRecord, true, false);
            if ($table === 'pages') {
79
                $label = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.createNewPage'));
80
81
                $pageTitle = sprintf($label, $tableTitle);
            } else {
82
                $label = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.createNewRecord'));
83
                if ($this->data['effectivePid'] === 0) {
84
                    $label = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.createNewRecordRootLevel'));
85
86
87
88
                }
                $pageTitle = sprintf($label, $tableTitle, $pageTitle);
            }
        } else {
89
            $icon = BackendUtility::wrapClickMenuOnIcon($icon, $table, $row['uid']);
90
91
92
93
94
            $newOrUid = ' <span class="typo3-TCEforms-recUid">[' . htmlspecialchars($row['uid']) . ']</span>';

            // @todo: getRecordTitlePrep applies an htmlspecialchars here
            $recordLabel = BackendUtility::getRecordTitlePrep($this->data['recordTitle']);
            if ($table === 'pages') {
95
                $label = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.editPage'));
96
97
                $pageTitle = sprintf($label, $tableTitle, $recordLabel);
            } else {
98
                $label = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.editRecord'));
99
100
101
                $workspacedPageRecord = BackendUtility::getRecordWSOL('pages', $row['pid'], 'uid,title');
                $pageTitle = BackendUtility::getRecordTitle('pages', $workspacedPageRecord, true, false);
                if (empty($recordLabel)) {
102
                    $label = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.editRecordNoTitle'));
103
104
                }
                if ($this->data['effectivePid'] === 0) {
105
                    $label = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.editRecordRootLevel'));
106
107
108
109
110
111
112
113
114
115
116
                }
                if (!empty($recordLabel)) {
                    // Use record title and prepend an edit label.
                    $pageTitle = sprintf($label, $tableTitle, $recordLabel, $pageTitle);
                } else {
                    // Leave out the record title since it is not set.
                    $pageTitle = sprintf($label, $tableTitle, $pageTitle);
                }
            }
        }

117
118
119
120
121
122
123
124
        $view = GeneralUtility::makeInstance(StandaloneView::class);
        $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
            'EXT:backend/Resources/Private/Templates/OuterWrapContainer.html'
        ));

        $descriptionColumn = !empty($this->data['processedTca']['ctrl']['descriptionColumn'])
            ? $this->data['processedTca']['ctrl']['descriptionColumn'] : null;
        if ($descriptionColumn !== null) {
125
            $title = $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.recordInformation');
126
127
128
129
130
131
            $content = $this->data['databaseRow'][$descriptionColumn];
            $view->assignMultiple([
                'infoBoxMessageTitle' => $title,
                'infoBoxMessage' => $content
            ]);
        }
132

133
134
135
136
        $fieldInformationResult = $this->renderFieldInformation();
        $fieldInformationHtml = $fieldInformationResult['html'];
        $result = $this->mergeChildReturnIntoExistingResult($result, $fieldInformationResult, false);

137
        $fieldWizardResult = $this->renderFieldWizard();
138
139
140
        $fieldWizardHtml = $fieldWizardResult['html'];
        $result = $this->mergeChildReturnIntoExistingResult($result, $fieldWizardResult, false);

141
        $view->assignMultiple([
142
            'pageTitle' => $pageTitle,
143
144
            'fieldInformationHtml' => $fieldInformationHtml,
            'fieldWizardHtml' => $fieldWizardHtml,
145
146
147
148
            'childHtml' => $childHtml,
            'icon' => $icon,
            'tableTitle' => $tableTitle,
            'newOrUid' => $newOrUid
149
        ]);
150
        $result['html'] = $view->render();
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
        return $result;
    }

    /**
     * @return LanguageService
     */
    protected function getLanguageService()
    {
        return $GLOBALS['LANG'];
    }

    /**
     * @return BackendUserAuthentication
     */
    protected function getBackendUserAuthentication()
    {
        return $GLOBALS['BE_USER'];
    }
169
}