Project

General

Profile

Actions

Bug #101925

closed

Check if index exists in stdWrap.listNum to avoid PHP warnings

Added by Michael Stopp 8 months ago. Updated 8 months ago.

Status:
Resolved
Priority:
Should have
Assignee:
-
Category:
TypoScript
Target version:
-
Start date:
2023-09-15
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
12
PHP Version:
8.2
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

Let's assume we want to use the 2nd image stored in a page's media field as a background image. We can do something like this in TypoScript to generate some inline CSS:

10 = IMG_RESOURCE
10 {
  file.import.data = levelmedia:-1, slide
  file.import.listNum = 1
  file.treatIdAsReference = 1
  stdWrap.wrap = body {background: url(|) no-repeat; background-size: cover; background-attachment: fixed;}
}

But if there is no 2nd image, a PHP warning is generated, which can flood your sys_log over time:

Core: Error handler (FE): PHP Warning: Undefined array key 1 in /typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php line 2592 

The listNum() method in ContentObjectRenderer currently just blindly returns the specified/calculated index:

return $temp[$index];

I think it would be cleaner and better to do something like this (same behaviour as if the exploded content was empty):

return $temp[$index] ?? '';

Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Task #101934: Cleanup code for ContentObjectRenderer::listNum and add testsClosedSybille Peters2023-09-17

Actions
Actions #1

Updated by Michael Stopp 8 months ago

  • Subject changed from Check if index existis in stdWrap.listNum to avoid PHP warnings to Check if index exists in stdWrap.listNum to avoid PHP warnings
Actions #2

Updated by Gerrit Code Review 8 months ago

  • Status changed from New to Under Review

Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81027

Actions #3

Updated by Christian Kuhn 8 months ago

  • Related to Task #101934: Cleanup code for ContentObjectRenderer::listNum and add tests added
Actions #4

Updated by Gerrit Code Review 8 months ago

Patch set 1 for branch 12.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81044

Actions #5

Updated by Gerrit Code Review 8 months ago

Patch set 1 for branch 11.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81045

Actions #6

Updated by Georg Ringer 8 months ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions

Also available in: Atom PDF