‪TYPO3CMS  10.4
OpendocsToolbarItem.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
27 
33 {
37  protected ‪$documentService;
38 
45  {
46  $this->documentService = ‪$documentService ?: GeneralUtility::makeInstance(OpenDocumentService::class);
47  }
48 
54  public function ‪checkAccess(): bool
55  {
56  return !(bool)($this->‪getBackendUser()->‪getTSConfig()['backendToolbarItem.']['tx_opendocs.']['disabled'] ?? false);
57  }
58 
64  public function ‪getItem()
65  {
66  $view = $this->‪getFluidTemplateObject('ToolbarItem.html');
67 
68  return $view->render();
69  }
70 
76  public function ‪hasDropDown()
77  {
78  return true;
79  }
80 
86  public function ‪getDropDown()
87  {
88  $view = $this->‪getFluidTemplateObject('DropDown.html');
89  $view->assignMultiple([
90  'openDocuments' => $this->‪getMenuEntries($this->documentService->getOpenDocuments()),
91  // If there are "recent documents" in the list, add them
92  'recentDocuments' => $this->getMenuEntries($this->documentService->getRecentDocuments()),
93  ]);
94 
95  return $view->render();
96  }
97 
103  public function ‪getAdditionalAttributes()
104  {
105  return [];
106  }
107 
113  public function ‪getIndex()
114  {
115  return 30;
116  }
117 
124  public function ‪updateNumberOfOpenDocsHook(&$params)
125  {
126  $params['JScode'] = '
127  if (top && top.TYPO3.OpendocsMenu) {
128  top.TYPO3.OpendocsMenu.updateMenu();
129  }
130  ';
131  }
132 
139  protected function ‪getMenuEntries(array $documents): array
140  {
141  $entries = [];
142 
143  foreach ($documents as $identifier => $document) {
144  $menuEntry = $this->‪getMenuEntry($document, $identifier);
145 
146  if (!empty($menuEntry)) {
147  $entries[] = $menuEntry;
148  }
149  }
150 
151  return $entries;
152  }
153 
161  protected function ‪getMenuEntry(array $document, string $identifier): array
162  {
163  $table = $document[3]['table'];
164  $uid = $document[3]['uid'];
165  $record = ‪BackendUtility::getRecordWSOL($table, $uid);
166 
167  if (!is_array($record)) {
168  // Record seems to be deleted
169  return [];
170  }
171 
172  $result = [];
173  $result['table'] = $table;
174  $result['record'] = $record;
175  $result['label'] = strip_tags(htmlspecialchars_decode($document[0]));
177  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
178  $uri = (string)$uriBuilder->buildUriFromRoute('record_edit') . '&' . $document[2];
179  $pid = (int)$document[3]['pid'];
180 
181  if ($document[3]['table'] === 'pages') {
182  $pid = (int)$document[3]['uid'];
183  }
184 
185  $result['pid'] = $pid;
186  $result['uri'] = $uri;
187  $result['md5sum'] = $identifier;
188 
189  return $result;
190  }
191 
198  protected function ‪getFluidTemplateObject(string $filename): ‪StandaloneView
199  {
200  $view = GeneralUtility::makeInstance(StandaloneView::class);
201  $view->setLayoutRootPaths(['EXT:opendocs/Resources/Private/Layouts']);
202  $view->setPartialRootPaths([
203  'EXT:backend/Resources/Private/Partials/ToolbarItems',
204  'EXT:opendocs/Resources/Private/Partials/ToolbarItems',
205  ]);
206  $view->setTemplateRootPaths(['EXT:opendocs/Resources/Private/Templates/ToolbarItems']);
207  $view->setTemplate($filename);
208  $view->getRequest()->setControllerExtensionName('Opendocs');
209 
210  return $view;
211  }
212 
216  protected function ‪getBackendUser(): ‪BackendUserAuthentication
217  {
218  return ‪$GLOBALS['BE_USER'];
219  }
220 }
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem
Definition: OpendocsToolbarItem.php:33
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\updateNumberOfOpenDocsHook
‪updateNumberOfOpenDocsHook(&$params)
Definition: OpendocsToolbarItem.php:123
‪TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface
Definition: ToolbarItemInterface.php:25
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\checkAccess
‪bool checkAccess()
Definition: OpendocsToolbarItem.php:53
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems
Definition: OpendocsToolbarItem.php:18
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\__construct
‪__construct(OpenDocumentService $documentService=null)
Definition: OpendocsToolbarItem.php:43
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getTSConfig
‪array getTSConfig()
Definition: BackendUserAuthentication.php:1217
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\getIndex
‪int getIndex()
Definition: OpendocsToolbarItem.php:112
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\getDropDown
‪string getDropDown()
Definition: OpendocsToolbarItem.php:85
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\hasDropDown
‪bool hasDropDown()
Definition: OpendocsToolbarItem.php:75
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\getItem
‪string getItem()
Definition: OpendocsToolbarItem.php:63
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\$documentService
‪OpenDocumentService $documentService
Definition: OpendocsToolbarItem.php:36
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\getMenuEntry
‪array getMenuEntry(array $document, string $identifier)
Definition: OpendocsToolbarItem.php:160
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService
Definition: OpenDocumentService.php:27
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\getFluidTemplateObject
‪StandaloneView getFluidTemplateObject(string $filename)
Definition: OpendocsToolbarItem.php:197
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordWSOL
‪static array getRecordWSOL( $table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)
Definition: BackendUtility.php:139
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:34
‪$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:215
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\getMenuEntries
‪array getMenuEntries(array $documents)
Definition: OpendocsToolbarItem.php:138
‪TYPO3\CMS\Opendocs\Backend\ToolbarItems\OpendocsToolbarItem\getAdditionalAttributes
‪array getAdditionalAttributes()
Definition: OpendocsToolbarItem.php:102