Skip to content

Commit

Permalink
[BUGFIX] Fix typing issues in various backend controllers
Browse files Browse the repository at this point in the history
This change aims to reduce all left-over strict type changes,
and backwards-incompatible changes in our own code base
making sure that TYPO3 can run smoothly with PHP 8.

Resolves: #94335
Releases: master
Change-Id: I9d1c8966a56a80bb68216ae535547e0bf55e50c9
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/67243
Tested-by: core-ci <typo3@b13.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
bmack authored and lolli42 committed Jun 14, 2021
1 parent f8c1f6d commit 8019925
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 39 deletions.
2 changes: 1 addition & 1 deletion typo3/sysext/backend/Classes/Clipboard/Clipboard.php
Expand Up @@ -540,7 +540,7 @@ public function padTitle($pad)
{
$el = count($this->elFromTable($this->fileMode ? '_FILE' : '', $pad));
if ($el) {
return ' (' . ($pad === 'normal' ? ($this->clipData['normal']['mode'] === 'copy' ? $this->clLabel('copy', 'cm') : $this->clLabel('cut', 'cm')) : htmlspecialchars((string)$el)) . ')';
return ' (' . ($pad === 'normal' ? (($this->clipData['normal']['mode'] ?? '') === 'copy' ? $this->clLabel('copy', 'cm') : $this->clLabel('cut', 'cm')) : htmlspecialchars((string)$el)) . ')';
}
return '';
}
Expand Down
Expand Up @@ -92,7 +92,7 @@ public function render(): array
$disabled = true;
}
// Traversing the array of items
$items = $this->data['parameterArray']['fieldConf']['config']['items'];
$items = $this->data['parameterArray']['fieldConf']['config']['items'] ?? [];

$numberOfItems = \count($items);
if ($numberOfItems === 0) {
Expand Down
Expand Up @@ -359,7 +359,7 @@ protected function getLinkExplanation(string $itemValue): array
case LinkService::TYPE_PAGE:
$pageRecord = BackendUtility::readPageAccess($linkData['pageuid'], '1=1');
// Is this a real page
if ($pageRecord['uid']) {
if ($pageRecord['uid'] ?? 0) {
$fragmentTitle = '';
if (isset($linkData['fragment'])) {
if (MathUtility::canBeInterpretedAsInteger($linkData['fragment'])) {
Expand Down
Expand Up @@ -79,7 +79,7 @@ public function render()
$languageId = 0;
if (isset($GLOBALS['TCA'][$table]['ctrl']['languageField']) && !empty($GLOBALS['TCA'][$table]['ctrl']['languageField'])) {
$languageField = $GLOBALS['TCA'][$table]['ctrl']['languageField'];
$languageId = (int)((is_array($row[$languageField]) ? $row[$languageField][0] : $row[$languageField]) ?? 0);
$languageId = (int)((is_array($row[$languageField] ?? null) ? ($row[$languageField][0] ?? 0) : $row[$languageField]) ?? 0);
}

$itemValue = $parameterArray['itemFormElValue'];
Expand Down
Expand Up @@ -168,10 +168,10 @@ protected function initializeChildrenLanguage(array $result, $fieldName)
) {
if (is_array($result['databaseRow'][$parentLanguageField])) {
$result['processedTca']['columns'][$fieldName]['config']['inline']['parentSysLanguageUid']
= (int)$result['databaseRow'][$parentLanguageField][0];
= (int)($result['databaseRow'][$parentLanguageField][0] ?? 0);
} else {
$result['processedTca']['columns'][$fieldName]['config']['inline']['parentSysLanguageUid']
= (int)$result['databaseRow'][$parentLanguageField];
= (int)($result['databaseRow'][$parentLanguageField] ?? 0);
}
}

Expand Down
Expand Up @@ -43,7 +43,7 @@ public function addData(array $result): array

if (($result['processedTca']['ctrl']['languageField'] ?? '') !== '') {
$languageField = $result['processedTca']['ctrl']['languageField'];
$languageId = (int)((is_array($row[$languageField]) ? $row[$languageField][0] : $row[$languageField]) ?? 0);
$languageId = (int)((is_array($row[$languageField] ?? null) ? ($row[$languageField][0] ?? 0) : $row[$languageField]) ?? 0);
}

foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) {
Expand Down
Expand Up @@ -197,7 +197,7 @@ protected function getLanguageColumnsWithDefLangBindingForPageLayoutContext(Page

foreach ($grid->getRows() as $rows) {
foreach ($rows->getColumns() as $column) {
if ($translationInfo['mode'] === 'connected') {
if (($translationInfo['mode'] ?? '') === 'connected') {
foreach ($column->getItems() as $item) {
// check if translation exists
foreach ($translatedRows as $translation) {
Expand Down
Expand Up @@ -454,7 +454,7 @@ public function getPagesOverlay(array $pagesInput, $languageUid = null)
foreach ($pagesInput as $key => $origPage) {
if (is_array($origPage)) {
$pagesOutput[$key] = $origPage;
if (isset($overlays[$origPage['uid']])) {
if (isset($origPage['uid'], $overlays[$origPage['uid']])) {
// Overwrite the original field with the overlay
foreach ($overlays[$origPage['uid']] as $fieldName => $fieldValue) {
if ($fieldName !== 'uid' && $fieldName !== 'pid') {
Expand Down Expand Up @@ -485,11 +485,13 @@ public function isPageSuitableForLanguage(array $page, LanguageAspect $languageA
// Checks if the default language version can be shown
// Block page is set, if l18n_cfg allows plus: 1) Either default language or 2) another language but NO overlay record set for page!
$pageTranslationVisibility = new PageTranslationVisibility((int)($page['l18n_cfg'] ?? 0));
if ($pageTranslationVisibility->shouldBeHiddenInDefaultLanguage() && (!$languageUid || $languageUid && !$page['_PAGES_OVERLAY'])) {
if ((!$languageUid || !($page['_PAGES_OVERLAY'] ?? false))
&& $pageTranslationVisibility->shouldBeHiddenInDefaultLanguage()
) {
return false;
}
if ($languageUid > 0 && $pageTranslationVisibility->shouldHideTranslationIfNoTranslatedRecordExists()) {
if (!$page['_PAGES_OVERLAY'] || (int)$page['_PAGES_OVERLAY_LANGUAGE'] !== $languageUid) {
if (!($page['_PAGES_OVERLAY'] ?? false) || (int)($page['_PAGES_OVERLAY_LANGUAGE'] ?? 0) !== $languageUid) {
return false;
}
} elseif ($languageUid > 0) {
Expand Down
Expand Up @@ -132,7 +132,7 @@ public function addProperty(string $property, string $content, array $subPropert
if (!isset($handledPropertyConfig['allowedSubProperties'])) {
continue;
}
foreach ((array)$handledPropertyConfig['allowedSubProperties'] as $allowedSubProperty => $allowedSubPropertyConfig) {
foreach ((array)($handledPropertyConfig['allowedSubProperties'] ?? []) as $allowedSubProperty => $allowedSubPropertyConfig) {
$propertyKey = is_array($allowedSubPropertyConfig) ? $allowedSubProperty : $allowedSubPropertyConfig;

if ($property !== $handledProperty . $this->subPropertySeparator . $propertyKey ||
Expand Down
Expand Up @@ -466,7 +466,7 @@ protected function renderLinkAttributeFields()

$content = '';
foreach ($this->linkAttributeFields as $attribute) {
$content .= $fieldRenderingDefinitions[$attribute];
$content .= $fieldRenderingDefinitions[$attribute] ?? '';
}

// add update button if appropriate
Expand All @@ -493,7 +493,7 @@ protected function getLinkAttributeFieldDefinitions()
<label class="col-sm-3 col-form-label">' . htmlspecialchars($lang->getLL('target')) . '</label>
<div class="col-sm-4">
<input type="text" name="ltarget" class="t3js-linkTarget form-control"
value="' . htmlspecialchars($this->linkAttributeValues['target']) . '" />
value="' . htmlspecialchars($this->linkAttributeValues['target'] ?? '') . '" />
</div>
<div class="col-sm-5">
<select name="ltarget_type" class="t3js-targetPreselect form-select">
Expand All @@ -512,7 +512,7 @@ protected function getLinkAttributeFieldDefinitions()
<label class="col-sm-3 col-form-label">' . htmlspecialchars($lang->getLL('title')) . '</label>
<div class="col-sm-9">
<input type="text" name="ltitle" class="form-control"
value="' . htmlspecialchars($this->linkAttributeValues['title']) . '" />
value="' . htmlspecialchars($this->linkAttributeValues['title'] ?? '') . '" />
</div>
</div>
</form>';
Expand All @@ -524,7 +524,7 @@ protected function getLinkAttributeFieldDefinitions()
<label class="col-sm-3 col-form-label">' . htmlspecialchars($lang->getLL('class')) . '</label>
<div class="col-sm-9">
<input type="text" name="lclass" class="form-control"
value="' . htmlspecialchars($this->linkAttributeValues['class']) . '" />
value="' . htmlspecialchars($this->linkAttributeValues['class'] ?? '') . '" />
</div>
</div>
</form>';
Expand All @@ -536,7 +536,7 @@ protected function getLinkAttributeFieldDefinitions()
<label class="col-sm-3 col-form-label">' . htmlspecialchars($lang->getLL('params')) . '</label>
<div class="col-sm-9">
<input type="text" name="lparams" class="form-control"
value="' . htmlspecialchars($this->linkAttributeValues['params']) . '" />
value="' . htmlspecialchars($this->linkAttributeValues['params'] ?? '') . '" />
</div>
</div>
</form>';
Expand Down
Expand Up @@ -221,9 +221,12 @@ protected function renderItem(ResourceInterface $fileOrFolderObject)
*/
public function getBodyTagAttributes()
{
return [
'data-current-link' => GeneralUtility::makeInstance(LinkService::class)->asString(['type' => LinkService::TYPE_FILE, 'file' => $this->linkParts['url']['file']])
];
if (isset($this->linkParts['url']['file'])) {
return [
'data-current-link' => GeneralUtility::makeInstance(LinkService::class)->asString(['type' => LinkService::TYPE_FILE, 'file' => $this->linkParts['url']['file']])
];
}
return [];
}

/**
Expand Down
Expand Up @@ -54,7 +54,7 @@ protected function getFolderContent(Folder $folder, $extensionList)
*/
public function getBodyTagAttributes()
{
if ($this->linkParts['url']['folder'] instanceof $this->expectedClass) {
if (isset($this->linkParts['url']['folder']) && $this->linkParts['url']['folder'] instanceof $this->expectedClass) {
return [
'data-current-link' => GeneralUtility::makeInstance(LinkService::class)->asString(['type' => LinkService::TYPE_FOLDER, 'folder' => $this->linkParts['url']['folder']])
];
Expand Down
Expand Up @@ -90,7 +90,7 @@ public function formatCurrentUrl()

return $lang->getLL('page')
. ' \'' . GeneralUtility::fixed_lgd_cs($pageRow['title'], $titleLen) . '\''
. ' (ID: ' . $id . ($this->linkParts['url']['fragment'] ? ', #' . $this->linkParts['url']['fragment'] : '') . ')';
. ' (ID: ' . $id . (!empty($this->linkParts['url']['fragment']) ? ', #' . $this->linkParts['url']['fragment'] : '') . ')';
}

/**
Expand Down Expand Up @@ -198,7 +198,7 @@ public function getBodyTagAttributes()
'data-current-link' => GeneralUtility::makeInstance(LinkService::class)->asString([
'type' => LinkService::TYPE_PAGE,
'pageuid' => (int)$this->linkParts['url']['pageuid'],
'fragment' => $this->linkParts['url']['fragment']
'fragment' => $this->linkParts['url']['fragment'] ?? ''
])
];
}
Expand Down
Expand Up @@ -248,13 +248,13 @@ protected function renderLinkAttributeFields()
}
}
// Default target
$this->defaultLinkTarget = $this->classesAnchorDefault[$this->displayedLinkHandlerId] && $this->classesAnchorDefaultTarget[$this->displayedLinkHandlerId]
$this->defaultLinkTarget = ($this->classesAnchorDefault[$this->displayedLinkHandlerId] ?? false) && ($this->classesAnchorDefaultTarget[$this->displayedLinkHandlerId] ?? false)
? $this->classesAnchorDefaultTarget[$this->displayedLinkHandlerId]
: ($this->buttonConfig[$this->displayedLinkHandlerId]['properties']['target']['default'] ?? $this->buttonConfig['properties']['target']['default'] ?? '');

// todo: find new name for this option
// Initializing additional attributes
if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rte_ckeditor']['plugins']['TYPO3Link']['additionalAttributes']) {
if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rte_ckeditor']['plugins']['TYPO3Link']['additionalAttributes'] ?? false) {
$addAttributes = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rte_ckeditor']['plugins']['TYPO3Link']['additionalAttributes'], true);
foreach ($addAttributes as $attribute) {
$this->additionalAttributes[$attribute] = $this->linkAttributeValues[$attribute] ?? '';
Expand Down Expand Up @@ -301,7 +301,7 @@ protected function getAllowedItems()
: [];
$allowedItems = array_diff($allowedItems, $blindLinkOptions);

if (is_array($this->buttonConfig['options']) && $this->buttonConfig['options']['removeItems']) {
if (is_array($this->buttonConfig['options'] ?? null) && !empty($this->buttonConfig['options']['removeItems'])) {
$allowedItems = array_diff($allowedItems, GeneralUtility::trimExplode(',', $this->buttonConfig['options']['removeItems'], true));
}

Expand Down Expand Up @@ -385,14 +385,15 @@ protected function getRelField()
protected function getTargetField()
{
$targetSelectorConfig = [];
if (is_array($this->buttonConfig['targetSelector'])) {
if (is_array($this->buttonConfig['targetSelector'] ?? null)) {
$targetSelectorConfig = $this->buttonConfig['targetSelector'];
}
$target = $this->linkAttributeValues['target'] ?: $this->defaultLinkTarget;
$target = !empty($this->linkAttributeValues['target']) ? $this->linkAttributeValues['target'] : $this->defaultLinkTarget;
$lang = $this->getLanguageService();
$targetSelector = '';

if (!$targetSelectorConfig['disabled']) {
$disabled = $targetSelectorConfig['disabled'] ?? false;
if (!$disabled) {
$targetSelector = '
<select name="ltarget_type" class="t3js-targetPreselect form-select">
<option value=""></option>
Expand All @@ -404,7 +405,7 @@ protected function getTargetField()

return '
<form action="" name="ltargetform" id="ltargetform" class="t3js-dummyform form-horizontal">
<div class="row mb-3" ' . ($targetSelectorConfig['disabled'] ? ' style="display: none;"' : '') . '>
<div class="row mb-3" ' . ($disabled ? ' style="display: none;"' : '') . '>
<label class="col-sm-3 col-form-label">' . htmlspecialchars($lang->getLL('target')) . '</label>
<div class="col-sm-4">
<input type="text" name="ltarget" class="t3js-linkTarget form-control"
Expand All @@ -425,15 +426,15 @@ protected function getTargetField()
*/
protected function getTitleField()
{
if ($this->linkAttributeValues['title']) {
if ($this->linkAttributeValues['title'] ?? null) {
$title = $this->linkAttributeValues['title'];
} else {
$title = $this->classesAnchorDefaultTitle[$this->displayedLinkHandlerId] ?: '';
$title = ($this->classesAnchorDefaultTitle[$this->displayedLinkHandlerId] ?? false) ?: '';
}
$readOnlyTitle = $this->isReadonlyTitle();

if ($readOnlyTitle) {
$currentClass = $this->linkAttributeFields['class'];
$currentClass = $this->linkAttributeFields['class'] ?? '';
if (!$currentClass) {
$currentClass = empty($this->classesAnchorDefault[$this->displayedLinkHandlerId]) ? '' : $this->classesAnchorDefault[$this->displayedLinkHandlerId];
}
Expand Down Expand Up @@ -462,7 +463,7 @@ protected function getTitleField()
protected function getClassField()
{
$selectClass = '';
if ($this->classesAnchorJSOptions[$this->displayedLinkHandlerId]) {
if (isset($this->classesAnchorJSOptions[$this->displayedLinkHandlerId])) {
$selectClass = '
<form action="" name="lclassform" id="lclassform" class="t3js-dummyform form-horizontal">
<div class="row mb-3">
Expand Down
Expand Up @@ -58,11 +58,9 @@ public function resolve()
// If RTE is generally enabled by user settings and RTE object registry can return something valid
&& $backendUser->isRTE()
// If RTE is enabled for field
&& isset($parameterArray['fieldConf']['config']['enableRichtext'])
&& (bool)$parameterArray['fieldConf']['config']['enableRichtext'] === true
&& (bool)($parameterArray['fieldConf']['config']['enableRichtext'] ?? false) === true
// If RTE config is found (prepared by TcaText data provider)
&& isset($parameterArray['fieldConf']['config']['richtextConfiguration'])
&& is_array($parameterArray['fieldConf']['config']['richtextConfiguration'])
&& is_array($parameterArray['fieldConf']['config']['richtextConfiguration'] ?? null)
// If RTE is not disabled on configuration level
&& !($parameterArray['fieldConf']['config']['richtextConfiguration']['disabled'] ?? false)
) {
Expand Down
Expand Up @@ -127,7 +127,7 @@ public function render(): array
$this->data['tableName'] . ' > ' . $this->data['fieldName'],
[
'target' => 0,
'effectivePid' => $this->data['effectivePid']
'effectivePid' => $this->data['effectivePid'] ?? 0
]
);

Expand Down

0 comments on commit 8019925

Please sign in to comment.