data['uid'] ?? 0); if ($parentUid <= 0) { $processedData[$as] = []; return $processedData; } $pid = (int)($cObj->data['pid'] ?? 0); $sysLanguageUid = (int)($cObj->data['sys_language_uid'] ?? 0); $qb = GeneralUtility::makeInstance(ConnectionPool::class) ->getQueryBuilderForTable('tt_content'); $rows = $qb ->select('*') ->from('tt_content') ->where( $qb->expr()->eq('tx_container_parent', $qb->createNamedParameter($parentUid, Connection::PARAM_INT)), $qb->expr()->eq('pid', $qb->createNamedParameter($pid, Connection::PARAM_INT)), $qb->expr()->eq('sys_language_uid', $qb->createNamedParameter($sysLanguageUid, Connection::PARAM_INT)) ) ->orderBy('colPos') ->addOrderBy('sorting') ->executeQuery() ->fetchAllAssociative(); $byColPos = []; foreach ($rows as $record) { $byColPos[(int)$record['colPos']][] = $this->normalise($record); } ksort($byColPos); $items = []; foreach ($byColPos as $colPos => $contentElements) { $items[] = [ 'config' => ['colPos' => $colPos], 'contentElements' => $contentElements, ]; } $processedData[$as] = $items; } catch (\Throwable $e) { $processedData[$as] = []; } return $processedData; } private function normalise(array $record): array { $data = []; foreach ($record as $field => $value) { if (in_array($field, self::ENVELOPE, true)) { continue; } if (in_array($field, self::SYSTEM_FIELDS, true)) { continue; } if ($this->isEmpty($value) && !in_array($field, self::KEEP_IF_ZERO, true)) { continue; } $data[$field] = $this->castValue($field, $value); } return [ 'id' => (int)$record['uid'], 'type' => (string)$record['CType'], 'colPos' => (int)$record['colPos'], 'sorting' => (int)($record['sorting'] ?? 0), 'appearance' => [ 'layout' => (string)($record['layout'] ?? ''), 'frameClass' => (string)($record['frame_class'] ?? 'default'), 'spaceBefore' => (string)($record['space_before_class'] ?? ''), 'spaceAfter' => (string)($record['space_after_class'] ?? ''), ], 'data' => (object)$data, ]; } private function isEmpty(mixed $value): bool { return $value === null || $value === '' || $value === 0 || $value === '0'; } private function castValue(string $field, mixed $value): mixed { if (in_array($field, ['header_layout'], true)) { return (int)$value; } return $value; } }