Skip to content

Commit

Permalink
[WIP][FEATURE] Support re-definition of File Reference types
Browse files Browse the repository at this point in the history
The table sys_file_reference of TYPO3 is special. It has a type field,
which references a value of another table "sys_file". As these values
are fixed, it is not possible to extend it with custom types. This
means the only possibility is to override the types "showitem" section.

Some adjustments on various places are needed to make this work:
- Handle typeField "uid_local:type"
- Do not prepend a typeField
- Append the hidden palette filePalette
- Prepend overrides of "type"
- Do not call fillTypeFieldSelectItems

todo: Think about a clever syntax for local overrides with
overrideChildTca.

Fixes: #76
  • Loading branch information
nhovratov committed Dec 4, 2024
1 parent 0b23feb commit 6724fcf
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Classes/Definition/Factory/ContentBlockCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ private function prependTypeFieldForRecordType(
ProcessedFieldsResult $result,
bool $isExistingField
): array {
if ($result->contentType->table === 'sys_file_reference') {
return $yamlFields;
}
if ($isExistingField) {
$typeFieldDefinition = [
'identifier' => $result->tableDefinition->typeField,
Expand Down
7 changes: 7 additions & 0 deletions Classes/Generator/TcaGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ protected function fillTypeFieldSelectItems(): void
if ($tableDefinition->getTypeField() === null) {
continue;
}
if ($tableDefinition->getTable() === 'sys_file_reference') {
continue;
}
foreach ($tableDefinition->getContentTypeDefinitionCollection() ?? [] as $typeDefinition) {
$languagePathTitle = $typeDefinition->getLanguagePathTitle();
if ($this->languageFileRegistry->isset($typeDefinition->getName(), $languagePathTitle)) {
Expand Down Expand Up @@ -739,6 +742,10 @@ protected function getRecordTypeStandardShowItem(ContentTypeInterface $typeDefin
if ($showItem !== '') {
$parts[] = $showItem;
}
// Add hidden palette with system fields and uid_local.
if ($tableDefinition->getTable() === 'sys_file_reference') {
$parts[] = '--palette--;;filePalette';
}
if ($this->simpleTcaSchemaFactory->has($tableDefinition->getTable())) {
$tcaSchema = $this->simpleTcaSchemaFactory->get($tableDefinition->getTable());
$capability = new NativeTableCapabilityProxy($tcaSchema);
Expand Down
10 changes: 7 additions & 3 deletions Classes/Schema/SimpleTcaSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,13 @@ protected function buildLanguageCapability(): Capability\LanguageAwareSchemaCapa

public function getTypeField(): ?TcaFieldTypeInterface
{
if (isset($this->schemaConfiguration['type']) && isset($this->fields[$this->schemaConfiguration['type']])) {
return $this->fields[$this->schemaConfiguration['type']];
$type = $this->schemaConfiguration['type'] ?? null;
if ($type === null) {
return null;
}
return null;
if (str_contains($type, ':')) {
$type = explode(':', $type, 2)[0];
}
return $this->fields[$type] ?? null;
}
}
24 changes: 24 additions & 0 deletions ContentBlocks/RecordTypes/my-file-reference/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: nikita/my-file-reference
table: sys_file_reference
typeName: 2
fields:
- identifier: basic
type: Palette
label: LLL:EXT:core/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.imageoverlayPalette
fields:
- identifier: alternative
useExistingField: true
- identifier: description
useExistingField: true
- type: Linebreak
- identifier: link
useExistingField: true
- identifier: title
useExistingField: true
- type: Linebreak
- identifier: custom_field
type: Text
label: My custom Field
- type: Linebreak
- identifier: crop
useExistingField: true

0 comments on commit 6724fcf

Please sign in to comment.