Commit caec6d15 authored by Oliver Hader's avatar Oliver Hader Committed by Oliver Bartsch
Browse files

[TASK] Prevent undefined array key warnings in ext:adminpanel

This change addresses several "undefined array key" issues that have
been identified by PsalmPHP (see issue #98321).

Resolves: #98324
Releases: main, 11.5
Change-Id: I1f9cb64d920f8d4e3d5a44f4af3488543df12e99
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/75683


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Tested-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Oliver Klee's avatarOliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
parent cf39675a
......@@ -103,7 +103,7 @@ class MainController implements SingletonInterface
'toggleActiveUrl' => $this->generateBackendUrl('ajax_adminPanel_toggle'),
'resources' => $resources,
'adminPanelActive' => StateUtility::isOpen(),
'languageKey' => $this->getBackendUser()->user['lang'],
'languageKey' => $this->getBackendUser()->user['lang'] ?? null,
]
);
if (StateUtility::isOpen()) {
......
......@@ -48,7 +48,8 @@ class CacheModule extends AbstractModule implements PageSettingsProviderInterfac
$view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$feCacheClear = $this->getBackendUser()->isAdmin() || $this->getBackendUser()->getTSConfig()['options.']['clearCache.']['pages'];
$feCacheClear = $this->getBackendUser()->isAdmin()
|| !empty($this->getBackendUser()->getTSConfig()['options.']['clearCache.']['pages']);
$pageId = 0;
$pageArguments = $GLOBALS['TYPO3_REQUEST']->getAttribute('routing');
......@@ -68,7 +69,7 @@ class CacheModule extends AbstractModule implements PageSettingsProviderInterfac
'cacheCmd' => $pageId,
]
),
'languageKey' => $this->getBackendUser()->user['lang'],
'languageKey' => $this->getBackendUser()->user['lang'] ?? null,
]
);
......
......@@ -19,6 +19,7 @@ namespace TYPO3\CMS\Adminpanel\Modules\Debug;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Http\Message\ServerRequestInterface;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\AbstractDumper;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
......@@ -66,13 +67,13 @@ class Events extends AbstractSubModule implements DataProviderInterface
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
$view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
$values = $data->getArrayCopy();
$events = $values['events'];
$events = $values['events'] ?? null;
$dumper = new HtmlDumper(null, null, AbstractDumper::DUMP_LIGHT_ARRAY);
$dumper->setTheme('light');
$view->assign('events', $dumper->dump($events, true));
$view->assign('languageKey', $this->getBackendUser()->user['lang']);
$view->assign('events', $events instanceof Data ? $dumper->dump($events, true) : null);
$view->assign('languageKey', $this->getBackendUser()->user['lang'] ?? null);
return $view->render();
}
......
......@@ -100,7 +100,7 @@ class Log extends AbstractSubModule implements DataProviderInterface, ModuleSett
$templateNameAndPath = 'EXT:adminpanel/Resources/Private/Templates/Modules/Debug/LogSettings.html';
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
$view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
$view->assign('languageKey', $this->getBackendUser()->user['lang']);
$view->assign('languageKey', $this->getBackendUser()->user['lang'] ?? null);
$maxLevel = LogLevel::normalizeLevel(\Psr\Log\LogLevel::DEBUG);
$levels = [];
......@@ -158,7 +158,7 @@ class Log extends AbstractSubModule implements DataProviderInterface, ModuleSett
$data['groupByComponent'] = $groupByComponent;
$data['groupByLevel'] = $groupByLevel;
$view->assignMultiple($data->getArrayCopy());
$view->assign('languageKey', $this->getBackendUser()->user['lang']);
$view->assign('languageKey', $this->getBackendUser()->user['lang'] ?? null);
return $view->render();
}
......
......@@ -79,12 +79,13 @@ class PageTitle extends AbstractSubModule implements DataProviderInterface
$log = InMemoryLogWriter::$log;
foreach ($log as $logEntry) {
if ($logEntry->getComponent() === self::LOG_COMPONENT) {
if (isset($logEntry->getData()['orderedTitleProviders'])) {
$data['orderedProviders'] = $logEntry->getData()['orderedTitleProviders'];
} elseif (isset($logEntry->getData()['providerUsed'])) {
$data['usedProvider'] = $logEntry->getData();
$logEntryData = $logEntry->getData();
if (isset($logEntryData['orderedTitleProviders'])) {
$data['orderedProviders'] = $logEntryData['orderedTitleProviders'];
} elseif (isset($logEntryData['providerUsed'])) {
$data['usedProvider'] = $logEntryData;
} elseif (isset($logEntry->getData()['skippedProvider'])) {
$data['skippedProviders'][] = $logEntry->getData();
$data['skippedProviders'][] = $logEntryData;
}
}
}
......@@ -104,7 +105,7 @@ class PageTitle extends AbstractSubModule implements DataProviderInterface
);
$this->getLanguageService()->includeLLFile('EXT:adminpanel/Resources/Private/Language/locallang_debug.xlf');
$view->assignMultiple($data->getArrayCopy());
$view->assign('languageKey', $this->getBackendUser()->user['lang']);
$view->assign('languageKey', $this->getBackendUser()->user['lang'] ?? null);
return $view->render();
}
......
......@@ -88,7 +88,7 @@ class QueryInformation extends AbstractSubModule implements DataProviderInterfac
);
$this->getLanguageService()->includeLLFile('EXT:adminpanel/Resources/Private/Language/locallang_debug.xlf');
$view->assignMultiple($data->getArrayCopy());
$view->assign('languageKey', $this->getBackendUser()->user['lang']);
$view->assign('languageKey', $this->getBackendUser()->user['lang'] ?? null);
return $view->render();
}
......
......@@ -81,7 +81,7 @@ class GeneralInformation extends AbstractSubModule implements DataProviderInterf
$view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
$view->assignMultiple($data->getArrayCopy());
$view->assign('languageKey', $this->getBackendUser()->user['lang']);
$view->assign('languageKey', $this->getBackendUser()->user['lang'] ?? null);
return $view->render();
}
......
......@@ -67,7 +67,7 @@ class PhpInformation extends AbstractSubModule implements DataProviderInterface
$view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
$view->assignMultiple($data->getArrayCopy());
$view->assign('languageKey', $this->getBackendUser()->user['lang']);
$view->assign('languageKey', $this->getBackendUser()->user['lang'] ?? null);
return $view->render();
}
......
......@@ -64,7 +64,7 @@ class RequestInformation extends AbstractSubModule implements DataProviderInterf
$view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
$view->assignMultiple($data->getArrayCopy());
$view->assign('languageKey', $this->getBackendUser()->user['lang']);
$view->assign('languageKey', $this->getBackendUser()->user['lang'] ?? null);
return $view->render();
}
......
......@@ -61,7 +61,7 @@ class UserIntInformation extends AbstractSubModule implements DataProviderInterf
$view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
$view->assignMultiple($data->getArrayCopy());
$view->assign('languageKey', $this->getBackendUser()->user['lang']);
$view->assign('languageKey', $this->getBackendUser()->user['lang'] ?? null);
return $view->render();
}
......
......@@ -40,7 +40,14 @@ class PreviewModule extends AbstractModule implements RequestEnricherInterface,
/**
* module configuration, set on initialize
*
* @var array
* @var array{
* showHiddenPages?: bool,
* simulateDate?: int,
* showHiddenRecords?: bool,
* showScheduledRecords?: bool,
* simulateUserGroup?: int,
* showFluidDebug?: bool
* }
*/
protected $config;
......@@ -110,17 +117,17 @@ class PreviewModule extends AbstractModule implements RequestEnricherInterface,
[
'show' => [
'pageId' => $pageId,
'hiddenPages' => $this->config['showHiddenPages'],
'hiddenRecords' => $this->config['showHiddenRecords'],
'showScheduledRecords' => $this->config['showScheduledRecords'],
'fluidDebug' => $this->config['showFluidDebug'],
'hiddenPages' => $this->config['showHiddenPages'] ?? false,
'hiddenRecords' => $this->config['showHiddenRecords'] ?? false,
'showScheduledRecords' => $this->config['showScheduledRecords'] ?? false,
'fluidDebug' => $this->config['showFluidDebug'] ?? false,
],
'simulateDate' => $this->config['simulateDate'],
'simulateDate' => (int)($this->config['simulateDate'] ?? 0),
'frontendUserGroups' => [
'availableGroups' => $frontendGroupsRepository->getAvailableFrontendUserGroups(),
'selected' => (int)$this->config['simulateUserGroup'],
'selected' => (int)($this->config['simulateUserGroup'] ?? 0),
],
'languageKey' => $this->getBackendUser()->user['lang'],
'languageKey' => $this->getBackendUser()->user['lang'] ?? null,
]
);
return $view->render();
......
......@@ -92,7 +92,7 @@ class TypoScriptWaterfall extends AbstractSubModule implements RequestEnricherIn
'trackContentRendering' => (int)$this->getConfigurationOption('LR'),
'forceTemplateParsing' => (int)$this->getConfigurationOption('forceTemplateParsing'),
'typoScriptLog' => $this->renderTypoScriptLog(),
'languageKey' => $this->getBackendUser()->user['lang'],
'languageKey' => $this->getBackendUser()->user['lang'] ?? null,
]
);
......@@ -116,7 +116,7 @@ class TypoScriptWaterfall extends AbstractSubModule implements RequestEnricherIn
],
'trackContentRendering' => (int)$this->getConfigurationOption('LR'),
'forceTemplateParsing' => (int)$this->getConfigurationOption('forceTemplateParsing'),
'languageKey' => $this->getBackendUser()->user['lang'],
'languageKey' => $this->getBackendUser()->user['lang'] ?? null,
]
);
......
......@@ -51,8 +51,8 @@ class ModuleLoader
1519490105
);
}
if (!is_string($configuration['module']) ||
empty($configuration['module']) ||
if (empty($configuration['module']) ||
!is_string($configuration['module']) ||
!class_exists($configuration['module']) ||
!is_subclass_of(
$configuration['module'],
......
......@@ -29,7 +29,7 @@ class ResourceUtility
* one array - returns an array of full html tags
*
* @param \TYPO3\CMS\Adminpanel\ModuleApi\ModuleInterface[] $modules
* @return array
* @return array{js: string, css: string}
*/
public static function getAdditionalResourcesForModules(array $modules): array
{
......
......@@ -32,6 +32,9 @@ final class IsArrayViewHelper extends AbstractViewHelper
$this->registerArgument('value', 'mixed', 'The variable being checked', true);
}
/**
* @param array{value: mixed} $arguments
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): bool
{
return is_array($arguments['value']);
......
......@@ -46,12 +46,12 @@ final class SubModuleRenderViewHelper extends AbstractViewHelper
/**
* Resolve user name from backend user id.
*
* @param array{module: ContentProviderInterface, data: ModuleDataStorageCollection} $arguments
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
{
/** @var ContentProviderInterface $module */
$module = $arguments['module'];
/** @var ModuleDataStorageCollection $data */
$data = $arguments['data'];
$moduleData = $data->contains($module) ? $data->offsetGet($module) : new ModuleData();
return $module->getContent($moduleData);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment