Skip to content

Instantly share code, notes, and snippets.

@nitori
Created July 5, 2024 16:29
Show Gist options
  • Save nitori/44556ab1edeaee2052803bb0ccfd2caa to your computer and use it in GitHub Desktop.
Save nitori/44556ab1edeaee2052803bb0ccfd2caa to your computer and use it in GitHub Desktop.
<?php
namespace Vendor\MyExt\Xclass;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Http\Uri;
use TYPO3\CMS\Core\Routing\SiteMatcher;
use TYPO3\CMS\Core\Site\Entity\NullSite;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
class AuthenticationStyleInformation extends \TYPO3\CMS\Backend\View\AuthenticationStyleInformation
{
public function getLogo(): string
{
$logo = parent::getLogo();
$config = $this->getCurrentSiteConfiguration();
$path = $config['schoolDir'] ?? null;
if (empty($path)) {
return $logo;
}
$logoWebPath = rtrim($path, '/') . '/logo.svg';
$logoSysPath = GeneralUtility::getFileAbsFileName($logoWebPath);
if (!file_exists($logoSysPath)) {
return $logo;
}
return PathUtility::getAbsoluteWebPath($logoSysPath);
}
public function getHighlightColorStyles(): string
{
$styles = parent::getHighlightColorStyles();
$config = $this->getCurrentSiteConfiguration();
$firstColor = current($config['themeColors'] ?? [['color' => null]])['color'] ?? null;
if (empty($firstColor)) {
return $styles;
}
$styles = preg_replace(
'/\.btn-login \{ background-color: [^;]*; }/',
'.btn-login { background-color: ' . $firstColor . '; }',
$styles
);
$styles = preg_replace(
'/\.card-login \.card-footer \{ border-color: [^;]*; \}/',
'.card-login .card-footer { border-color: ' . $firstColor . '; }',
$styles
);
return $styles;
}
protected function getCurrentSiteConfiguration(): array
{
/** @var ServerRequest $request */
$request = $GLOBALS['TYPO3_REQUEST'] ?? null;
if ($request === null) {
return [];
}
/** @var Site|NullSite $site */
$site = $this->findSiteByUrl($request->getUri());
if ($site instanceof NullSite) {
return [];
}
return $site->getConfiguration();
}
protected function findSiteByUrl(string|Uri $url)
{
if (is_string($url)) {
$url = GeneralUtility::makeInstance(Uri::class, $url);
}
$request = GeneralUtility::makeInstance(ServerRequest::class, $url);
$matcher = GeneralUtility::makeInstance(SiteMatcher::class);
$routeResult = $matcher->matchRequest($request);
return $routeResult->getSite();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment