‪TYPO3CMS  9.5
EditToolbarService.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
32 
39 {
40 
46  public function ‪createToolbar(): string
47  {
49  $languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
50  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
51  $tsfe = $this->‪getTypoScriptFrontendController();
52  // If mod.newContentElementWizard.override is set, use that extension's create new content wizard instead:
53  $moduleName = ‪BackendUtility::getPagesTSconfig($tsfe->page['uid'])['mod.']['newContentElementWizard.']['override'] ?? 'new_content_element';
54  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
55  $perms = $this->‪getBackendUser()->‪calcPerms($tsfe->page);
56  $langAllowed = $this->‪getBackendUser()->‪checkLanguageAccess($languageAspect->getId());
57  $id = $tsfe->id;
58  $returnUrl = GeneralUtility::getIndpEnv('REQUEST_URI');
59  $classes = 'typo3-adminPanel-btn typo3-adminPanel-btn-default';
60  ‪$output = [];
61  ‪$output[] = '<div class="typo3-adminPanel-form-group">';
62  ‪$output[] = ' <div class="typo3-adminPanel-btn-group" role="group">';
63 
64  // History
65  $link = (string)$uriBuilder->buildUriFromRoute(
66  'record_history',
67  [
68  'element' => 'pages:' . $id,
69  'returnUrl' => $returnUrl,
70  ]
71  );
72  $title = $this->‪getLabel('edit_recordHistory');
73  ‪$output[] = '<a class="' .
74  $classes .
75  '" href="' .
76  htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) .
77  '#latest" title="' .
78  $title .
79  '">';
80  ‪$output[] = ' ' . $iconFactory->getIcon('actions-document-history-open', ‪Icon::SIZE_SMALL)->render();
81  ‪$output[] = '</a>';
82 
83  // New Content
84  if ($perms & ‪Permission::CONTENT_EDIT && $langAllowed) {
85  $linkParameters = [
86  'id' => $id,
87  'returnUrl' => $returnUrl,
88  ];
89  if (!empty($languageAspect->getId())) {
90  $linkParameters['sys_language_uid'] = $languageAspect->getId();
91  }
92  $link = (string)$uriBuilder->buildUriFromRoute($moduleName, $linkParameters);
93  $icon = $iconFactory->getIcon('actions-add', ‪Icon::SIZE_SMALL)->render();
94  $title = $this->‪getLabel('edit_newContentElement');
95  ‪$output[] = '<a class="' .
96  $classes .
97  '" href="' .
98  htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) .
99  '" title="' .
100  $title .
101  '">';
102  ‪$output[] = ' ' . $icon;
103  ‪$output[] = '</a>';
104  }
105 
106  // Move Page
107  if ($perms & ‪Permission::PAGE_EDIT) {
108  $link = (string)$uriBuilder->buildUriFromRoute(
109  'move_element',
110  [
111  'table' => 'pages',
112  'uid' => $id,
113  'returnUrl' => $returnUrl,
114  ]
115  );
116  $icon = $iconFactory->getIcon('actions-document-move', ‪Icon::SIZE_SMALL)->render();
117  $title = $this->‪getLabel('edit_move_page');
118  ‪$output[] = '<a class="' .
119  $classes .
120  '" href="' .
121  htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) .
122  '" title="' .
123  $title .
124  '">';
125  ‪$output[] = ' ' . $icon;
126  ‪$output[] = '</a>';
127  }
128 
129  // New Page
130  if ($perms & ‪Permission::PAGE_NEW) {
131  $link = (string)$uriBuilder->buildUriFromRoute(
132  'db_new',
133  [
134  'id' => $id,
135  'pagesOnly' => 1,
136  'returnUrl' => $returnUrl,
137  ]
138  );
139  $icon = $iconFactory->getIcon('actions-page-new', ‪Icon::SIZE_SMALL)->render();
140  $title = $this->‪getLabel('edit_newPage');
141  ‪$output[] = '<a class="' .
142  $classes .
143  '" href="' .
144  htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) .
145  '" title="' .
146  $title .
147  '">';
148  ‪$output[] = ' ' . $icon;
149  ‪$output[] = '</a>';
150  }
151 
152  // Edit Page
153  if ($perms & ‪Permission::PAGE_EDIT) {
154  $link = (string)$uriBuilder->buildUriFromRoute(
155  'record_edit',
156  [
157  'edit[pages][' . $id . ']' => 'edit',
158  'noView' => 1,
159  'returnUrl' => $returnUrl,
160  ]
161  );
162  $icon = $iconFactory->getIcon('actions-page-open', ‪Icon::SIZE_SMALL)->render();
163  $title = $this->‪getLabel('edit_editPageProperties');
164  ‪$output[] = '<a class="' .
165  $classes .
166  '" href="' .
167  htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) .
168  '" title="' .
169  $title .
170  '">';
171  ‪$output[] = ' ' . $icon;
172  ‪$output[] = '</a>';
173  }
174 
175  // Edit Page Overlay
176  if ($perms & ‪Permission::PAGE_EDIT && $languageAspect->getId() > 0 && $langAllowed) {
177  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
178  ->getQueryBuilderForTable('pages');
179  $queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));
180  $row = $queryBuilder
181  ->select('uid', 'pid', 't3ver_state')
182  ->from('pages')
183  ->where(
184  $queryBuilder->expr()->eq(
185  ‪$GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'],
186  $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)
187  ),
188  $queryBuilder->expr()->eq(
189  ‪$GLOBALS['TCA']['pages']['ctrl']['languageField'],
190  $queryBuilder->createNamedParameter($languageAspect->getId(), \PDO::PARAM_INT)
191  )
192  )
193  ->setMaxResults(1)
194  ->execute()
195  ->fetch();
196  $tsfe->sys_page->versionOL('pages', $row);
197  if (is_array($row)) {
198  $link = (string)$uriBuilder->buildUriFromRoute(
199  'record_edit',
200  [
201  'edit[pages][' . $row['uid'] . ']' => 'edit',
202  'noView' => 1,
203  'returnUrl' => $returnUrl,
204  ]
205  );
206  $icon = $iconFactory->getIcon('mimetypes-x-content-page-language-overlay', ‪Icon::SIZE_SMALL)
207  ->render();
208  $title = $this->‪getLabel('edit_editPageOverlay');
209  ‪$output[] = '<a class="' .
210  $classes .
211  '" href="' .
212  htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) .
213  '" title="' .
214  $title .
215  '">';
216  ‪$output[] = ' ' . $icon;
217  ‪$output[] = '</a>';
218  }
219  }
220 
221  // Open list view
222  if ($this->‪getBackendUser()->check('modules', 'web_list')) {
223  $link = (string)$uriBuilder->buildUriFromRoute(
224  'web_list',
225  [
226  'id' => $id,
227  'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'),
228  ]
229  );
230  $icon = $iconFactory->getIcon('actions-system-list-open', ‪Icon::SIZE_SMALL)->render();
231  $title = $this->‪getLabel('edit_db_list');
232  ‪$output[] = '<a class="' .
233  $classes .
234  '" href="' .
235  htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) .
236  '" title="' .
237  $title .
238  '">';
239  ‪$output[] = ' ' . $icon;
240  ‪$output[] = '</a>';
241  }
242 
243  ‪$output[] = ' </div>';
244  ‪$output[] = '</div>';
245  return implode('', ‪$output);
246  }
247 
254  protected function ‪getLabel($key): ?string
255  {
256  return htmlspecialchars($this->‪getLanguageService()->getLL($key), ENT_QUOTES | ENT_HTML5);
257  }
258 
263  {
264  return ‪$GLOBALS['BE_USER'];
265  }
266 
271  {
272  return ‪$GLOBALS['LANG'];
273  }
274 
279  {
280  return ‪$GLOBALS['TSFE'];
281  }
282 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:29
‪TYPO3\CMS\Adminpanel\Service\EditToolbarService
Definition: EditToolbarService.php:39
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_NEW
‪const PAGE_NEW
Definition: Permission.php:47
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication
Definition: FrontendBackendUserAuthentication.php:35
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\calcPerms
‪int calcPerms($row)
Definition: BackendUserAuthentication.php:592
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:31
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:49
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:23
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:35
‪TYPO3\CMS\Adminpanel\Service
Definition: ConfigurationService.php:4
‪TYPO3\CMS\Adminpanel\Service\EditToolbarService\getBackendUser
‪FrontendBackendUserAuthentication getBackendUser()
Definition: EditToolbarService.php:262
‪TYPO3\CMS\Adminpanel\Service\EditToolbarService\createToolbar
‪string createToolbar()
Definition: EditToolbarService.php:46
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\checkLanguageAccess
‪bool checkLanguageAccess($langValue)
Definition: BackendUserAuthentication.php:733
‪TYPO3\CMS\Core\Context\LanguageAspect
Definition: LanguageAspect.php:55
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪$output
‪$output
Definition: annotationChecker.php:113
‪TYPO3\CMS\Adminpanel\Service\EditToolbarService\getTypoScriptFrontendController
‪TypoScriptFrontendController getTypoScriptFrontendController()
Definition: EditToolbarService.php:278
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:97
‪TYPO3\CMS\Core\Type\Bitmask\Permission\CONTENT_EDIT
‪const CONTENT_EDIT
Definition: Permission.php:52
‪TYPO3\CMS\Backend\Utility\BackendUtility\getPagesTSconfig
‪static array getPagesTSconfig($id, $rootLine=null, $returnPartArray=false)
Definition: BackendUtility.php:864
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_EDIT
‪const PAGE_EDIT
Definition: Permission.php:37
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer
Definition: FrontendRestrictionContainer.php:29
‪TYPO3\CMS\Adminpanel\Service\EditToolbarService\getLanguageService
‪LanguageService getLanguageService()
Definition: EditToolbarService.php:270
‪TYPO3\CMS\Adminpanel\Service\EditToolbarService\getLabel
‪string getLabel($key)
Definition: EditToolbarService.php:254