diff --git a/typo3/sysext/opendocs/Classes/Backend/ToolbarItems/OpendocsToolbarItem.php b/typo3/sysext/opendocs/Classes/Backend/ToolbarItems/OpendocsToolbarItem.php index cf8246804f809f7c108909fa034f97f0eee3ae61..74e3fd97e74f2f37b94706f72b1fb6c1780b990f 100644 --- a/typo3/sysext/opendocs/Classes/Backend/ToolbarItems/OpendocsToolbarItem.php +++ b/typo3/sysext/opendocs/Classes/Backend/ToolbarItems/OpendocsToolbarItem.php @@ -18,10 +18,8 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface; use TYPO3\CMS\Backend\Utility\BackendUtility; -use TYPO3\CMS\Core\Imaging\Icon; -use TYPO3\CMS\Core\Imaging\IconFactory; -use TYPO3\CMS\Core\Page\PageRenderer; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Fluid\View\StandaloneView; /** * Alist of all open documents @@ -38,21 +36,12 @@ class OpendocsToolbarItem implements ToolbarItemInterface */ protected $recentDocs; - /** - * @var IconFactory - */ - protected $iconFactory; - /** * Constructor */ public function __construct() { - $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class); - $this->getLanguageService()->includeLLFile('EXT:opendocs/Resources/Private/Language/locallang.xlf'); $this->loadDocsFromUserSession(); - $pageRenderer = $this->getPageRenderer(); - $pageRenderer->loadRequireJsModule('TYPO3/CMS/Opendocs/Toolbar/OpendocsMenu'); } /** @@ -74,8 +63,8 @@ class OpendocsToolbarItem implements ToolbarItemInterface public function loadDocsFromUserSession() { $backendUser = $this->getBackendUser(); - list($this->openDocs, ) = $backendUser->getModuleData('FormEngine', 'ses'); - $this->recentDocs = $backendUser->getModuleData('opendocs::recent'); + list($this->openDocs, ) = $backendUser->getModuleData('FormEngine', 'ses') ?: []; + $this->recentDocs = $backendUser->getModuleData('opendocs::recent') ?: []; } /** @@ -85,14 +74,13 @@ class OpendocsToolbarItem implements ToolbarItemInterface */ public function getItem() { - $numDocs = count($this->openDocs); - $title = htmlspecialchars($this->getLanguageService()->getLL('toolbaritem')); - $icon = $this->iconFactory->getIcon('apps-toolbar-menu-opendocs', Icon::SIZE_SMALL)->render('inline'); - return ' - <span class="toolbar-item-icon" title="' . $title . '">' . $icon . '</span> - <span class="toolbar-item-title">' . $title . '</span> - <span class="toolbar-item-badge badge" id="tx-opendocs-counter">' . $numDocs . '</span> - '; + // Rendering of the output via fluid + $view = GeneralUtility::makeInstance(StandaloneView::class); + $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName( + 'EXT:opendocs/Resources/Private/Templates/ToolbarItem.html' + )); + $view->assign('numDocs', count($this->openDocs)); + return $view->render(); } /** @@ -102,60 +90,48 @@ class OpendocsToolbarItem implements ToolbarItemInterface */ public function getDropDown() { - $languageService = $this->getLanguageService(); + $assigns = []; $openDocuments = $this->openDocs; $recentDocuments = $this->recentDocs; - $entries = []; + $assigns['openDocuments'] = $this->getMenuEntries($openDocuments); + // If there are "recent documents" in the list, add them + $assigns['recentDocuments'] = $this->getMenuEntries($recentDocuments); - $entries[] = '<h3 class="dropdown-headline">'; - $entries[] = htmlspecialchars($this->getLanguageService()->getLL('toolbaritem')); - $entries[] = '</h3>'; - $entries[] = '<hr>'; + // Rendering of the output via fluid + $view = GeneralUtility::makeInstance(StandaloneView::class); + $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName( + 'EXT:opendocs/Resources/Private/Templates/DropDown.html' + )); + $view->assignMultiple($assigns); + return $view->render(); + } - if (!empty($openDocuments)) { - $entries[] = '<h3 class="dropdown-headline">'; - $entries[] = htmlspecialchars($languageService->getLL('open_docs')); - $entries[] = '</h3>'; - $entries[] = '<div class="dropdown-table">'; - $i = 0; - foreach ($openDocuments as $md5sum => $openDocument) { - $i++; - $entries[] = $this->renderMenuEntry($openDocument, $md5sum, false, $i == 1); - } - $entries[] = '</div>'; - $entries[] = '<hr>'; - } - // If there are "recent documents" in the list, add them - if (!empty($recentDocuments)) { - $entries[] = '<h3 class="dropdown-headline">'; - $entries[] = htmlspecialchars($languageService->getLL('recent_docs')); - $entries[] = '</h3>'; - $entries[] = '<div class="dropdown-table">'; - $i = 0; - foreach ($recentDocuments as $md5sum => $recentDocument) { - $i++; - $entries[] = $this->renderMenuEntry($recentDocument, $md5sum, true, $i == 1); + /** + * Get menu entries for all eligible records + * + * @param $documents + * @return array + */ + protected function getMenuEntries(array $documents) : array + { + $entries = []; + foreach ($documents as $md5sum => $recentDocument) { + $menuEntry = $this->getMenuEntry($recentDocument, $md5sum); + if ($menuEntry !== '') { + $entries[] = $menuEntry; } - $entries[] = '</div>'; } - if (!empty($entries)) { - $content = implode('', $entries); - } else { - $content = '<p>' . htmlspecialchars($languageService->getLL('no_docs')) . '</p>'; - } - return $content; + return $entries; } /** - * Returns the recent documents list as an array + * Returns the data for a recent or open document * * @param array $document * @param string $md5sum - * @param bool $isRecentDoc - * @param bool $isFirstDoc - * @return array All recent documents as list-items + * @return array The data of a recent or closed document */ - protected function renderMenuEntry($document, $md5sum, $isRecentDoc = false, $isFirstDoc = false) + protected function getMenuEntry($document, $md5sum) { $table = $document[3]['table']; $uid = $document[3]['uid']; @@ -164,46 +140,20 @@ class OpendocsToolbarItem implements ToolbarItemInterface // Record seems to be deleted return ''; } + $result = []; + $result['table'] = $table; + $result['record'] = $record; $label = htmlspecialchars(strip_tags(htmlspecialchars_decode($document[0]))); - $icon = $this->iconFactory->getIconForRecord($table, $record, Icon::SIZE_SMALL)->render(); + $result['label'] = $label; $link = BackendUtility::getModuleUrl('record_edit') . '&' . $document[2]; $pageId = (int)$document[3]['uid']; if ($document[3]['table'] !== 'pages') { $pageId = (int)$document[3]['pid']; } $onClickCode = 'jump(' . GeneralUtility::quoteJSvalue($link) . ', \'web_list\', \'web\', ' . $pageId . '); TYPO3.OpendocsMenu.toggleMenu(); return false;'; - if (!$isRecentDoc) { - $title = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc')); - // Open document - $entry = '<div class="dropdown-table-row t3js-topbar-opendocs-item">'; - $entry .= '<div class="dropdown-table-column dropdown-table-icon">'; - $entry .= $icon; - $entry .= '</div>'; - $entry .= '<div class="dropdown-table-column dropdown-table-title">'; - $entry .= '<a class="dropdown-table-title-ellipsis" href="#" onclick="' . htmlspecialchars($onClickCode) . '" target="list_frame">'; - $entry .= $label; - $entry .= '</a>'; - $entry .= '</div>'; - $entry .= '<div class="dropdown-table-column dropdown-table-actions">'; - $entry .= '<a href="#" class="dropdown-table-actions-btn dropdown-table-actions-btn-close t3js-topbar-opendocs-close" data-opendocsidentifier="' . $md5sum . '" title="' . $title . '">'; - $entry .= $this->iconFactory->getIcon('actions-close', Icon::SIZE_SMALL)->render('inline'); - $entry .= '</a>'; - $entry .= '</div>'; - $entry .= '</div>'; - } else { - // Recently used document - $entry = '<div class="dropdown-table-row t3js-topbar-recentdoc">'; - $entry .= '<div class="dropdown-table-column dropdown-table-icon">'; - $entry .= $icon; - $entry .= '</div>'; - $entry .= '<div class="dropdown-table-column dropdown-table-title">'; - $entry .= '<a class="dropdown-table-title-ellipsis" href="#" onclick="' . htmlspecialchars($onClickCode) . '" target="list_frame">'; - $entry .= $label; - $entry .= '</a>'; - $entry .= '</div>'; - $entry .= '</div>'; - } - return $entry; + $result['onClickCode'] = $onClickCode; + $result['md5sum'] = $md5sum; + return $result; } /** @@ -286,8 +236,7 @@ class OpendocsToolbarItem implements ToolbarItemInterface public function renderMenu(ServerRequestInterface $request, ResponseInterface $response) { $response->getBody()->write($this->getDropDown()); - $response = $response->withHeader('Content-Type', 'text/html; charset=utf-8'); - return $response; + return $response->withHeader('Content-Type', 'text/html; charset=utf-8'); } /** @@ -309,24 +258,4 @@ class OpendocsToolbarItem implements ToolbarItemInterface { return $GLOBALS['BE_USER']; } - - /** - * Returns current PageRenderer - * - * @return PageRenderer - */ - protected function getPageRenderer() - { - return GeneralUtility::makeInstance(PageRenderer::class); - } - - /** - * Returns LanguageService - * - * @return \TYPO3\CMS\Lang\LanguageService - */ - protected function getLanguageService() - { - return $GLOBALS['LANG']; - } } diff --git a/typo3/sysext/opendocs/Resources/Private/Templates/DropDown.html b/typo3/sysext/opendocs/Resources/Private/Templates/DropDown.html new file mode 100644 index 0000000000000000000000000000000000000000..ef23bfb6dbd3e82c941ca8537db9f605c71bf577 --- /dev/null +++ b/typo3/sysext/opendocs/Resources/Private/Templates/DropDown.html @@ -0,0 +1,60 @@ +{namespace core=TYPO3\CMS\Core\ViewHelpers} + +<f:be.pageRenderer loadJQuery="false" includeRequireJsModules="{0:'TYPO3/CMS/Opendocs/Toolbar/OpendocsMenu'}" /> + +<h3 class="dropdown-headline"> + {f:translate(key: 'toolbaritem', extensionName: 'opendocs')} +</h3> +<hr> + +<f:if condition="{noDocs}"> + <f:then> + <p><f:translate key="no_docs" extensionName="opendocs"/></p> + </f:then> + <f:else> + <f:if condition="{openDocuments}"> + <h3 class="dropdown-headline"> + <f:translate key="open_docs" extensionName="opendocs"/> + </h3> + <div class="dropdown-table"> + <f:for each="{openDocuments}" as="openDocument"> + <div class="dropdown-table-row t3js-topbar-opendocs-item"> + <div class="dropdown-table-column dropdown-table-icon"> + <core:iconForRecord table="{openDocument.table}" row="{openDocument.record}" /> + </div> + <div class="dropdown-table-column dropdown-table-title"> + <a class="dropdown-table-title-ellipsis" href="#" onclick="{openDocument.onClickCode}" target="contentIframe"> + {openDocument.label} + </a> + </div> + <div class="dropdown-table-column dropdown-table-actions"> + <a href="#" class="dropdown-table-actions-btn dropdown-table-actions-btn-close t3js-topbar-opendocs-close" data-opendocsidentifier="{openDocument.md5sum}" title="{f:translate(key: 'LLL:EXT:lang/locallang_core.xlf:rm.closeDoc')}"> + <core:icon identifier="actions-close" alternativeMarkupIdentifier="inline" /> + </a> + </div> + </div> + </f:for> + </div> + <hr> + </f:if> + <f:if condition="{recentDocuments}"> + <h3 class="dropdown-headline"> + <f:translate key="recent_docs" extensionName="opendocs"/> + </h3> + <div class="dropdown-table"> + <f:for each="{recentDocuments}" as="recentDocument"> + <div class="dropdown-table-row t3js-topbar-recentdoc"> + <div class="dropdown-table-column dropdown-table-icon"> + <core:iconForRecord table="{recentDocument.table}" row="{recentDocument.record}" /> + </div> + <div class="dropdown-table-column dropdown-table-title"> + <a class="dropdown-table-title-ellipsis" href="#" onclick="{recentDocument.onClickCode}" target="contentIframe"> + {recentDocument.label} + </a> + </div> + </div> + </f:for> + </div> + </f:if> + </f:else> +</f:if> \ No newline at end of file diff --git a/typo3/sysext/opendocs/Resources/Private/Templates/ToolbarItem.html b/typo3/sysext/opendocs/Resources/Private/Templates/ToolbarItem.html new file mode 100644 index 0000000000000000000000000000000000000000..7cd5a802c25dc8bd0811414d43ee78171c920dc5 --- /dev/null +++ b/typo3/sysext/opendocs/Resources/Private/Templates/ToolbarItem.html @@ -0,0 +1,7 @@ +{namespace core=TYPO3\CMS\Core\ViewHelpers} + +<span class="toolbar-item-icon" title="{f:translate(key: 'toolbaritem', extensionName: 'opendocs')}"> + <core:icon identifier="apps-toolbar-menu-opendocs" alternativeMarkupIdentifier="inline" /> +</span> +<span class="toolbar-item-title">{f:translate(key: 'toolbaritem', extensionName: 'opendocs')}</span> +<span class="toolbar-item-badge badge" id="tx-opendocs-counter">{numDocs}</span>