getQueryParams(); $parsedBody = $request->getParsedBody() ?? []; return new self( fieldReference: (string)($parsedBody['fieldReference'] ?? $queryParams['fieldReference'] ?? ''), allowedTypes: (string)($parsedBody['allowedTypes'] ?? $queryParams['allowedTypes'] ?? ''), disallowedFileExtensions: (string)($parsedBody['disallowedFileExtensions'] ?? $queryParams['disallowedFileExtensions'] ?? ''), irreObjectId: (string)($parsedBody['irreObjectId'] ?? $queryParams['irreObjectId'] ?? ''), useEvents: (bool)(int)($parsedBody['useEvents'] ?? $queryParams['useEvents'] ?? 0), ); } /** * Returns the allowed file extensions as an array. * * @return string[] List of allowed file extensions */ public function getAllowedFileExtensions(): array { if ($this->allowedTypes === '' || $this->allowedTypes === '*') { return []; } // Skip if it looks like a table name (contains underscore typical for TYPO3 tables) if (str_contains($this->allowedTypes, 'sys_file')) { return []; } return GeneralUtility::trimExplode(',', $this->allowedTypes, true); } /** * Returns the disallowed file extensions as an array. * * @return string[] List of disallowed file extensions */ public function getDisallowedFileExtensions(): array { if ($this->disallowedFileExtensions === '') { return []; } return GeneralUtility::trimExplode(',', $this->disallowedFileExtensions, true); } /** * Parses the allowed file extensions from the allowedTypes field. * * @return array{allowed: string[], disallowed: string[]} */ public function getFileExtensions(): array { return [ 'allowed' => $this->getAllowedFileExtensions(), 'disallowed' => $this->getDisallowedFileExtensions(), ]; } /** * Parses the allowed tables from the allowedTypes field. * * @return string[] List of allowed table names */ public function getAllowedTables(): array { if ($this->allowedTypes === '' || $this->allowedTypes === '*') { return []; } return GeneralUtility::trimExplode(',', $this->allowedTypes, true); } /** * Returns the field reference parsed into table name and field name. * * Parses format like "data[tt_content][123][image]" to extract * table name ("tt_content") and field name ("image"). * * @return array{tableName: string, fieldName: string} */ public function getFieldReferenceParts(): array { $result = [ 'tableName' => '', 'fieldName' => '', ]; if ($this->fieldReference === '') { return $result; } // Parse "data[table][uid][field]" format $parts = explode('[', $this->fieldReference); if (count($parts) >= 4) { // parts[1] = "table]", parts[3] = "field]" $result['tableName'] = rtrim($parts[1], ']'); $result['fieldName'] = rtrim($parts[3], ']'); } return $result; } /** * Returns data attributes for use in HTML elements (body tag). * * @return array */ public function toDataAttributes(): array { return [ 'data-field-reference' => $this->fieldReference, 'data-irre-object-id' => $this->irreObjectId ?: null, 'data-use-events' => $this->useEvents ? 'true' : null, ]; } /** * Returns array representation of the parameters. * * @return array{ * fieldReference: string, * allowedTypes: string, * disallowedFileExtensions: string, * irreObjectId: string, * useEvents: bool * } */ public function toArray(): array { return [ 'fieldReference' => $this->fieldReference, 'allowedTypes' => $this->allowedTypes, 'disallowedFileExtensions' => $this->disallowedFileExtensions, 'irreObjectId' => $this->irreObjectId, 'useEvents' => $this->useEvents, ]; } /** * Returns URL query parameters array (new format). * * @return array */ public function toQueryParameters(): array { $params = []; if ($this->fieldReference !== '') { $params['fieldReference'] = $this->fieldReference; } if ($this->allowedTypes !== '') { $params['allowedTypes'] = $this->allowedTypes; } if ($this->disallowedFileExtensions !== '') { $params['disallowedFileExtensions'] = $this->disallowedFileExtensions; } if ($this->irreObjectId !== '') { $params['irreObjectId'] = $this->irreObjectId; } if ($this->useEvents) { $params['useEvents'] = '1'; } return $params; } public function jsonSerialize(): array { return $this->toArray(); } }