ew_base/Classes/ToolbarItems/ReleaseToolbarItem.php
Sebastian Fischer 5319bd35a5 First commit
2024-02-09 17:13:28 +01:00

99 lines
2.7 KiB
PHP
Executable File

<?php
namespace Evoweb\EwBase\ToolbarItems;
/*
* This file is developed by evoWeb.
*
* 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.
*/
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Toolbar\RequestAwareToolbarItemInterface;
use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface;
use TYPO3\CMS\Backend\View\BackendViewFactory;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class ReleaseToolbarItem implements ToolbarItemInterface, RequestAwareToolbarItemInterface
{
private ServerRequestInterface $request;
public function __construct(
private readonly BackendViewFactory $backendViewFactory,
) {
}
public function setRequest(ServerRequestInterface $request): void
{
$this->request = $request;
}
public function checkAccess(): bool
{
$result = false;
$backendUser = $this->getBackendUser();
if ($backendUser->isAdmin()) {
$result = true;
}
if ($backendUser->getTSConfig()['options.']['showSystemInformation'] ?? false) {
$result = true;
}
$release = $this->getRelease();
if (empty($release)) {
$result = false;
}
return $result;
}
public function getItem(): string
{
$view = $this->backendViewFactory->create($this->request, ['typo3/cms-backend', 'evoweb/ew-base']);
return $view->render('ToolbarItems/ShowReleaseToolbarItem');
}
public function hasDropDown(): bool
{
return true;
}
public function getDropDown(): string
{
$view = $this->backendViewFactory->create($this->request, ['typo3/cms-backend', 'evoweb/ew-base']);
$view->assignMultiple([
'release' => $this->getRelease(),
]);
return $view->render('ToolbarItems/ShowReleaseDropDown');
}
public function getAdditionalAttributes(): array
{
return [];
}
public function getIndex(): int
{
return 20;
}
protected function getRelease(): array
{
$release = GeneralUtility::getUrl(Environment::getProjectPath() . '/release');
return $release ? [
'release' => trim($release),
'isTag' => str_contains($release, '.'),
] : [];
}
protected function getBackendUser(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}
}