Important: The select item event declares what TYPO3 passes
Description
\FGTCLB\ declares the
parameters of an
items as a PHPStan array shape, and the item
providers that dispatch the event repeated that shape. Three keys of it were
declared narrower than TYPO3 fills them in the backend form:
| Key | Declared | Passed by TYPO3 v12, v13 and v14 |
|---|---|---|
inline,
inline |
int
| The empty string '' for a record that is not edited as an
inline child. A NEW... string for a parent that is not saved
yet. Otherwise the uid of the parent, as an integer or a numeric
string. The site configuration passes
null
as
inline. |
site
|
Site | A
\TYPO3\ for a record
outside any site, on page 0 for example. |
items
| arrays |
\TYPO3\ objects for
the items TYPO3 built before the item provider ran, the static
items of the field among them. The items a provider adds are
arrays. |
The event declares the shape once now, as the PHPStan type alias
Items, with
int for
inline,
int for
inline,
\TYPO3\ for
site
,
and
Select or an array for an item. The item providers of
fgtclb/academic-jobs
,
fgtclb/academic-persons
and
fgtclb/academic-contacts4pages
import it. The providers of
fgtclb/academic-persons
and
fgtclb/academic-contacts4pages
therefore declare
row
optional as well, as the event does since
Important: The select item helper passes an empty row.
Only the declaration changes. TYPO3 passed these values before, and the item providers pass them on unchanged.
Impact
A listener that static analysis accepted could fail at runtime for the common
case. One that passes
$parameters to a parameter
typed
int
raises a
\Type for every record that is not
edited as an inline child. One that calls a method only
Site
has on
$parameters fails for a record outside any site. One that
types the item of a closure as
array
raises a
\Type for a
field with static items. Static analysis reports such a listener now.
Cast an inline uid and use it only when it is above 0, check the site before
calling a method of
Site
, and type an item as
array:
$parentUid = (int)($parameters['inlineParentUid'] ?? 0);
if ($parentUid > 0) {
// The record is edited as an inline child of a saved parent.
}
$site = $parameters['site'] ?? null;
if ($site instanceof \TYPO3\CMS\Core\Site\Entity\Site) {
$settings = $site->getSettings();
}
$values = array_map(
static fn(array|\TYPO3\CMS\Core\Schema\Struct\SelectItem $item): string => (string)($item['value'] ?? ''),
$parameters['items'],
);
A listener or an item provider of a project can import the alias instead of repeating the shape:
/**
* @phpstan-import-type ItemsProcFuncParameters from \FGTCLB\AcademicBase\Event\ModifyTcaSelectFieldItemsEvent
*/
Affected Installations
Installations with a listener of
\FGTCLB\, or with code
that calls one of the item providers of the academic extensions, that is
checked by static analysis. The listener reports point at code that already
failed or misbehaved at runtime.