‪TYPO3CMS  9.5
OpendocsToolbarItem.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
25 
31 {
35  protected ‪$recentDocs = [];
36 
40  protected ‪$documentService;
41 
48  {
49  $this->documentService = ‪$documentService ?: GeneralUtility::makeInstance(OpenDocumentService::class);
50  }
51 
57  public function ‪checkAccess(): bool
58  {
59  return !(bool)($this->‪getBackendUser()->‪getTSConfig()['backendToolbarItem.']['tx_opendocs.']['disabled'] ?? false);
60  }
61 
67  public function ‪getItem()
68  {
69  $view = $this->‪getFluidTemplateObject('ToolbarItem.html');
70 
71  return $view->render();
72  }
73 
79  public function ‪hasDropDown()
80  {
81  return true;
82  }
83 
89  public function ‪getDropDown()
90  {
91  $view = $this->‪getFluidTemplateObject('DropDown.html');
92  $view->assignMultiple([
93  'openDocuments' => $this->‪getMenuEntries($this->documentService->getOpenDocuments()),
94  // If there are "recent documents" in the list, add them
95  'recentDocuments' => $this->getMenuEntries($this->documentService->getRecentDocuments()),
96  ]);
97 
98  return $view->render();
99  }
100 
106  public function ‪getAdditionalAttributes()
107  {
108  return [];
109  }
110 
116  public function ‪getIndex()
117  {
118  return 30;
119  }
120 
127  public function ‪updateNumberOfOpenDocsHook(&$params)
128  {
129  $params['JScode'] = '
130  if (top && top.TYPO3.OpendocsMenu) {
131  top.TYPO3.OpendocsMenu.updateMenu();
132  }
133  ';
134  }
135 
142  protected function ‪getMenuEntries(array $documents): array
143  {
144  $entries = [];
145 
146  foreach ($documents as $identifier => $document) {
147  $menuEntry = $this->‪getMenuEntry($document, $identifier);
148 
149  if (!empty($menuEntry)) {
150  $entries[] = $menuEntry;
151  }
152  }
153 
154  return $entries;
155  }
156 
164  protected function ‪getMenuEntry(array $document, string $identifier): array
165  {
166  $table = $document[3]['table'];
167  $uid = $document[3]['uid'];
168  $record = ‪BackendUtility::getRecordWSOL($table, $uid);
169 
170  if (!is_array($record)) {
171  // Record seems to be deleted
172  return [];
173  }
174 
175  $result = [];
176  $result['table'] = $table;
177  $result['record'] = $record;
178  $result['label'] = htmlspecialchars(strip_tags(htmlspecialchars_decode($document[0])));
180  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
181  $uri = (string)$uriBuilder->buildUriFromRoute('record_edit') . '&' . $document[2];
182  $pid = (int)$document[3]['pid'];
183 
184  if ($document[3]['table'] === 'pages') {
185  $pid = (int)$document[3]['uid'];
186  }
187 
188  $result['onClickCode'] = 'jump(' . GeneralUtility::quoteJSvalue($uri) . ', \'web_list\', \'web\', ' . $pid . '); TYPO3.OpendocsMenu.toggleMenu(); return false;';
189  $result['md5sum'] = $identifier;
190 
191  return $result;
192  }
193 
200  protected function ‪getFluidTemplateObject(string $filename): ‪StandaloneView
201  {
202  $view = GeneralUtility::makeInstance(StandaloneView::class);
203  $view->setLayoutRootPaths(['EXT:opendocs/Resources/Private/Layouts']);
204  $view->setPartialRootPaths([
205  'EXT:backend/Resources/Private/Partials/ToolbarItems',
206  'EXT:opendocs/Resources/Private/Partials/ToolbarItems',
207  ]);
208  $view->setTemplateRootPaths(['EXT:opendocs/Resources/Private/Templates/ToolbarItems']);
209  $view->setTemplate($filename);
210  $view->getRequest()->setControllerExtensionName('Opendocs');
211 
212  return $view;
213  }
214 
218  protected function ‪getBackendUser(): ‪BackendUserAuthentication
219  {
220  return ‪$GLOBALS['BE_USER'];
221  }
222 }
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem
Definition: OpendocsToolbarItem.php:31
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\updateNumberOfOpenDocsHook
‪updateNumberOfOpenDocsHook(&$params)
Definition: OpendocsToolbarItem.php:125
‪TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface
Definition: ToolbarItemInterface.php:24
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\checkAccess
‪bool checkAccess()
Definition: OpendocsToolbarItem.php:55
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems
Definition: OpendocsToolbarItem.php:3
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\$recentDocs
‪array $recentDocs
Definition: OpendocsToolbarItem.php:34
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\__construct
‪__construct(OpenDocumentService $documentService=null)
Definition: OpendocsToolbarItem.php:45
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getTSConfig
‪array getTSConfig($objectString=null, $config=null)
Definition: BackendUserAuthentication.php:1232
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\getIndex
‪int getIndex()
Definition: OpendocsToolbarItem.php:114
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\getDropDown
‪string getDropDown()
Definition: OpendocsToolbarItem.php:87
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\hasDropDown
‪bool hasDropDown()
Definition: OpendocsToolbarItem.php:77
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\getItem
‪string getItem()
Definition: OpendocsToolbarItem.php:65
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\$documentService
‪OpenDocumentService $documentService
Definition: OpendocsToolbarItem.php:38
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\getMenuEntry
‪array getMenuEntry(array $document, string $identifier)
Definition: OpendocsToolbarItem.php:162
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:35
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService
Definition: OpenDocumentService.php:25
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\getFluidTemplateObject
‪StandaloneView getFluidTemplateObject(string $filename)
Definition: OpendocsToolbarItem.php:198
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordWSOL
‪static array getRecordWSOL( $table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)
Definition: BackendUtility.php:174
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:32
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: OpendocsToolbarItem.php:216
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\getMenuEntries
‪array getMenuEntries(array $documents)
Definition: OpendocsToolbarItem.php:140
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\getAdditionalAttributes
‪array getAdditionalAttributes()
Definition: OpendocsToolbarItem.php:104