Issue Bug Closed

#97146Undefined array key "uid" in ContentContentObject

Georg Tiefenbrunn 03/08/22, 15:52 updated 10/04/22, 14:14

Description

ContentContentObject::render() can’t handle ‘records’ without uid:

# TypoScript
page.10 = CONTENT
page.10 {
  table = tt_content
  select.selectFields = count(*)
  renderObj = TEXT
  renderObj {
    field = count(*)
    wrap = value:|
  }
}
PHP Warning: Undefined array key "uid" in typo3/sysext/frontend/Classes/ContentObject/ContentContentObject.php line 91

According to https://docs.typo3.org/m/typo3/reference-typoscript/11.5/en-us/Functions/Select.html#selectfields select.selectFields = count(*) is valid TypoScript:

> List of fields to select, or count(*).

TypoScript workaround

page.10 = CONTENT
page.10 {
  table = tt_content
  select.selectFields = count(uid) AS count, uid
  renderObj = TEXT
  renderObj {
    value = {field:count}
    insertData = 1
    wrap = value:|
  }
}

Fix

// typo3/sysext/frontend/Classes/ContentObject/ContentContentObject.php line 91
-                    $registerField = $conf['table'] . ':' . $row['uid'];
+                    $registerField = $conf['table'] . ':' . (int)($row['uid'] ?? 0);

Reviews 2