TYPO3 v15 dev-main snapshot ()

This commit is contained in:
2026-08-10 22:31:09 +02:00
commit af8cc155b5
6818 changed files with 642608 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema;
/**
* A relation to another field / schema.
*
* An example:
* - A field "authors" in table "books" has an active relation to the field "written_books" in table "tx_myextension_author"
* - A field "assets" in table "tt_content" has an active relation TO "sys_file_reference.uid".
*/
final readonly class ActiveRelation
{
public function __construct(
private string $toTable,
private ?string $toField
) {}
public function toTable(): string
{
return $this->toTable;
}
public function toField(): ?string
{
return $this->toField;
}
public static function __set_state(array $state): self
{
return new self(...$state);
}
}
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Capability;
use TYPO3\CMS\Core\Schema\Field\FieldTypeInterface;
/**
* Can be used for any kind of field which HAS a definition in the "columns" section of TCA.
*
* Examples:
* - editLock
* - descriptionField
* - any kind of enableFields
*/
final readonly class FieldCapability implements SchemaCapabilityInterface
{
public function __construct(
private FieldTypeInterface $field
) {}
public function getFieldName(): string
{
return $this->field->getName();
}
public function getField(): FieldTypeInterface
{
return $this->field;
}
public function __toString(): string
{
return $this->getFieldName();
}
}
@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Capability;
/**
* Contains all information of compiling the label information of a schema.
*/
final readonly class LabelCapability implements SchemaCapabilityInterface
{
public function __construct(
private ?string $primaryFieldName,
/** @var string[] */
private array $additionalFieldNames,
private bool $alwaysRenderAdditionalFields,
private array $configuration,
) {}
public function getPrimaryFieldName(): ?string
{
return $this->primaryFieldName;
}
public function hasPrimaryField(): bool
{
return $this->primaryFieldName !== null;
}
/**
* @return string[]
*/
public function getAdditionalFieldNames(): array
{
return $this->additionalFieldNames;
}
public function getAllLabelFieldNames(): array
{
return array_unique(array_filter(array_merge([$this->primaryFieldName], $this->additionalFieldNames)));
}
public function alwaysRenderAdditionalFields(): bool
{
return $this->alwaysRenderAdditionalFields;
}
public function getConfiguration(): array
{
return $this->configuration;
}
}
@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Capability;
use TYPO3\CMS\Core\Schema\Field\FieldTypeInterface;
use TYPO3\CMS\Core\Schema\Field\LanguageFieldType;
use TYPO3\CMS\Core\Schema\Field\LanguageTagFieldType;
/**
* Contains all information if a schema is language-aware, meaning
* it has a "languageField", a "translationOrigPointerField", maybe a "translationSourceField"
* and maybe a "diffSourceField".
*/
final readonly class LanguageAwareSchemaCapability implements SchemaCapabilityInterface
{
public function __construct(
private LanguageFieldType $languageField,
private FieldTypeInterface $originPointerField,
private ?FieldTypeInterface $translationSourceField,
private ?FieldTypeInterface $diffSourceField
) {}
/**
* languageField->getName() typically resolves to 'sys_language_uid'
*/
public function getLanguageField(): LanguageFieldType
{
return $this->languageField;
}
public function getLanguageTagField(): LanguageTagFieldType
{
return new LanguageTagFieldType('language_tag');
}
/**
* translationOriginPointerField->getName() typically resolves to 'l10n_parent' or 'l18n_parent'
*/
public function getTranslationOriginPointerField(): FieldTypeInterface
{
return $this->originPointerField;
}
public function hasTranslationSourceField(): bool
{
return $this->translationSourceField !== null;
}
public function getTranslationSourceField(): ?FieldTypeInterface
{
return $this->translationSourceField;
}
/**
* diffSourceField->getName() typically resolves to 'l10n_diffsource' or 'l18n_diffsource'
*/
public function getDiffSourceField(): ?FieldTypeInterface
{
return $this->diffSourceField;
}
public function hasDiffSourceField(): bool
{
return $this->diffSourceField !== null;
}
}
@@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Capability;
/**
* Capability to understand the flag within
* - security.ignoreRootLevelRestriction
*/
final readonly class RootLevelCapability implements SchemaCapabilityInterface
{
public const int TYPE_ONLY_ON_PAGES = 0; // must be on a page (not pid=0)
public const int TYPE_ONLY_ON_ROOTLEVEL = 1; // only allowed on pid=0
public const int TYPE_BOTH = -1; // does not matter
public function __construct(
private int $rootLevelType,
private bool $ignoreRootLevelRestriction
) {}
public function getRootLevelType(): int
{
return $this->rootLevelType;
}
public function shallIgnoreRootLevelRestriction(): bool
{
return $this->ignoreRootLevelRestriction;
}
public function canExistOnRootLevel(): bool
{
return $this->rootLevelType === self::TYPE_BOTH || $this->rootLevelType === self::TYPE_ONLY_ON_ROOTLEVEL;
}
public function canExistOnPages(): bool
{
return $this->rootLevelType === self::TYPE_BOTH || $this->rootLevelType === self::TYPE_ONLY_ON_PAGES;
}
/**
* Allows non-admin users to access records that on the root-level (page-id 0), thus bypassing this usual restriction.
*/
public function canAccessRecordsOnRootLevel(): bool
{
return !$this->rootLevelType || $this->ignoreRootLevelRestriction;
}
}
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Capability;
/**
* Primitive capability that just contains a fixed value.
* Examples:
* - default_sortby
* - versioningWS
* - adminOnly
* - readOnly
* - hideAtCopy
* - hideTable
* - prependAtCopy
*/
final readonly class ScalarCapability implements SchemaCapabilityInterface
{
public function __construct(
private bool|string|int|array|float|null $value = null
) {}
public function getValue(): bool|string|int|array|float|null
{
return $this->value;
}
}
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Capability;
/**
* A semantic interface for any kind of capability.
*/
interface SchemaCapabilityInterface {}
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Capability;
/**
* Can be used for any kind of field which does NOT have
* a definition in the "columns" section of TCA.
*
* -> sortBy
* -> crdate
* -> tstamp
* -> delete
*/
final readonly class SystemInternalFieldCapability implements SchemaCapabilityInterface
{
public function __construct(
private string $fieldName
) {}
public function getFieldName(): string
{
return $this->fieldName;
}
public function __toString(): string
{
return $this->getFieldName();
}
}
@@ -0,0 +1,110 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Capability;
/**
* Contains all capabilities that can be defined in TCA
* and are understandable by the Schema API.
*/
enum TcaSchemaCapability
{
// TCA[ctrl][delete]
case SoftDelete;
// TCA[ctrl][crdate]
case CreatedAt;
// TCA[ctrl][tstamp]
case UpdatedAt;
// TCA[ctrl][sortby]
case SortByField;
// TCA[ctrl][default_sortby]
case DefaultSorting;
// TCA[ctrl][origUid]
case AncestorReferenceField;
// TCA[ctrl][editlock]
case EditLock;
// TCA[ctrl][descriptionColumn]
case InternalDescription;
// TCA[ctrl][language]
case Language;
// TCA[ctrl][workspace]
case Workspace;
// TCA[ctrl][label],TCA[ctrl][label_alt],TCA[ctrl][label_alt_force]...
case Label;
// TCA[ctrl][adminOnly]
case AccessAdminOnly;
// TCA[ctrl][readOnly]
case AccessReadOnly;
// TCA[ctrl][hideAtCopy]
case HideRecordsAtCopy;
// TCA[ctrl][hideTable]
case HideInUi;
// TCA[ctrl][prependAtCopy]
case PrependLabelTextAtCopy;
// TCA[ctrl][enablecolumns][disabled]
case RestrictionDisabledField;
// TCA[ctrl][enablecolumns][starttime]
case RestrictionStartTime;
// TCA[ctrl][enablecolumns][endtime]
case RestrictionEndTime;
// TCA[ctrl][enablecolumns][fe_group]
case RestrictionUserGroup;
// TCA[ctrl][extbase][enableHistoryTracking]
case ExtbaseHistoryTracking;
case RestrictionRootLevel;
// TCA[ctrl][ignoreWebMountRestriction] inverted
case RestrictionWebMount;
private const SYSTEM_CAPABILITIES = [
self::CreatedAt,
self::UpdatedAt,
self::RestrictionStartTime,
self::RestrictionEndTime,
self::SoftDelete,
self::EditLock,
self::RestrictionDisabledField,
self::InternalDescription,
self::SortByField,
self::RestrictionUserGroup,
];
public static function getSystemCapabilities(): array
{
return self::SYSTEM_CAPABILITIES;
}
}
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Exception;
use TYPO3\CMS\Core\Exception;
class FieldTypeNotAvailableException extends Exception {}
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Exception;
use TYPO3\CMS\Core\Exception;
class InvalidSchemaTypeException extends Exception {}
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Exception;
use TYPO3\CMS\Core\Exception;
class UndefinedFieldException extends Exception {}
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Exception;
use TYPO3\CMS\Core\Exception;
class UndefinedSchemaException extends Exception {}
+111
View File
@@ -0,0 +1,111 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
use TYPO3\CMS\Core\DataHandling\TableColumnType;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* A single field definition containing the basic information for a field
*/
abstract readonly class AbstractFieldType implements FieldTypeInterface
{
public function __construct(
protected string $name,
protected array $configuration,
) {}
public static function __set_state(array $state): self
{
/** @phpstan-ignore-next-line Usage is safe because state is exported by PHP var_export() from the static instance */
return new static(...$state);
}
abstract public function getType(): string;
public function getName(): string
{
return $this->name;
}
public function getLabel(): string
{
return (string)($this->configuration['label'] ?? '');
}
public function getDescription(): string
{
return (string)($this->configuration['description'] ?? '');
}
public function supportsAccessControl(): bool
{
return (bool)($this->configuration['exclude'] ?? false);
}
public function isRequired(): bool
{
return (bool)($this->configuration['required'] ?? false);
}
public function isNullable(): bool
{
return (bool)($this->configuration['nullable'] ?? false);
}
abstract public function isSearchable(): bool;
public function getDefaultValue(): mixed
{
return $this->configuration['default'] ?? null;
}
public function hasDefaultValue(): bool
{
return array_key_exists('default', $this->configuration);
}
public function getConfiguration(): array
{
return $this->configuration;
}
public function getTranslationBehaviour(): FieldTranslationBehaviour
{
return FieldTranslationBehaviour::tryFromFieldConfiguration($this->configuration);
}
public function getDisplayConditions(): array|string
{
return $this->configuration['displayCond'] ?? [];
}
public function isType(TableColumnType ...$tableColumnTypes): bool
{
return in_array(TableColumnType::tryFrom($this->getType()), $tableColumnTypes, true);
}
public function getSoftReferenceKeys(): array|false
{
if (!isset($this->configuration['softref'])) {
return false;
}
return GeneralUtility::trimExplode(',', $this->configuration['softref'], true);
}
}
@@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
use TYPO3\CMS\Core\Schema\RelationshipType;
final readonly class CategoryFieldType extends AbstractFieldType implements RelationalFieldTypeInterface
{
public function __construct(
protected string $name,
protected array $configuration,
private array $relations
) {}
public function getType(): string
{
return 'category';
}
public function isSearchable(): false
{
return false;
}
public function getTreeConfiguration(): array
{
return $this->configuration['treeConfig'] ?? [];
}
public function getRelations(): array
{
return $this->relations;
}
public function getRelationshipType(): RelationshipType
{
return RelationshipType::fromTcaConfiguration($this->configuration);
}
public function isNullable(): false
{
return false;
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
final readonly class CheckboxFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'check';
}
public function isSearchable(): false
{
return false;
}
public function isNullable(): false
{
return false;
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
+41
View File
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
final readonly class ColorFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'color';
}
public function supportsOpacity(): bool
{
return (bool)($this->configuration['opacity'] ?? false);
}
public function isSearchable(): bool
{
return (bool)($this->configuration['searchable'] ?? true);
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
+36
View File
@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
final readonly class CountryFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'country';
}
public function isSearchable(): false
{
return false;
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
@@ -0,0 +1,76 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
use TYPO3\CMS\Core\Database\Query\QueryHelper;
final readonly class DateTimeFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'datetime';
}
/**
* native datetime fields are nullable by default, and
* are only not-nullable if `nullable` is explicitly set to false.
*/
public function isNullable(): bool
{
if ($this->getPersistenceType() !== null) {
return $this->configuration['nullable'] ?? true;
}
return parent::isNullable();
}
public function getFormat(): string
{
$format = $this->configuration['format'] ?? null;
$persistenceType = $this->getPersistenceType();
// A native time field must not be formatted as date
if (($format === 'datetime' || $format === 'date') && $persistenceType === 'time') {
return 'timesec';
}
// A native date field must not be formatted as time
if (($format === 'time' || $format === 'timesec') && $persistenceType === 'date') {
return 'date';
}
if (in_array($format, ['datetime', 'date', 'time', 'timesec', 'datetimesec'], true)) {
return $format;
}
if ($persistenceType !== null) {
return $persistenceType === 'time' ? 'timesec' : $persistenceType;
}
return 'datetime';
}
public function isSearchable(): bool
{
return $this->getPersistenceType() === null && ($this->configuration['searchable'] ?? true);
}
public function getPersistenceType(): ?string
{
return in_array($this->configuration['dbType'] ?? null, QueryHelper::getDateTimeTypes(), true) ? $this->configuration['dbType'] : null;
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
final readonly class EmailFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'email';
}
public function isSearchable(): bool
{
return (bool)($this->configuration['searchable'] ?? true);
}
}
+71
View File
@@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
final readonly class FieldCollection implements \ArrayAccess, \IteratorAggregate, \Countable
{
public function __construct(
/**
* @var array<string, FieldTypeInterface> $fieldDefinitions
*/
private array $fieldDefinitions = []
) {}
public static function __set_state(array $state): self
{
return new self(...$state);
}
public function offsetExists(mixed $offset): bool
{
return isset($this->fieldDefinitions[$offset]);
}
public function offsetGet(mixed $offset): ?FieldTypeInterface
{
return $this->fieldDefinitions[$offset] ?? null;
}
public function offsetSet(mixed $offset, mixed $value): void
{
throw new \InvalidArgumentException('Fields cannot be set.', 1712539281);
}
public function offsetUnset(mixed $offset): void
{
throw new \InvalidArgumentException('Fields cannot be unset.', 1712539280);
}
public function getNames(): array
{
return array_keys($this->fieldDefinitions);
}
/**
* @return \Traversable|FieldTypeInterface[]
*/
public function getIterator(): \Traversable
{
return new \ArrayIterator($this->fieldDefinitions);
}
public function count(): int
{
return count($this->fieldDefinitions);
}
}
@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
/**
* Defines possible behaviour scenarios based on TCA settings
* - 'l10n_mode' = exclude
* - 'l10n_mode' = prefixLangTitle
* - none = field is translatable
*/
enum FieldTranslationBehaviour
{
/**
* A field can be translated -> any custom value can be set.
*/
case Translatable;
/**
* A field can be translated. A prefix is prepended on initial localization like this:
* `[Translate to <language name>:]`
*/
case PrefixLanguageTitle;
/**
* A field is excluded from the translation editing - means, it always has the same value
* as the default translation
*/
case Excluded;
public static function tryFromFieldConfiguration(array $fieldConfiguration): self
{
$l10nMode = $fieldConfiguration['l10n_mode'] ?? null;
if ($l10nMode === 'exclude') {
return self::Excluded;
}
if ($l10nMode === 'prefixLangTitle') {
return self::PrefixLanguageTitle;
}
return self::Translatable;
}
}
@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
use TYPO3\CMS\Core\DataHandling\TableColumnType;
/**
* Interface for a Schema Field.
*/
interface FieldTypeInterface
{
public function getType(): string;
public function isType(TableColumnType ...$columnType): bool;
public function getName(): string;
public function getLabel(): string;
public function supportsAccessControl(): bool;
public function isRequired(): bool;
public function isNullable(): bool;
public function isSearchable(): bool;
public function getDisplayConditions(): array|string;
public function getDefaultValue(): mixed;
public function hasDefaultValue(): bool;
public function getTranslationBehaviour(): FieldTranslationBehaviour;
public function getConfiguration(): array;
public function getSoftReferenceKeys(): array|false;
public static function __set_state(array $state): FieldTypeInterface;
}
+83
View File
@@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
use TYPO3\CMS\Core\Schema\RelationshipType;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* This is a field to a "file" (which is very similar to "inline") but with a hard-coded
* selection to sys_file_reference.
*/
final readonly class FileFieldType extends AbstractFieldType implements RelationalFieldTypeInterface
{
public function __construct(
protected string $name,
protected array $configuration,
private array $relations,
) {}
public function getType(): string
{
return 'file';
}
public function getAllowedFileExtensions(): array
{
return is_array($this->configuration['allowed'] ?? null)
? $this->configuration['allowed']
: GeneralUtility::trimExplode(',', $this->configuration['allowed'] ?? '', true);
}
public function getDisallowedFileExtensions(): array
{
return is_array($this->configuration['disallowed'] ?? null)
? $this->configuration['disallowed']
: GeneralUtility::trimExplode(',', $this->configuration['disallowed'] ?? '', true);
}
public function getRelations(): array
{
return $this->relations;
}
public function isSearchable(): false
{
return false;
}
public function getRelationshipType(): RelationshipType
{
return RelationshipType::fromTcaConfiguration($this->configuration);
}
public function isNullable(): false
{
return false;
}
public function hasDefaultValue(): false
{
return false;
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
final readonly class FlexFormFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'flex';
}
public function isSearchable(): bool
{
return (bool)($this->configuration['searchable'] ?? true);
}
public function getDataStructure(): string
{
if (!isset($this->configuration['ds'])) {
return '';
}
return is_string($this->configuration['ds']) ? $this->configuration['ds'] : '';
}
public function isNullable(): false
{
return false;
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
+45
View File
@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
final readonly class FolderFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'folder';
}
public function isSearchable(): false
{
return false;
}
public function isNullable(): false
{
return false;
}
public function hasDefaultValue(): false
{
return false;
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
+59
View File
@@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
use TYPO3\CMS\Core\Schema\RelationshipType;
final readonly class GroupFieldType extends AbstractFieldType implements RelationalFieldTypeInterface
{
public function __construct(
protected string $name,
protected array $configuration,
private array $relations,
) {}
public function getType(): string
{
return 'group';
}
public function isNullable(): false
{
return false;
}
public function getRelations(): array
{
return $this->relations;
}
public function getRelationshipType(): RelationshipType
{
return RelationshipType::fromTcaConfiguration($this->configuration);
}
public function isSearchable(): false
{
return false;
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
final readonly class ImageManipulationFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'imageManipulation';
}
public function isSearchable(): false
{
return false;
}
public function isNullable(): false
{
return false;
}
public function hasDefaultValue(): false
{
return false;
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
+72
View File
@@ -0,0 +1,72 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
use TYPO3\CMS\Core\Schema\RelationshipType;
/**
* This is an "inline" reference field - the "parent" field to a child table / field.
*/
final readonly class InlineFieldType extends AbstractFieldType implements RelationalFieldTypeInterface
{
public function __construct(
protected string $name,
protected array $configuration,
private array $relations
) {}
public function getType(): string
{
return 'inline';
}
public function isSearchable(): false
{
return false;
}
public function getRelations(): array
{
return $this->relations;
}
public function getRelationshipType(): RelationshipType
{
return RelationshipType::fromTcaConfiguration($this->configuration);
}
public function isMovingChildrenEnabled(): bool
{
return (bool)($this->configuration['behaviour']['disableMovingChildrenWithParent'] ?? false) === false;
}
public function isNullable(): false
{
return false;
}
public function hasDefaultValue(): false
{
return false;
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
final readonly class InputFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'input';
}
public function isSearchable(): bool
{
return (bool)($this->configuration['searchable'] ?? true);
}
}
+41
View File
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
final readonly class JsonFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'json';
}
public function isSearchable(): bool
{
return (bool)($this->configuration['searchable'] ?? true);
}
public function isNullable(): false
{
return false;
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
final readonly class LanguageFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'language';
}
public function isSearchable(): false
{
return false;
}
public function isNullable(): false
{
return false;
}
public function hasDefaultValue(): false
{
return false;
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
final readonly class LanguageTagFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'language_tag';
}
public function isSearchable(): true
{
return true;
}
public function isNullable(): true
{
return true;
}
public function hasDefaultValue(): true
{
return true;
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
+36
View File
@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
final readonly class LinkFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'link';
}
public function isSearchable(): bool
{
return (bool)($this->configuration['searchable'] ?? true);
}
public function getAllowedLinkTypes(): array
{
return $this->configuration['allowedTypes'] ?? ['*'];
}
}
+48
View File
@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
use TYPO3\CMS\Core\Schema\FieldFormat;
final readonly class NoneFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'none';
}
public function isSearchable(): false
{
return false;
}
public function getFormat(): FieldFormat
{
return FieldFormat::fromTcaConfiguration($this->configuration);
}
public function hasDefaultValue(): false
{
return false;
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
+41
View File
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
final readonly class NumberFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'number';
}
public function isSearchable(): bool
{
return $this->getFormat() === 'integer';
}
public function getFormat(): string
{
return $this->configuration['format'] ?? '';
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
final readonly class PassthroughFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'passthrough';
}
public function isSearchable(): false
{
return false;
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
final readonly class PasswordFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'password';
}
public function isSearchable(): false
{
return false;
}
public function isHashed(): bool
{
return $this->configuration['hashed'] ?? true;
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
+41
View File
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
final readonly class RadioFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'radio';
}
public function isSearchable(): false
{
return false;
}
public function isNullable(): false
{
return false;
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
use TYPO3\CMS\Core\Schema\ActiveRelation;
use TYPO3\CMS\Core\Schema\RelationshipType;
/**
* Interface for a schema field that has a relation to somewhere else.
*/
interface RelationalFieldTypeInterface
{
/**
* @return ActiveRelation[]
*/
public function getRelations(): array;
public function getRelationshipType(): RelationshipType;
}
@@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
use TYPO3\CMS\Core\Schema\RelationshipType;
/**
* This is a select type with a relation to some other schema.
*/
final readonly class SelectRelationFieldType extends AbstractFieldType implements RelationalFieldTypeInterface
{
public function __construct(
protected string $name,
protected array $configuration,
private array $relations,
) {}
public function getType(): string
{
return 'select';
}
public function getRelations(): array
{
return $this->relations;
}
public function getRelationshipType(): RelationshipType
{
return RelationshipType::fromTcaConfiguration($this->configuration);
}
public function isSearchable(): false
{
return false;
}
public function isNullable(): false
{
return false;
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
+60
View File
@@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
final readonly class SlugFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'slug';
}
public function isSearchable(): bool
{
return (bool)($this->configuration['searchable'] ?? true);
}
public function getGeneratorOption(string $optionName): array|string|bool|null
{
return $this->configuration['generatorOptions'][$optionName] ?? null;
}
public function getGeneratorOptions(): array
{
return is_array($this->configuration['generatorOptions']) ? $this->configuration['generatorOptions'] : [];
}
public function hasDefaultValue(): true
{
return true;
}
public function getDefaultValue(): string
{
return '';
}
public function isNullable(): false
{
return false;
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
use TYPO3\CMS\Core\Schema\Struct\SelectItem;
/**
* This is a select type without any MM or foreign table logic.
*/
final readonly class StaticSelectFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'select';
}
public function isSearchable(): false
{
return false;
}
/**
* @return SelectItem[]
*/
public function getItems(): array
{
return is_array($this->configuration['items'] ?? false) ? array_map(
static fn($item): SelectItem => SelectItem::fromTcaItemArray($item),
$this->configuration['items']
) : [];
}
public function isNullable(): false
{
return false;
}
}
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
/**
* This is used for system-internal fields that haven't been defined in the "columns"
* but need a representation in some areas such as "label_alt".
* @internal This is an experimental implementation.
*/
final readonly class SystemInternalFieldType extends AbstractFieldType
{
public function getType(): string
{
return '';
}
public function isSearchable(): false
{
return false;
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
+36
View File
@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
final readonly class TextFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'text';
}
public function isSearchable(): bool
{
return (bool)($this->configuration['searchable'] ?? true);
}
public function isRichText(): bool
{
return $this->configuration['enableRichtext'] ?? false;
}
}
+41
View File
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
final readonly class UserFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'user';
}
public function getRenderType(): string
{
return $this->configuration['renderType'] ?? '';
}
public function isSearchable(): false
{
return false;
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
+56
View File
@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Field;
final readonly class UuidFieldType extends AbstractFieldType
{
public function getType(): string
{
return 'uuid';
}
public function isSearchable(): bool
{
return (bool)($this->configuration['searchable'] ?? true);
}
public function getVersion(): int
{
return in_array($this->configuration['version'] ?? 0, [4, 6, 7], true) ? $this->configuration['version'] : 4;
}
public function isNullable(): false
{
return false;
}
public function getDefaultValue(): string
{
return '';
}
public function hasDefaultValue(): true
{
return true;
}
public function getSoftReferenceKeys(): false
{
return false;
}
}
+112
View File
@@ -0,0 +1,112 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema;
enum FieldFormat: string
{
case Date = 'date';
case Datetime = 'datetime';
case Time = 'time';
case Timesec = 'timesec';
case Datetimesec = 'datetimesec';
case Year = 'year';
case Int = 'int';
case Float = 'float';
case Number = 'number';
case Md5 = 'md5';
case Filesize = 'filesize';
case User = 'user';
case Undefined = '';
private const FORMAT_CONFIGURATION = [
self::Date->value => [
'strftime',
'option',
'appendAge',
],
self::Int->value => [
'base',
],
self::Float->value => [
'precision',
],
self::Number->value => [
'option',
],
self::Filesize->value => [
'appendByteSize',
],
self::User->value => [
'userFunc',
],
];
public static function fromTcaConfiguration(array $configuration): self
{
if (isset($configuration['config'])) {
$configuration = $configuration['config'];
}
if (isset($configuration['format'])) {
return match ($configuration['format']) {
'date' => self::Date,
'datetime' => self::Datetime,
'time' => self::Time,
'timesec' => self::Timesec,
'datetimesec' => self::Datetimesec,
'year' => self::Year,
'int' => self::Int,
'float' => self::Float,
'number' => self::Number,
'md5' => self::Md5,
'filesize' => self::Filesize,
'user' => self::User,
default => throw new \UnexpectedValueException('Invalid format: ' . $configuration['format'], 1724744407),
};
}
return self::Undefined;
}
public function getFormatConfiguration(array $configuration): array
{
if (isset($configuration['config'])) {
$configuration = $configuration['config'];
}
if (!isset(self::FORMAT_CONFIGURATION[$this->value])
|| !is_array($configuration['format.'] ?? false)
|| $configuration['format.'] === []
) {
return [];
}
return array_filter($configuration['format.'], fn(string $option): bool => in_array($option, self::FORMAT_CONFIGURATION[$this->value], true), ARRAY_FILTER_USE_KEY);
}
}
+174
View File
@@ -0,0 +1,174 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema;
use TYPO3\CMS\Core\Schema\Exception\FieldTypeNotAvailableException;
use TYPO3\CMS\Core\Schema\Field\CategoryFieldType;
use TYPO3\CMS\Core\Schema\Field\CheckboxFieldType;
use TYPO3\CMS\Core\Schema\Field\ColorFieldType;
use TYPO3\CMS\Core\Schema\Field\CountryFieldType;
use TYPO3\CMS\Core\Schema\Field\DateTimeFieldType;
use TYPO3\CMS\Core\Schema\Field\EmailFieldType;
use TYPO3\CMS\Core\Schema\Field\FieldTypeInterface;
use TYPO3\CMS\Core\Schema\Field\FileFieldType;
use TYPO3\CMS\Core\Schema\Field\FlexFormFieldType;
use TYPO3\CMS\Core\Schema\Field\FolderFieldType;
use TYPO3\CMS\Core\Schema\Field\GroupFieldType;
use TYPO3\CMS\Core\Schema\Field\ImageManipulationFieldType;
use TYPO3\CMS\Core\Schema\Field\InlineFieldType;
use TYPO3\CMS\Core\Schema\Field\InputFieldType;
use TYPO3\CMS\Core\Schema\Field\JsonFieldType;
use TYPO3\CMS\Core\Schema\Field\LanguageFieldType;
use TYPO3\CMS\Core\Schema\Field\LinkFieldType;
use TYPO3\CMS\Core\Schema\Field\NoneFieldType;
use TYPO3\CMS\Core\Schema\Field\NumberFieldType;
use TYPO3\CMS\Core\Schema\Field\PassthroughFieldType;
use TYPO3\CMS\Core\Schema\Field\PasswordFieldType;
use TYPO3\CMS\Core\Schema\Field\RadioFieldType;
use TYPO3\CMS\Core\Schema\Field\RelationalFieldTypeInterface;
use TYPO3\CMS\Core\Schema\Field\SelectRelationFieldType;
use TYPO3\CMS\Core\Schema\Field\SlugFieldType;
use TYPO3\CMS\Core\Schema\Field\StaticSelectFieldType;
use TYPO3\CMS\Core\Schema\Field\TextFieldType;
use TYPO3\CMS\Core\Schema\Field\UserFieldType;
use TYPO3\CMS\Core\Schema\Field\UuidFieldType;
/**
* Create field objects based on the TCA of the "columns" area.
*
* A field type is a class that represents a field in a schema.
*
* Currently, the FieldTypes are hard-coded in this class, but in the future, this might be moved
* into a more flexible registry.
*
* Also, the class currently encapsulates the building of the FlexFormSchema (which in turn also has
* fields), however, since this has some tight coupling this resides here for the time being,
* but should be extracted later-on.
*
* Some interesting points:
* - the special type "select" is separated into two different classes - one with relations, and one without.
*/
class FieldTypeFactory
{
/**
* @var array<string, class-string<FieldTypeInterface>>
*/
protected array $availableFieldTypes = [
'category' => CategoryFieldType::class,
'check' => CheckboxFieldType::class,
'color' => ColorFieldType::class,
'country' => CountryFieldType::class,
'datetime' => DateTimeFieldType::class,
'email' => EmailFieldType::class,
'file' => FileFieldType::class,
'flex' => FlexFormFieldType::class,
'folder' => FolderFieldType::class,
'group' => GroupFieldType::class,
'imageManipulation' => ImageManipulationFieldType::class,
'inline' => InlineFieldType::class,
'input' => InputFieldType::class,
'json' => JsonFieldType::class,
'language' => LanguageFieldType::class,
'link' => LinkFieldType::class,
'none' => NoneFieldType::class,
'number' => NumberFieldType::class,
'passthrough' => PassthroughFieldType::class,
'password' => PasswordFieldType::class,
'radio' => RadioFieldType::class,
'slug' => SlugFieldType::class,
'text' => TextFieldType::class,
'user' => UserFieldType::class,
'uuid' => UuidFieldType::class,
];
public function createFieldType(string $fieldName, array $configuration, string $schemaName, RelationMap $relationMap, ?string $parentSchemaName = null, ?string $parentFieldName = null): FieldTypeInterface
{
$fieldType = $configuration['config']['type'] ?? '';
switch ($fieldType) {
case 'flex':
// Build all schemata first
return $this->createFlexFormField($parentSchemaName ?? $schemaName, $fieldName, $configuration, $relationMap, $parentSchemaName ? $schemaName : null);
case 'select':
// In case type "select" is used without any relationship information, it's a static list
if (RelationshipType::fromTcaConfiguration($configuration) === RelationshipType::Undefined) {
return $this->createFromTca(StaticSelectFieldType::class, $fieldName, $configuration);
}
return $this->createFromTca(SelectRelationFieldType::class, $fieldName, $configuration, $relationMap->getActiveRelations($parentSchemaName ?? $schemaName, $parentFieldName ?? $fieldName));
default:
if ($this->hasFieldType($fieldType)) {
$fieldTypeClass = $this->availableFieldTypes[$fieldType];
if (is_a($fieldTypeClass, RelationalFieldTypeInterface::class, true)) {
return $this->createFromTca($fieldTypeClass, $fieldName, $configuration, $relationMap->getActiveRelations($parentSchemaName ?? $schemaName, $parentFieldName ?? $fieldName));
}
return $this->createFromTca($fieldTypeClass, $fieldName, $configuration);
}
throw new FieldTypeNotAvailableException('Field type "' . $fieldType . '" for field "' . $fieldName . '" not found for schema "' . $schemaName . '".', 1661532580);
}
}
protected function hasFieldType(string $fieldType): bool
{
return array_key_exists($fieldType, $this->availableFieldTypes);
}
/**
* Basic factory to create the field type from the TCA configuration via new().
*/
protected function createFromTca(string $targetClass, string $fieldName, array $fieldConfiguration, ?array $relations = null): FieldTypeInterface
{
// We deliberately reduce the "config" subarray to make life easier in the future
$fieldConfiguration = $this->streamlineFieldConfiguration($fieldConfiguration);
$arguments = [
$fieldName,
$fieldConfiguration,
];
if ($relations !== null) {
$arguments[] = $relations;
}
return new $targetClass(...$arguments);
}
/**
* First, parse the data structures (and if we only have a subschema, we use that one, ofc)
*/
protected function createFlexFormField(string $mainSchemaName, string $fieldName, array $tcaConfig, RelationMap $relationMap, ?string $subSchemaName = null): FlexFormFieldType
{
$tcaConfig = $this->streamlineFieldConfiguration($tcaConfig);
// This is the place to get all schema / data structures but should be called somewhere else, probably
// in user-land code
// @todo: this should go away, or FlexFormSchemaFactory should be removed altogether
// $flexSchemas = GeneralUtility::makeInstance(FlexFormSchemaFactory::class)->createSchemataForFlexField($tcaConfig, $mainSchemaName, $fieldName, $relationMap);
return new FlexFormFieldType(
$fieldName,
$tcaConfig,
);
}
/**
* Removes the "config" subkey from TCA, to make it easier to work with the configuration array,
* also makes caching smaller.
*/
protected function streamlineFieldConfiguration(array $fieldConfiguration): array
{
$configSubArrayInfo = $fieldConfiguration['config'] ?? null;
unset($fieldConfiguration['config']);
return array_replace_recursive($configSubArrayInfo ?? [], $fieldConfiguration);
}
}
+143
View File
@@ -0,0 +1,143 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema;
use TYPO3\CMS\Core\Schema\Field\FieldCollection;
use TYPO3\CMS\Core\Schema\Field\FieldTypeInterface;
use TYPO3\CMS\Core\Schema\Struct\FlexSheet;
final readonly class FlexFormSchema implements SchemaInterface
{
public function __construct(
private string $structIdentifier,
/** @var FlexSheet[] */
private array $sheets
) {}
public function getSheets(): array
{
return $this->sheets;
}
public function getFields(?callable $filterFunction = null): FieldCollection
{
$allFields = [];
foreach ($this->sheets as $sheet) {
$allFields = array_merge($allFields, iterator_to_array($sheet->getFields()));
}
if ($filterFunction === null) {
return new FieldCollection($allFields);
}
return new FieldCollection(array_filter(iterator_to_array($allFields), $filterFunction));
}
public function getName(): string
{
return $this->structIdentifier;
}
public function getField(string $fieldName, ?string $sheetName = null): ?FieldTypeInterface
{
if ($sheetName !== null) {
return $this->getFieldFromSheet($sheetName, $fieldName);
}
foreach ($this->sheets as $name => $sheet) {
if ($field = $this->getFieldFromSheet($name, $fieldName)) {
return $field;
}
}
return null;
}
public static function __set_state(array $state): self
{
return new self(...$state);
}
/**
* This method attempts to find a field within a given sheet.
*
* If the field is not set directly on the sheet, each section
* of the sheet will be checked for a matching field.
*/
private function getFieldFromSheet(string $sheetName, string $fieldName): ?FieldTypeInterface
{
if (!isset($this->sheets[$sheetName])) {
return null;
}
$sheet = $this->sheets[$sheetName];
if ($sheet->hasField($sheetName . '/' . $fieldName)) {
return $sheet->getField($sheetName . '/' . $fieldName);
}
return $this->getFieldFromSections($sheetName, $fieldName);
}
/**
* This method searches for a field name within all sections of a sheet.
*
* Any slashes in the field name, section name, or container name
* are replaced with dots to support field names such as:
* - settings.mysettings.67fb88e136a4a575936...
* - my_settings.67fb88e136a4a575936...
*/
private function getFieldFromSections(string $sheetName, string $fieldName): ?FieldTypeInterface
{
$sheet = $this->sheets[$sheetName];
$fieldPath = $sheetName . '.' . $fieldName;
foreach ($sheet->getSections() as $sectionName => $section) {
$sectionPath = str_replace('/', '.', $sectionName);
// If the field is not inside the current section, continue to the next
if (!str_starts_with($fieldPath, $sectionPath)) {
continue;
}
// Remove the section path from the field name
$relativeField = substr($fieldPath, strlen($sectionPath) + 1);
if (($pos = strpos($relativeField, '.')) !== false) {
// Get the container name from the field
$containerField = substr($relativeField, $pos + 1);
foreach ($section as $containerName => $container) {
// If the field is not inside the current container, continue to the next
if (!str_starts_with($sectionName . '/' . $containerField, $containerName)) {
continue;
}
// Get the field name
$finalFieldName = substr($sectionName . '/' . $containerField, strlen($containerName) + 1);
/** @var \TYPO3\CMS\Core\Schema\Struct\FlexSectionContainer $container */
if ($container->hasField($finalFieldName)) {
return $container->getField($finalFieldName);
}
}
}
}
return null;
}
}
+121
View File
@@ -0,0 +1,121 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema;
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use TYPO3\CMS\Core\Configuration\FlexForm\Exception\InvalidIdentifierException;
use TYPO3\CMS\Core\Configuration\FlexForm\Exception\InvalidTcaException;
use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools;
use TYPO3\CMS\Core\Domain\RawRecord;
use TYPO3\CMS\Core\Schema\Exception\UndefinedSchemaException;
use TYPO3\CMS\Core\Schema\Field\FieldCollection;
use TYPO3\CMS\Core\Schema\Field\FlexFormFieldType;
use TYPO3\CMS\Core\Schema\Struct\FlexSectionContainer;
use TYPO3\CMS\Core\Schema\Struct\FlexSheet;
/**
* Parses all possibles schemas of all sheets of a field.
*/
#[Autoconfigure(public: true, shared: true)]
final readonly class FlexFormSchemaFactory
{
public function __construct(
private FlexFormTools $flexFormTools,
private FieldTypeFactory $fieldTypeFactory,
private TcaSchemaFactory $tcaSchemaFactory,
) {}
/**
* Currently this mixes Schema and Record Information, and could be handled in a cleaner way.
* This method signature will most likely change.
*/
public function getSchemaForRecord(RawRecord $record, FlexFormFieldType $field, RelationMap $relationMap): ?FlexFormSchema
{
try {
$schema = $this->tcaSchemaFactory->get($record->getMainType());
$dataStructureIdentifier = $this->flexFormTools->getDataStructureIdentifier(
['config' => $field->getConfiguration()],
$record->getMainType(),
$field->getName(),
$record->toArray(),
$schema
);
$resolvedDataStructure = $this->flexFormTools->parseDataStructureByIdentifier($dataStructureIdentifier, $schema);
} catch (InvalidTcaException|InvalidIdentifierException|UndefinedSchemaException) {
return null;
}
$sheets = [];
foreach ($resolvedDataStructure['sheets'] ?? [] as $sheetIdentifier => $sheetData) {
$fields = [];
$sections = [];
foreach ($sheetData['ROOT']['el'] ?? [] as $flexFieldName => $flexFieldConfig) {
$fieldIdentifier = $sheetIdentifier . '/' . $flexFieldName;
if (($flexFieldConfig['type'] ?? '') === 'array' && ($flexFieldConfig['section'] ?? false)) {
// We are inside a section, now loop over the section containers
$sectionContainers = [];
foreach ($flexFieldConfig['el'] ?? [] as $sectionContainerIdentifier => $sectionContainerDetails) {
// Sections can only have section containers
if (($sectionContainerDetails['type'] ?? '') !== 'array') {
continue;
}
$sectionFieldIdentifier = $fieldIdentifier . '/' . $sectionContainerIdentifier;
$fieldsInSectionContainer = [];
$sectionContainerTitle = $sectionContainerDetails['title'] ?? '';
// Collect all elements within this section container
foreach ($sectionContainerDetails['el'] ?? [] as $fieldNameInSectionContainer => $sectionContainerConfig) {
$fieldsInSectionContainer[$fieldNameInSectionContainer] = $this->fieldTypeFactory->createFieldType(
$fieldNameInSectionContainer,
$sectionContainerConfig ?? [],
$record->getMainType(),
$relationMap,
null,
$field->getName()
);
}
$sectionContainers[$sectionFieldIdentifier] = new FlexSectionContainer(
$sectionFieldIdentifier,
$sectionContainerTitle,
'',
new FieldCollection($fieldsInSectionContainer)
);
}
$sections[$fieldIdentifier] = $sectionContainers;
} else {
$fields[$fieldIdentifier] = $this->fieldTypeFactory->createFieldType(
$fieldIdentifier,
$flexFieldConfig ?? [],
$record->getMainType(),
$relationMap,
null,
$field->getName()
);
}
}
$fields = new FieldCollection($fields);
$sheets[$sheetIdentifier] = new FlexSheet(
$sheetIdentifier,
$sheetData['ROOT']['sheetTitle'] ?? '',
$sheetData['ROOT']['sheetDescription'] ?? '',
$fields,
$sections
);
}
return new FlexFormSchema($dataStructureIdentifier, $sheets);
}
}
+50
View File
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema;
/**
* A relation from another field / schema.
*
* Examples:
* - A table "tx_myextension_author" has a passive relation FROM the table "tx_books" and its field "authors".
* - A TCA table of type inline has a passthrough field in the child table, and that's a PASSIVE relation FROM the
* parent table.
*/
final readonly class PassiveRelation
{
public function __construct(
private string $fromTable,
private ?string $fromField,
private ?string $flexPointer,
) {}
public function fromTable(): string
{
return $this->fromTable;
}
public function fromField(): ?string
{
return $this->fromField;
}
public static function __set_state(array $state): self
{
return new self(...$state);
}
}
+151
View File
@@ -0,0 +1,151 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* A class to collect actual relations. Contains all information...
* -> what is the target of a relation of a field
* -> what is pointing to a specific schema
*
* @internal not part of TYPO3 API as it should not be exposed, although this is really cool and powerful.
*/
final class RelationMap
{
public function __construct(
private array $relations = []
) {}
public function add(string $fromTable, string $fromFieldName, array $fieldConfig, ?string $flexPointer = null): void
{
$fieldType = $fieldConfig['type'] ?? null;
if ($fieldType === 'group') {
$toTables = GeneralUtility::trimExplode(',', $fieldConfig['allowed'] ?? $fieldConfig['foreign_table'] ?? '');
foreach ($toTables as $toTable) {
if (isset($fieldConfig['MM'])) {
$this->addMMRelation(
$fromTable,
$fromFieldName,
$toTable,
$fieldConfig['MM'],
$fieldConfig['MM_opposite_field'] ?? null,
$flexPointer
);
} else {
$this->addActiveRelationToTable($fromTable, $fromFieldName, $toTable, $flexPointer);
}
}
} elseif (in_array($fieldType, ['select', 'inline', 'file', 'category'], true)) {
if (isset($fieldConfig['MM'])) {
$this->addMMRelation(
$fromTable,
$fromFieldName,
$fieldConfig['foreign_table'],
$fieldConfig['MM'],
$fieldConfig['MM_opposite_field'] ?? null,
$flexPointer
);
} elseif (isset($fieldConfig['foreign_table'], $fieldConfig['foreign_field'])) {
$this->addActiveRelationWithField(
$fromTable,
$fromFieldName,
$fieldConfig['foreign_table'],
$fieldConfig['foreign_field'],
$flexPointer
);
} elseif (isset($fieldConfig['foreign_table'])) {
$this->addActiveRelationToTable(
$fromTable,
$fromFieldName,
$fieldConfig['foreign_table'],
$flexPointer
);
}
// @todo: I guess we also need to do the foreign_table_field option
}
}
private function addMMRelation(string $fromTable, string $fromField, string $toTable, string $mm, ?string $mmOppositeField = null, ?string $flexPointer = null): void
{
$this->relations[$fromTable][$fromField][] = [
'target' => $toTable,
'mm' => $mm,
'mmOppositeField' => $mmOppositeField,
'flexPointer' => $flexPointer,
];
}
private function addActiveRelationWithField(string $fromTable, string $fromField, string $toTable, string $toField, ?string $flexPointer = null): void
{
$this->relations[$fromTable][$fromField][] = [
'target' => $toTable,
'targetField' => $toField,
'flexPointer' => $flexPointer,
];
}
private function addActiveRelationToTable(string $fromTable, string $fromField, string $toTable, ?string $flexPointer = null): void
{
$this->relations[$fromTable][$fromField][] = [
'target' => $toTable,
'flexPointer' => $flexPointer,
];
}
/**
* @return ActiveRelation[]
*/
public function getActiveRelations(string $tableName, string $fieldName): array
{
return array_map([$this, 'makeActiveRelation'], $this->relations[$tableName][$fieldName] ?? []);
}
private function makeActiveRelation(array $relation): ActiveRelation
{
return new ActiveRelation($relation['mm'] ?? $relation['target'], $relation['mmOppositeField'] ?? $relation['targetField'] ?? null);
}
/**
* Passive relations can never be pointed to a field within a FlexSchema
*/
public function getPassiveRelations(string $tableName, ?string $fieldName = null): array
{
$relations = [];
foreach ($this->relations as $fromTable => $fields) {
foreach ($fields as $fromField => $relation) {
foreach ($relation as $rel) {
// target table does not match
if (!in_array($rel['target'], [$tableName, '*'], true)) {
continue;
}
// restriction to field is set, if this is set, this must match the targetField
// otherwise we include all relations to the target table (regardless if it is attached to a field or not)
// because we want to get the passive relations for the table.
if ($fieldName !== null) {
if (!isset($rel['targetField']) || $rel['targetField'] !== $fieldName) {
continue;
}
}
$relations[] = new PassiveRelation($fromTable, $fromField, $rel['flexPointer'] ?? null);
}
}
}
return $relations;
}
}
+94
View File
@@ -0,0 +1,94 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema;
use TYPO3\CMS\Core\Configuration\FlexForm\Exception\InvalidDataStructureException;
use TYPO3\CMS\Core\Configuration\FlexForm\Exception\InvalidIdentifierException;
use TYPO3\CMS\Core\Configuration\FlexForm\Exception\InvalidTcaSchemaException;
use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools;
/**
* Low-level API to parse TCA to find field types which should be processed, as they contain
* a relation.
*
* This also parses ALL flexforms available, that's why it juggles through all FlexForm
* fields and parses the FlexForms as well.
*
* Everything is stored in a simple "RelationMap" object with an internal array structure.
*
* @internal not part of TYPO3 API as it should not be exposed, although this is really cool and powerful.
*/
final readonly class RelationMapBuilder
{
public function __construct(
private FlexFormTools $flexFormTools
) {}
public function buildFromStructure(array $tca): RelationMap
{
$relationMap = new RelationMap();
foreach ($tca as $table => $tableConfig) {
// What fields can have a relational connection to other tables?
foreach ($tableConfig['columns'] ?? [] as $fieldName => $fieldConfig) {
$fieldConfig = $fieldConfig['config'] ?? null;
if (!in_array($fieldConfig['type'] ?? '', ['select', 'group', 'inline', 'file', 'category', 'flex'], true)) {
continue;
}
if ($fieldConfig['type'] === 'flex') {
$this->addRelationsForFlexFieldToRelationMap($table, $tableConfig, $fieldName, $relationMap);
} else {
$relationMap->add($table, $fieldName, $fieldConfig);
}
}
}
return $relationMap;
}
/**
* Adds relations for a flex field to the relation map.
* Note: Inside a section, it is not possible to add a field with a relation (type 'inline', 'file', 'folder', 'group', 'category').
* See TcaFlexProcess class for details.
*/
private function addRelationsForFlexFieldToRelationMap(string $tableName, array $tableConfig, string $fieldName, RelationMap $relationMap): void
{
foreach (array_merge(['default'], array_keys($tableConfig['types'] ?? [])) as $recordType) {
try {
$dataStructure = $this->flexFormTools->parseDataStructureByIdentifier(json_encode([
'type' => 'tca',
'tableName' => $tableName,
'fieldName' => $fieldName,
'dataStructureKey' => $recordType,
]), $tableConfig);
} catch (InvalidTcaSchemaException|InvalidIdentifierException|InvalidDataStructureException) {
// Skip default on error
continue;
}
if (!is_array($dataStructure['sheets'] ?? null)) {
continue;
}
foreach ($dataStructure['sheets'] as $sheetIdentifier => $sheet) {
foreach ($sheet['ROOT']['el'] as $flexFieldName => $flexFieldConfig) {
$fieldIdentifier = $sheetIdentifier . '/' . $flexFieldName;
$relationMap->add($tableName, $fieldName, $flexFieldConfig['config'] ?? [], $fieldIdentifier);
}
}
}
}
}
+86
View File
@@ -0,0 +1,86 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema;
enum RelationshipType: string
{
// A direct relation, e.g. sys_file.metadata => sys_file_metadata
case OneToOne = '1:1';
// A record with active relations, e.g. inline elements blog_article.comments => comment. The reference
// to the left side is stored in a pointer field in the right side. Typically used when 'foreign_field' is set.
case OneToMany = '1:n';
// One item is selected on the active site, e.g. be_users.avatar => file, while file can be selected by any user
case ManyToOne = 'n:1';
// Regular MM intermediate table is used to store data
case ManyToMany = 'mm';
// An item list (separated by comma) is stored (like select type is doing)
case List = 'list';
// Type can not be defined
case Undefined = '';
public static function fromTcaConfiguration(array $configuration): self
{
if (isset($configuration['config'])) {
$configuration = $configuration['config'];
}
if (isset($configuration['MM'])) {
return self::ManyToMany;
}
if (isset($configuration['relationship'])) {
return match ($configuration['relationship']) {
'oneToOne' => self::OneToOne,
'oneToMany' => self::OneToMany,
'manyToOne' => self::ManyToOne,
default => throw new \UnexpectedValueException('Invalid relationship type: ' . $configuration['relationship'], 1724661829),
};
}
if (isset($configuration['foreign_field'])) {
return self::OneToMany;
}
if (isset($configuration['foreign_table'])) {
// ManyToOne (as with `renderType=selectSingle`) is
// handled by `relationship` configuration above.
// See `TcaPreparation::configureSelectSingle()`.
return self::List;
}
if (($configuration['type'] ?? '') === 'group') {
return self::List;
}
return self::Undefined;
}
public function hasOne(): bool
{
return in_array($this, [self::OneToOne, self::ManyToOne], true);
}
public function hasMany(): bool
{
return in_array($this, [self::ManyToMany, self::OneToMany, self::List], true);
}
public function isSingularRelationship(): bool
{
return in_array($this, [self::OneToOne, self::ManyToOne, self::OneToMany, self::List], true);
}
}
+108
View File
@@ -0,0 +1,108 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema;
use TYPO3\CMS\Core\Schema\Exception\UndefinedSchemaException;
final readonly class SchemaCollection implements \ArrayAccess, \IteratorAggregate, \Countable
{
public function __construct(
/**
* @var array<string, SchemaInterface>
*/
private array $items
) {}
public function offsetExists(mixed $offset): bool
{
return isset($this->items[$offset]);
}
public function offsetGet(mixed $offset): mixed
{
return $this->items[$offset];
}
public function offsetSet(mixed $offset, mixed $value): void
{
throw new \InvalidArgumentException('A schema cannot be set.', 1712539286);
}
public function offsetUnset(mixed $offset): void
{
throw new \InvalidArgumentException('A schema cannot be unset.', 1712539285);
}
public function getIterator(): \Traversable
{
return new \ArrayIterator($this->items);
}
public function count(): int
{
return count($this->items);
}
/**
* @return string[]
*/
public function getNames(): array
{
return array_values(array_map(fn($item): string => $item->getName(), $this->items));
}
/**
* Get a schema from the loaded TCA. Ensure to check for a schema with ->has() before
* calling ->get().
*/
public function get(string $schemaName): TcaSchema
{
if (!$this->has($schemaName)) {
throw new UndefinedSchemaException('No TCA schema exists for the name "' . $schemaName . '".', 1661540376);
}
if (str_contains($schemaName, '.')) {
[$mainSchema, $subSchema] = explode('.', $schemaName, 2);
return $this->get($mainSchema)->getSubSchema($subSchema);
}
if (!$this->items[$schemaName] instanceof TcaSchema) {
throw new \RuntimeException('The schema "' . $schemaName . '" is not of type TcaSchema.', 1773758542);
}
return $this->items[$schemaName];
}
/**
* Checks if a schema exists, does not build the schema if not needed, thus it's very slim
* and only creates a schema if a sub-schema is requested.
*/
public function has(string $schemaName): bool
{
if (str_contains($schemaName, '.')) {
[$mainSchema, $subSchema] = explode('.', $schemaName, 2);
if (!$this->has($mainSchema)) {
return false;
}
return $this->get($mainSchema)->hasSubSchema($subSchema);
}
return isset($this->items[$schemaName]);
}
public static function __set_state(array $state): self
{
return new self(...$state);
}
}
+33
View File
@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema;
use TYPO3\CMS\Core\Schema\Field\FieldCollection;
/**
* A generic interface for any kind of schema
* @internal this will be made public once FormEngine is using Schema API.
*/
interface SchemaInterface
{
public function getName(): string;
//public function getFields(?callable $filterFunction = null): FieldCollection;
//public function hasField(string $fieldName): bool;
public static function __set_state(array $state): SchemaInterface;
}
+188
View File
@@ -0,0 +1,188 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema;
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use TYPO3\CMS\Core\DataHandling\ItemProcessingService;
use TYPO3\CMS\Core\DataHandling\ItemsProcessorContext;
use TYPO3\CMS\Core\Schema\Struct\SelectItemCollection;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Resolves labels for TCA field items based on schema configuration
* and optional Page TSconfig overrides.
*
* Returns raw (untranslated) labels — callers are responsible for
* running language translation (e.g. sL()) when needed.
*/
#[Autoconfigure(public: true)]
readonly class SchemaLabelResolver
{
public function __construct(
private TcaSchemaFactory $tcaSchemaFactory,
private ItemProcessingService $itemProcessingService,
) {}
/**
* Resolve the label for a single field item value.
*
* @param string $table Table name
* @param string $field Field name
* @param string $value The item value to look up
* @param array $row Record row, needed for itemsProcFunc/itemsProcessors context
* @param array $columnTsConfig Optional TCEFORM.<table>.<field> TSconfig array for addItems/altLabels overrides
* @param array $fieldConfiguration Optional explicit field configuration (used for volatile configs like FlexForms)
* @return string The raw (untranslated) label, or empty string if not found
*/
public function getLabelForFieldValue(
string $table,
string $field,
string $value,
array $row = [],
array $columnTsConfig = [],
array $fieldConfiguration = [],
): string {
if ($columnTsConfig !== []) {
$tsConfigLabel = $this->resolveFromTsConfig($value, $columnTsConfig);
if ($tsConfigLabel !== null) {
return $tsConfigLabel;
}
}
$fieldConfiguration = $this->resolveFieldConfiguration($table, $field, $fieldConfiguration);
if ($fieldConfiguration === []) {
return '';
}
$items = $this->resolveItems($table, $field, $row, $fieldConfiguration);
foreach ($items as $itemConfiguration) {
if ((string)$itemConfiguration['value'] === $value) {
return $itemConfiguration['label'];
}
}
return '';
}
/**
* Resolve labels for a comma-separated list of field item values.
*
* @param string $table Table name
* @param string $field Field name
* @param string $valueList Comma-separated list of item values
* @param array $row Record row, needed for itemsProcFunc/itemsProcessors context
* @param array $columnTsConfig Optional TCEFORM.<table>.<field> TSconfig array for addItems/altLabels overrides
* @param array $fieldConfiguration Optional explicit field configuration (used for volatile configs like FlexForms)
* @return array<string> Array of raw (untranslated) labels for each matched value
*/
public function getLabelsForFieldValues(
string $table,
string $field,
string $valueList,
array $row = [],
array $columnTsConfig = [],
array $fieldConfiguration = [],
): array {
$fieldConfiguration = $this->resolveFieldConfiguration($table, $field, $fieldConfiguration);
if ($valueList === '' || $fieldConfiguration === []) {
return [];
}
$items = $this->resolveItems($table, $field, $row, $fieldConfiguration);
$keys = GeneralUtility::trimExplode(',', $valueList);
$labels = [];
foreach ($keys as $key) {
$label = null;
if ($columnTsConfig !== []) {
$label = $this->resolveFromTsConfig($key, $columnTsConfig);
}
if ($label === null) {
foreach ($items as $itemConfiguration) {
if ($key === (string)$itemConfiguration['value']) {
$label = $itemConfiguration['label'];
break;
}
}
}
if ($label !== null) {
$labels[] = $label;
}
}
return $labels;
}
private function resolveFromTsConfig(string $value, array $columnTsConfig): ?string
{
if ($value === '' && isset($columnTsConfig['altLabels'])) {
return $columnTsConfig['altLabels'];
}
if (isset($columnTsConfig['addItems.'][$value])) {
return $columnTsConfig['addItems.'][$value];
}
if (isset($columnTsConfig['altLabels.'][$value])) {
return $columnTsConfig['altLabels.'][$value];
}
return null;
}
private function resolveFieldConfiguration(string $table, string $field, array $fieldConfiguration): array
{
if ($fieldConfiguration !== []) {
return $fieldConfiguration;
}
if (!$this->tcaSchemaFactory->has($table)) {
return [];
}
$schema = $this->tcaSchemaFactory->get($table);
if (!$schema->hasField($field)) {
return [];
}
return $schema->getField($field)->getConfiguration();
}
private function resolveItems(string $table, string $field, array $row, array $fieldConfiguration): array
{
if (isset($fieldConfiguration['items']) && !is_array($fieldConfiguration['items'])) {
return [];
}
$items = $fieldConfiguration['items'] ?? [];
if (
($fieldConfiguration['itemsProcFunc'] ?? '') !== ''
|| ($fieldConfiguration['itemsProcessors'] ?? []) !== []
) {
$itemsCollection = SelectItemCollection::createFromArray($items, $fieldConfiguration['type']);
$context = new ItemsProcessorContext(
table: $table,
field: $field,
row: $row,
fieldConfiguration: $fieldConfiguration,
processorParameters: [],
realPid: (int)($row['pid'] ?? 0),
site: $this->itemProcessingService->resolveSite((int)($row['pid'] ?? 0))
);
$items = $this->itemProcessingService->processItems($itemsCollection, $context)->toArray();
}
return $items;
}
}
+63
View File
@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema;
/**
* It is possible to use a DB field in TCA for referencing the actual type of record, by dividing the schema
* in subschema by a type. For example, "pages" has a "type" field which references the "doktype" field
* of the "pages" table. This is defined in TCA[ctrl][type] property.
*
* However, it is also possible to use a field of a foreign table to define the type of record -
* for example - the "sys_file_reference" table has type "uid_foreign:title". The uid_foreign DB field
* of "sys_file_reference" references the "uid" field of the "sys_file" table (as defined in the "uid_foreign" field
* of "sys_file_reference", and the "title" field is then pointing to the related references' schema
*/
final readonly class SchemaTypeInformation
{
public function __construct(
private string $schemaName,
private string $fieldName,
private ?string $foreignFieldName = null,
private ?string $foreignSchemaName = null
) {}
public function isPointerToForeignFieldInForeignSchema(): bool
{
return $this->foreignFieldName !== null && $this->foreignSchemaName !== null;
}
public function getSchemaName(): string
{
return $this->schemaName;
}
public function getFieldName(): string
{
return $this->fieldName;
}
public function getForeignSchemaName(): ?string
{
return $this->foreignSchemaName;
}
public function getForeignFieldName(): ?string
{
return $this->foreignFieldName;
}
}
@@ -0,0 +1,103 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema;
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use TYPO3\CMS\Core\Schema\Field\FieldCollection;
use TYPO3\CMS\Core\Schema\Field\FieldTypeInterface;
/**
* Class that accesses the TCA[table][searchFields] via TcaSchema factory
*/
#[Autoconfigure(public: true)]
readonly class SearchableSchemaFieldsCollector
{
public function __construct(private TcaSchemaFactory $schemaFactory) {}
public function getFields(string $schemaName, array $searchFields = []): FieldCollection
{
if (!$this->schemaFactory->has($schemaName)) {
return new FieldCollection();
}
$schema = $this->schemaFactory->get($schemaName);
return $searchFields === []
// No searchFields defined, return all searchable fields
? $schema->getFields(static fn(FieldTypeInterface $field): bool => $field->isSearchable())
// Return given searchFields by filtering whether they are actually searchable
: $schema->getFields(static fn(FieldTypeInterface $field): bool => in_array($field->getName(), $searchFields, true) && $field->isSearchable());
}
/**
* @return string[]
*/
public function getFieldNames(string $schemaName, array $searchFields = []): array
{
return array_map(static fn(FieldTypeInterface $field) => $field->getName(), iterator_to_array($this->getFields($schemaName, $searchFields)));
}
/**
* @return string[]
*/
public function getUniqueFieldList(string $schemaName, array $existingFieldList, bool $includeSpecialFields): array
{
// Add special fields
if ($includeSpecialFields) {
$existingFieldList[] = 'uid';
$existingFieldList[] = 'pid';
}
// @todo should existing fields also be validated?
return array_unique(array_merge($existingFieldList, $this->getFieldNames($schemaName)));
}
/**
* Returns table subschema divisor field name and a list of fields not included in all subSchemas along with
* the list of subSchemas they are included.
*
* @param string $tableName
* @return array{0: string, 1: array<string, list<string>>}
* @internal only to be used in TYPO3 Core
*/
public function getSchemaFieldSubSchemaTypes(string $tableName): array
{
$result = [
0 => '',
1 => [],
];
if (!$this->schemaFactory->has($tableName)) {
return $result;
}
$schema = $this->schemaFactory->get($tableName);
if (!$schema->supportsSubSchema() || $schema->getSubSchemaTypeInformation()->isPointerToForeignFieldInForeignSchema()) {
// In case sub schema is a foreign table type, we have to return here since calling code
// might not do any joins and therefore cannot resolve the foreign table field properly.
return $result;
}
$result[0] = $schema->getSubSchemaTypeInformation()->getFieldName();
foreach ($schema->getSubSchemata() as $recordType => $subSchemata) {
foreach ($subSchemata->getFields() as $fieldInSubschema => $fieldConfig) {
$result[1][$fieldInSubschema] ??= [];
$result[1][$fieldInSubschema][] = $recordType;
}
}
// Remove all fields which are contained in all sub-schemas, determined by
// comparing each field types count with table types count.
$subSchemaCount = count($schema->getSubSchemata());
$result[1] = array_filter($result[1], static fn($value) => count($value) < $subSchemaCount);
return $result;
}
}
@@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Struct;
use TYPO3\CMS\Core\Schema\Field\FieldCollection;
use TYPO3\CMS\Core\Schema\Field\FieldTypeInterface;
/**
* FlexForms Sheets can contain a "repeatable set of fields", which we call "Section Container".
* The section container only contains fields, which is a very simple format.
*
* @internal This is an experimental implementation and might change until TYPO3 v13 LTS
*/
final readonly class FlexSectionContainer
{
public function __construct(
// @todo: incomplete or obsolete implementation, these properties are never read.
private string $sheetIdentifier,
private string $title,
private string $description,
private FieldCollection $fields
) {}
public function getFields(): FieldCollection
{
return $this->fields;
}
public function hasField(string $fieldName): bool
{
return isset($this->fields[$fieldName]);
}
public function getField(string $fieldName): FieldTypeInterface
{
return $this->fields[$fieldName];
}
public static function __set_state(array $state): self
{
return new self(...$state);
}
}
+64
View File
@@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Struct;
use TYPO3\CMS\Core\Schema\Field\FieldCollection;
use TYPO3\CMS\Core\Schema\Field\FieldTypeInterface;
/**
* FlexForms are always separated in sheets, "sDEF" being the default sheet
* if no sheets are defined.
* Each sheet contains fields OR Section Containers (defined by <section>1</section>) which then could also
* contain fields.
*/
final readonly class FlexSheet
{
public function __construct(
// @todo: incomplete or obsolete implementation, these properties are never read.
private string $sheetIdentifier,
private string $title,
private string $description,
private FieldCollection $fields,
private array $sections,
) {}
public function getFields(): FieldCollection
{
return $this->fields;
}
public function hasField(string $fieldName): bool
{
return isset($this->fields[$fieldName]);
}
public function getField(string $fieldName): FieldTypeInterface
{
return $this->fields[$fieldName];
}
public function getSections(): array
{
return $this->sections;
}
public static function __set_state(array $state): self
{
return new self(...$state);
}
}
+283
View File
@@ -0,0 +1,283 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Struct;
final class SelectItem implements \ArrayAccess
{
private const array LEGACY_INDEXED_KEYS_MAPPING_TABLE = [
0 => 'label',
1 => 'value',
2 => 'icon',
3 => 'group',
4 => 'description',
];
private array $container = [];
public function __construct(
private string $type,
private string $label,
private int|string|null $value,
private ?string $icon = null,
private ?string $group = null,
private string|array|null $description = null,
private bool $invertStateDisplay = false,
private ?string $iconIdentifierChecked = null,
private ?string $iconIdentifierUnchecked = null,
private ?string $labelChecked = null,
private ?string $labelUnchecked = null,
private ?string $iconOverlay = null,
) {}
public static function fromTcaItemArray(array $item, string $type = 'select'): SelectItem
{
return new self(
type: $type,
label: (string)($item['label'] ?? $item[0]),
value: $item['value'] ?? $item[1] ?? null,
icon: $item['icon'] ?? $item[2] ?? null,
group: $item['group'] ?? $item[3] ?? null,
description: $item['description'] ?? $item[4] ?? null,
invertStateDisplay: (bool)($item['invertStateDisplay'] ?? false),
iconIdentifierChecked: $item['iconIdentifierChecked'] ?? null,
iconIdentifierUnchecked: $item['iconIdentifierUnchecked'] ?? null,
labelChecked: $item['labelChecked'] ?? null,
labelUnchecked: $item['labelUnchecked'] ?? null,
iconOverlay: $item['iconOverlay'] ?? null,
);
}
public function toArray(): array
{
if ($this->type === 'radio') {
return [
'label' => $this->label,
'value' => $this->value,
];
}
if ($this->type === 'check') {
return [
'label' => $this->label,
'invertStateDisplay' => $this->invertStateDisplay,
'iconIdentifierChecked' => $this->iconIdentifierChecked,
'iconIdentifierUnchecked' => $this->iconIdentifierUnchecked,
'labelChecked' => $this->labelChecked,
'labelUnchecked' => $this->labelUnchecked,
];
}
// Default type=select
return [
'label' => $this->label,
'value' => $this->value,
'icon' => $this->icon,
'iconOverlay' => $this->iconOverlay,
'group' => $this->group,
'description' => $this->description,
];
}
public function getLabel(): string
{
return $this->label;
}
public function withLabel(string $label): SelectItem
{
$clone = clone $this;
$clone->label = $label;
return $clone;
}
public function getValue(): int|string|null
{
return $this->value;
}
public function withValue(int|string|null $value): SelectItem
{
$clone = clone $this;
$clone->value = $value;
return $clone;
}
public function getIcon(): ?string
{
return $this->icon;
}
public function hasIcon(): bool
{
return $this->icon !== null;
}
public function withIcon(?string $icon): SelectItem
{
$clone = clone $this;
$clone->icon = $icon;
return $clone;
}
public function getGroup(): ?string
{
return $this->group;
}
public function hasGroup(): bool
{
return $this->group !== null;
}
public function withGroup(?string $group): SelectItem
{
$clone = clone $this;
$clone->group = $group;
return $clone;
}
public function getDescription(): string|array|null
{
return $this->description;
}
public function hasDescription(): bool
{
return $this->description !== null;
}
public function withDescription(string|array|null $description): SelectItem
{
$clone = clone $this;
$clone->description = $description;
return $clone;
}
public function invertStateDisplay(): bool
{
return $this->invertStateDisplay;
}
public function getIconIdentifierChecked(): ?string
{
return $this->iconIdentifierChecked;
}
public function hasIconIdentifierChecked(): bool
{
return $this->iconIdentifierChecked !== null;
}
public function getIconIdentifierUnchecked(): ?string
{
return $this->iconIdentifierUnchecked;
}
public function hasIconIdentifierUnchecked(): bool
{
return $this->iconIdentifierUnchecked !== null;
}
public function getLabelChecked(): ?string
{
return $this->labelChecked;
}
public function hasLabelChecked(): bool
{
return $this->labelChecked !== null;
}
public function getLabelUnchecked(): ?string
{
return $this->labelUnchecked;
}
public function hasLabelUnchecked(): bool
{
return $this->labelUnchecked !== null;
}
public function getIconOverlay(): ?string
{
return $this->iconOverlay;
}
public function hasIconOverlay(): bool
{
return $this->iconOverlay !== null;
}
public function withIconOverlay(?string $iconOverlay): SelectItem
{
$clone = clone $this;
$clone->iconOverlay = $iconOverlay;
return $clone;
}
public function isDivider(): bool
{
return $this->value === '--div--';
}
public function offsetExists(mixed $offset): bool
{
if (array_key_exists($offset, self::LEGACY_INDEXED_KEYS_MAPPING_TABLE)) {
$offset = self::LEGACY_INDEXED_KEYS_MAPPING_TABLE[$offset];
}
if (property_exists($this, $offset)) {
return isset($this->toArray()[$offset]);
}
return isset($this->container[$offset]);
}
public function offsetGet(mixed $offset): mixed
{
if (array_key_exists($offset, self::LEGACY_INDEXED_KEYS_MAPPING_TABLE)) {
$offset = self::LEGACY_INDEXED_KEYS_MAPPING_TABLE[$offset];
}
if (property_exists($this, $offset)) {
return $this->toArray()[$offset];
}
return $this->container[$offset] ?? null;
}
public function offsetSet(mixed $offset, mixed $value): void
{
if (array_key_exists($offset, self::LEGACY_INDEXED_KEYS_MAPPING_TABLE)) {
$offset = self::LEGACY_INDEXED_KEYS_MAPPING_TABLE[$offset];
}
if (property_exists($this, $offset)) {
$this->{$offset} = $value;
} else {
$this->container[$offset] = $value;
}
}
public function offsetUnset(mixed $offset): void
{
if (array_key_exists($offset, self::LEGACY_INDEXED_KEYS_MAPPING_TABLE)) {
$offset = self::LEGACY_INDEXED_KEYS_MAPPING_TABLE[$offset];
}
if (property_exists($this, $offset)) {
$this->{$offset} = null;
} else {
unset($this->container[$offset]);
}
}
}
@@ -0,0 +1,147 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Struct;
use TYPO3\CMS\Core\Collection\CollectionInterface;
use TYPO3\CMS\Core\Collection\EditableCollectionInterface;
final class SelectItemCollection implements CollectionInterface, EditableCollectionInterface
{
private \SplDoublyLinkedList $storage;
public function __construct()
{
$this->storage = new \SplDoublyLinkedList();
}
/**
* Utility method to transform an arbitrary array to a proper SelectItem collection
*
* @param array $itemList List of SelectItem elements or legacy item arrays
* @param string $type The field type, e.g. "select"
*/
public static function createFromArray(array $itemList, string $type): self
{
$collection = new self();
foreach ($itemList as $item) {
if ($item instanceof SelectItem) {
$collection->add($item);
continue;
}
if (is_array($item)) {
$collection->add(
SelectItem::fromTcaItemArray($item, $type)
);
continue;
}
throw new \InvalidArgumentException(
'Values of $itemList must be of type ' . SelectItem::class . ' or array.',
1762417317
);
}
return $collection;
}
public function current(): SelectItem
{
return $this->storage->current();
}
public function next(): void
{
$this->storage->next();
}
public function key(): int
{
return $this->storage->key();
}
public function valid(): bool
{
return $this->storage->valid();
}
public function rewind(): void
{
$this->storage->rewind();
}
public function count(): int
{
return $this->storage->count();
}
/**
* @param mixed $data
* @todo replace this with a strict "SelectItem" type in TYPO3 v15.0
*/
public function add($data): void
{
if ($data instanceof SelectItem) {
$this->storage->push($data);
}
}
/**
* @param SelectItemCollection $other
*/
public function addAll(CollectionInterface $other): void
{
foreach ($other as $item) {
if ($item instanceof SelectItem) {
$this->storage->push($item);
}
}
}
/**
* @param mixed $data
* @todo replace this with a strict "SelectItem" type in TYPO3 v15.0
*/
public function remove($data): void
{
if (!($data instanceof SelectItem)) {
return;
}
foreach ($this->storage as $key => $value) {
if ($value === $data) {
$this->storage->offsetUnset($key);
break;
}
}
}
public function removeAll(): void
{
$this->storage = new \SplDoublyLinkedList();
}
/**
* @return SelectItem[]
*/
public function toArray(): array
{
$items = [];
foreach ($this->storage as $item) {
$items[] = $item;
}
return $items;
}
}
+49
View File
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema\Struct;
use TYPO3\CMS\Core\Schema\Field\FieldCollection;
final readonly class WizardStep
{
public function __construct(
private string $identifier,
private string $title,
private FieldCollection $fields,
) {}
public function getIdentifier(): string
{
return $this->identifier;
}
public function getTitle(): string
{
return $this->title;
}
public function getFields(): FieldCollection
{
return $this->fields;
}
public static function __set_state(array $state): self
{
return new self(...$state);
}
}
+319
View File
@@ -0,0 +1,319 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema;
use TYPO3\CMS\Core\DataHandling\TableColumnType;
use TYPO3\CMS\Core\Schema\Capability\TcaSchemaCapability;
use TYPO3\CMS\Core\Schema\Exception\InvalidSchemaTypeException;
use TYPO3\CMS\Core\Schema\Exception\UndefinedFieldException;
use TYPO3\CMS\Core\Schema\Exception\UndefinedSchemaException;
use TYPO3\CMS\Core\Schema\Field\FieldCollection;
use TYPO3\CMS\Core\Schema\Field\FieldTypeInterface;
use TYPO3\CMS\Core\Schema\Field\LanguageFieldType;
use TYPO3\CMS\Core\Schema\Field\RelationalFieldTypeInterface;
use TYPO3\CMS\Core\Schema\Struct\WizardStep;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Main implementation class for TCA-based schema.
*/
readonly class TcaSchema implements SchemaInterface
{
public function __construct(
protected string $name,
protected FieldCollection $fields,
protected array $schemaConfiguration,
protected ?SchemaCollection $subSchemata = null,
/** @var PassiveRelation[] */
protected array $passiveRelations = [],
/** @var list<WizardStep> $wizardSteps */
protected array $wizardSteps = [],
) {}
public function getName(): string
{
return $this->name;
}
public function getFields(?callable $filterFunction = null): FieldCollection
{
if ($filterFunction === null) {
return $this->fields;
}
return new FieldCollection(array_filter(iterator_to_array($this->fields), $filterFunction));
}
public function hasField(string $fieldName): bool
{
return isset($this->fields[$fieldName]);
}
public function getField(string $fieldName): FieldTypeInterface
{
if (!$this->hasField($fieldName)) {
throw new UndefinedFieldException('The field "' . $fieldName . '" is not defined for the TCA schema "' . $this->name . '".', 1661615151);
}
return $this->fields[$fieldName];
}
/**
* @return FieldTypeInterface[]
* @internal not part of TYPO3 Core API.
*/
public function getFieldsOfType(TableColumnType $type): iterable
{
foreach ($this->fields as $field) {
if (TableColumnType::tryFrom($field->getType()) !== $type) {
continue;
}
yield $field;
}
}
public function getTitle(?callable $fn = null): string
{
// If a title is defined in the schema configuration, use it.
if (isset($this->schemaConfiguration['title']) && $fn) {
return $fn($this->schemaConfiguration['title']);
}
return $this->schemaConfiguration['title'] ?? '';
}
public function getRawConfiguration(): array
{
return $this->schemaConfiguration;
}
public function isLanguageAware(): bool
{
return isset($this->schemaConfiguration['languageField']) && isset($this->schemaConfiguration['transOrigPointerField']);
}
public function isWorkspaceAware(): bool
{
return (bool)($this->schemaConfiguration['versioningWS'] ?? false);
}
public function hasCapability(TcaSchemaCapability $capability): bool
{
return match ($capability) {
TcaSchemaCapability::SoftDelete => !empty($this->schemaConfiguration['delete'] ?? null),
TcaSchemaCapability::CreatedAt => (bool)($this->schemaConfiguration['crdate'] ?? null),
TcaSchemaCapability::UpdatedAt => (bool)($this->schemaConfiguration['tstamp'] ?? null),
TcaSchemaCapability::SortByField => !empty($this->schemaConfiguration['sortby'] ?? null),
TcaSchemaCapability::DefaultSorting => (bool)($this->schemaConfiguration['default_sortby'] ?? null),
TcaSchemaCapability::AncestorReferenceField => (bool)($this->schemaConfiguration['origUid'] ?? null),
TcaSchemaCapability::EditLock => isset($this->schemaConfiguration['editlock']) && isset($this->fields[$this->schemaConfiguration['editlock']]),
TcaSchemaCapability::InternalDescription => isset($this->schemaConfiguration['descriptionColumn']) && isset($this->fields[$this->schemaConfiguration['descriptionColumn']]),
TcaSchemaCapability::Language => $this->isLanguageAware(),
TcaSchemaCapability::Workspace => $this->isWorkspaceAware(),
TcaSchemaCapability::Label => (bool)($this->schemaConfiguration['label'] ?? ''),
TcaSchemaCapability::AccessAdminOnly => (bool)($this->schemaConfiguration['adminOnly'] ?? false),
TcaSchemaCapability::AccessReadOnly => (bool)($this->schemaConfiguration['readOnly'] ?? false),
TcaSchemaCapability::HideRecordsAtCopy => (bool)($this->schemaConfiguration['hideAtCopy'] ?? false),
TcaSchemaCapability::HideInUi => (bool)($this->schemaConfiguration['hideTable'] ?? false),
TcaSchemaCapability::PrependLabelTextAtCopy => (bool)((string)($this->schemaConfiguration['prependAtCopy'] ?? '')),
TcaSchemaCapability::RestrictionDisabledField => isset($this->schemaConfiguration['enablecolumns']['disabled']),
TcaSchemaCapability::RestrictionStartTime => isset($this->schemaConfiguration['enablecolumns']['starttime']),
TcaSchemaCapability::RestrictionEndTime => isset($this->schemaConfiguration['enablecolumns']['endtime']),
TcaSchemaCapability::RestrictionUserGroup => isset($this->schemaConfiguration['enablecolumns']['fe_group']),
// This is an implicit restriction with a custom configuration
TcaSchemaCapability::RestrictionRootLevel => true,
TcaSchemaCapability::RestrictionWebMount => !empty($this->schemaConfiguration['security']['ignoreWebMountRestriction'] ?? false),
TcaSchemaCapability::ExtbaseHistoryTracking => (bool)($this->schemaConfiguration['extbase']['enableHistoryTracking'] ?? true),
};
}
/**
* @return ($capability is TcaSchemaCapability::Language ? Capability\LanguageAwareSchemaCapability
* : ($capability is TcaSchemaCapability::RestrictionRootLevel ? Capability\RootLevelCapability
* : ($capability is TcaSchemaCapability::EditLock ? Capability\FieldCapability
* : ($capability is TcaSchemaCapability::InternalDescription ? Capability\FieldCapability
* : ($capability is TcaSchemaCapability::RestrictionDisabledField ? Capability\FieldCapability
* : ($capability is TcaSchemaCapability::RestrictionStartTime ? Capability\FieldCapability
* : ($capability is TcaSchemaCapability::RestrictionEndTime ? Capability\FieldCapability
* : ($capability is TcaSchemaCapability::RestrictionUserGroup ? Capability\FieldCapability
* : ($capability is TcaSchemaCapability::AccessReadOnly ? Capability\ScalarCapability
* : ($capability is TcaSchemaCapability::AccessAdminOnly ? Capability\ScalarCapability
* : ($capability is TcaSchemaCapability::HideRecordsAtCopy ? Capability\ScalarCapability
* : ($capability is TcaSchemaCapability::HideInUi ? Capability\ScalarCapability
* : ($capability is TcaSchemaCapability::PrependLabelTextAtCopy ? Capability\ScalarCapability
* : ($capability is TcaSchemaCapability::DefaultSorting ? Capability\ScalarCapability
* : ($capability is TcaSchemaCapability::Label ? Capability\LabelCapability
* : ($capability is TcaSchemaCapability::ExtbaseHistoryTracking ? Capability\ScalarCapability
* : ($capability is TcaSchemaCapability::AncestorReferenceField ? Capability\SystemInternalFieldCapability
* : Capability\SystemInternalFieldCapability)))))))))))))))))
*/
public function getCapability(TcaSchemaCapability $capability): Capability\SchemaCapabilityInterface
{
return match ($capability) {
TcaSchemaCapability::SoftDelete => new Capability\SystemInternalFieldCapability((string)($this->schemaConfiguration['delete'] ?? '')),
TcaSchemaCapability::CreatedAt => new Capability\SystemInternalFieldCapability((string)($this->schemaConfiguration['crdate'] ?? '')),
TcaSchemaCapability::UpdatedAt => new Capability\SystemInternalFieldCapability((string)($this->schemaConfiguration['tstamp'] ?? '')),
TcaSchemaCapability::SortByField => new Capability\SystemInternalFieldCapability((string)($this->schemaConfiguration['sortby'] ?? '')),
TcaSchemaCapability::DefaultSorting => new Capability\ScalarCapability((string)($this->schemaConfiguration['default_sortby'] ?? '')),
TcaSchemaCapability::AncestorReferenceField => new Capability\SystemInternalFieldCapability((string)($this->schemaConfiguration['origUid'] ?? '')),
TcaSchemaCapability::EditLock => new Capability\FieldCapability($this->fields[$this->schemaConfiguration['editlock']]),
TcaSchemaCapability::InternalDescription => new Capability\FieldCapability($this->fields[$this->schemaConfiguration['descriptionColumn']]),
TcaSchemaCapability::Language => $this->buildLanguageCapability(),
TcaSchemaCapability::Workspace => new Capability\ScalarCapability((bool)($this->schemaConfiguration['versioningWS'] ?? false)),
TcaSchemaCapability::Label => $this->buildLabelCapability(),
TcaSchemaCapability::AccessAdminOnly => new Capability\ScalarCapability((bool)($this->schemaConfiguration['adminOnly'] ?? false)),
TcaSchemaCapability::AccessReadOnly => new Capability\ScalarCapability((bool)($this->schemaConfiguration['readOnly'] ?? false)),
TcaSchemaCapability::HideRecordsAtCopy => new Capability\ScalarCapability((bool)($this->schemaConfiguration['hideAtCopy'] ?? false)),
TcaSchemaCapability::HideInUi => new Capability\ScalarCapability((bool)($this->schemaConfiguration['hideTable'] ?? false)),
TcaSchemaCapability::PrependLabelTextAtCopy => new Capability\ScalarCapability((string)($this->schemaConfiguration['prependAtCopy'] ?? '')),
TcaSchemaCapability::RestrictionDisabledField => new Capability\FieldCapability($this->getField($this->schemaConfiguration['enablecolumns']['disabled'])),
TcaSchemaCapability::RestrictionStartTime => new Capability\FieldCapability($this->getField($this->schemaConfiguration['enablecolumns']['starttime'])),
TcaSchemaCapability::RestrictionEndTime => new Capability\FieldCapability($this->getField($this->schemaConfiguration['enablecolumns']['endtime'])),
TcaSchemaCapability::RestrictionUserGroup => new Capability\FieldCapability($this->getField($this->schemaConfiguration['enablecolumns']['fe_group'])),
TcaSchemaCapability::RestrictionRootLevel => new Capability\RootLevelCapability((int)($this->schemaConfiguration['rootLevel'] ?? 0), (bool)($this->schemaConfiguration['security']['ignoreRootLevelRestriction'] ?? false)),
TcaSchemaCapability::RestrictionWebMount => new Capability\ScalarCapability((bool)($this->schemaConfiguration['security']['ignoreWebMountRestriction'] ?? false)),
TcaSchemaCapability::ExtbaseHistoryTracking => new Capability\ScalarCapability((bool)($this->schemaConfiguration['extbase']['enableHistoryTracking'] ?? true)),
};
}
protected function buildLanguageCapability(): Capability\LanguageAwareSchemaCapability
{
/** @var LanguageFieldType $languageField */
$languageField = $this->fields[$this->schemaConfiguration['languageField']];
return new Capability\LanguageAwareSchemaCapability(
$languageField,
$this->fields[$this->schemaConfiguration['transOrigPointerField']],
(isset($this->schemaConfiguration['translationSource']) ? ($this->fields[$this->schemaConfiguration['translationSource']] ?? null) : null),
(isset($this->schemaConfiguration['transOrigDiffSourceField']) ? ($this->fields[$this->schemaConfiguration['transOrigDiffSourceField']] ?? null) : null),
);
}
protected function buildLabelCapability(): Capability\LabelCapability
{
$labelConfiguration = [];
if (isset($this->schemaConfiguration['label_userFunc'])) {
$labelConfiguration['generator'] = $this->schemaConfiguration['label_userFunc'];
$labelConfiguration['generatorOptions'] = $this->schemaConfiguration['label_userFunc_options'] ?? [];
}
if (isset($this->schemaConfiguration['formattedLabel_userFunc'])) {
$labelConfiguration['formatter'] = $this->schemaConfiguration['formattedLabel_userFunc'];
$labelConfiguration['formatterOptions'] = $this->schemaConfiguration['formattedLabel_userFunc_options'] ?? [];
}
return new Capability\LabelCapability(
$this->schemaConfiguration['label'] ?? null,
array_unique(GeneralUtility::trimExplode(',', $this->schemaConfiguration['label_alt'] ?? '', true)),
(bool)($this->schemaConfiguration['label_alt_force'] ?? false),
$labelConfiguration
);
}
public function hasSubSchema(string $subSchema): bool
{
return isset($this->subSchemata[$subSchema]);
}
public function getSubSchema(string $subSchema): TcaSchema
{
if (!$this->hasSubSchema($subSchema)) {
throw new UndefinedSchemaException('The sub schema "' . $subSchema . '" is not defined for the TCA schema "' . $this->name . '".', 1661617062);
}
return $this->subSchemata[$subSchema];
}
public function getSubSchemata(): SchemaCollection
{
return $this->subSchemata ?? new SchemaCollection([]);
}
public function supportsSubSchema(): bool
{
return isset($this->schemaConfiguration['type']);
}
public function getSubSchemaTypeInformation(): SchemaTypeInformation
{
$typeInformation = $this->schemaConfiguration['type'] ?? null;
if ($typeInformation === null) {
throw new InvalidSchemaTypeException('The schema "' . $this->name . '" has no type information.', 1749241443);
}
if (str_contains($typeInformation, ':')) {
[$localField, $foreignField] = explode(':', $typeInformation, 2);
if (!$this->fields->offsetExists($localField) || $this->fields[$localField] instanceof RelationalFieldTypeInterface === false) {
throw new InvalidSchemaTypeException('The schema "' . $this->name . '" defines a foreign field type "' . $typeInformation . '" but there is either no such local field "' . $localField . '" or the field is no relational field.', 1749241444);
}
$activeRelation = $this->fields[$localField]->getRelations()[0] ?? null;
if ($activeRelation instanceof ActiveRelation === false || $activeRelation->toTable() === '') {
throw new InvalidSchemaTypeException('The schema "' . $this->name . '" defines a foreign field type "' . $typeInformation . '" but the local field "' . $localField . '" does not provide a valid realtion.', 1749241445);
}
return new SchemaTypeInformation(
$this->getName(),
$localField,
$foreignField,
$activeRelation->toTable()
);
}
if (!$this->fields->offsetExists($typeInformation)) {
throw new InvalidSchemaTypeException('The schema "' . $this->name . '" defines a field type "' . $typeInformation . '" but there is no such field.', 1749241446);
}
return new SchemaTypeInformation(
$this->getName(),
$typeInformation,
);
}
/**
* @return PassiveRelation[]
*/
public function getPassiveRelations(): array
{
return $this->passiveRelations;
}
/**
* @return ActiveRelation[]
*/
public function getActiveRelations(): array
{
$relations = [];
foreach ($this->fields as $field) {
if ($field instanceof RelationalFieldTypeInterface) {
$relations = array_merge($relations, $field->getRelations());
}
}
return $relations;
}
public function getWizardSteps(): array
{
return $this->wizardSteps;
}
public static function __set_state(array $state): self
{
return new self(...$state);
}
}
+239
View File
@@ -0,0 +1,239 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema;
use TYPO3\CMS\Core\Schema\Exception\FieldTypeNotAvailableException;
use TYPO3\CMS\Core\Schema\Exception\UndefinedFieldException;
use TYPO3\CMS\Core\Schema\Field\FieldCollection;
use TYPO3\CMS\Core\Schema\Field\FieldTypeInterface;
use TYPO3\CMS\Core\Schema\Struct\WizardStep;
use TYPO3\CMS\Core\Service\DependencyOrderingService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* This class builds a TCA schema for a given TCA
* This is done the following way:
*
* As the relations need to be fully resolved first (done in RelationMapBuilder),
* the TcaSchemaFactory does two-step processing:
* 1a. Traverse TCA (and, if type=flex parts are registered), and find relations of all TCA parts pointing to each other
* 1b. Store this in a RelationMap object as a multi-level array.
* ---
* 2. Loop through all TCA tables one by one
* 2a. Build field objects for the TCA table.
* 2b. Detect "sub schemata" (if [ctrl][type] is set), build the field objects only relevant for the sub-schema
* 2c. Build the sub-schema
* 2d. Build the main schema
*
* @internal Not part of TYPO3's API.
*/
final readonly class TcaSchemaBuilder
{
public function __construct(
private RelationMapBuilder $relationMapBuilder,
private FieldTypeFactory $fieldTypeFactory,
) {}
public function buildFromStructure(array $fullTca): SchemaCollection
{
$schemata = [];
ksort($fullTca);
$relationMap = $this->relationMapBuilder->buildFromStructure($fullTca);
foreach (array_keys($fullTca) as $table) {
$schemata[$table] = $this->build($table, $fullTca, $relationMap);
}
return new SchemaCollection($schemata);
}
/**
* Builds a schema from a TCA table, if a sub-schema is requested, it will build the main schema and
* all sub-schematas first.
*
* First builds all fields, then the schema and attach the fields, so all parts can never be
* modified (except for adding sub-schema - this might be removed at some point hopefully).
*
* Then, resolves the sub-schema and the relevant fields for there with columnsOverrides taken into
* account.
*
* As it is crucial to understand, parts such as FlexForms (incl. Sheet, SectionContainers and their Fields)
* NEED to be resolved first, because they need to be attached.
*/
private function build(string $schemaName, array $fullTca, RelationMap $relationMap): TcaSchema
{
if (str_contains($schemaName, '.')) {
// @todo: This 'if' is dead code, isn't it?
[$mainSchema, $subSchema] = explode('.', $schemaName, 2);
$mainSchema = $this->build($mainSchema, $fullTca, $relationMap);
return $mainSchema->getSubSchema($subSchema);
}
// Collect all fields
$allFields = [];
$schemaDefinition = $fullTca[$schemaName];
foreach ($schemaDefinition['columns'] ?? [] as $fieldName => $fieldConfiguration) {
try {
$field = $this->fieldTypeFactory->createFieldType(
$fieldName,
$fieldConfiguration,
$schemaName,
$relationMap
);
} catch (FieldTypeNotAvailableException) {
continue;
}
$allFields[$fieldName] = $field;
}
$schemaConfiguration = $schemaDefinition['ctrl'] ?? [];
// Store "palettes" information into the ctrl section
if (is_array($schemaDefinition['palettes'] ?? null)) {
$schemaConfiguration['palettes'] = $schemaDefinition['palettes'];
}
// Resolve all sub schemas and collect their fields while keeping the system fields
$subSchemata = [];
if (isset($schemaDefinition['ctrl']['type'])) {
foreach ($schemaDefinition['types'] ?? [] as $subSchemaName => $subSchemaDefinition) {
$subSchemaName = (string)$subSchemaName;
$subSchemaFields = [];
$subSchemaFieldInformation = $this->findRelevantFieldsForSubSchema($schemaDefinition, $subSchemaName);
foreach ($subSchemaFieldInformation as $fieldName => $subSchemaFieldConfiguration) {
try {
$field = $this->fieldTypeFactory->createFieldType(
$fieldName,
$subSchemaFieldConfiguration,
$subSchemaName,
// Interesting side-note: The relations stay the same as it is not possible to modify
// this for a subtype.
$relationMap,
$schemaName
);
} catch (FieldTypeNotAvailableException) {
continue;
}
$subSchemaFields[$fieldName] = $field;
}
$subSchemaFieldCollection = new FieldCollection($subSchemaFields);
$subSchemata[$subSchemaName] = new TcaSchema(
$schemaName . '.' . $subSchemaName,
$subSchemaFieldCollection,
// Merge parts from the "types" section into the ctrl section of the main schema
array_replace_recursive($schemaConfiguration, $subSchemaDefinition),
null,
[],
$this->getOrderedWizardSteps($subSchemaDefinition, $subSchemaFieldCollection, $subSchemaName)
);
}
} elseif (($schemaDefinition['types'] ?? []) !== []) {
// Merge parts from the "types" section into the ctrl section of the main schema
$schemaConfiguration = array_replace_recursive(
$schemaConfiguration,
array_first($schemaDefinition['types'])
);
}
return new TcaSchema(
$schemaName,
new FieldCollection($allFields),
$schemaConfiguration,
$subSchemata !== [] ? new SchemaCollection($subSchemata) : null,
$relationMap->getPassiveRelations($schemaName)
);
}
private function findRelevantFieldsForSubSchema(array $tcaForTable, string $subSchemaName): array
{
$fields = [];
if (!isset($tcaForTable['types'][$subSchemaName])) {
throw new \InvalidArgumentException('Subschema "' . $subSchemaName . '" not found.', 1715269835);
}
$subSchemaConfig = $tcaForTable['types'][$subSchemaName];
$showItemArray = GeneralUtility::trimExplode(',', $subSchemaConfig['showitem'] ?? '', true);
foreach ($showItemArray as $aShowItemFieldString) {
[$fieldName, $fieldLabel, $paletteName] = GeneralUtility::trimExplode(';', $aShowItemFieldString . ';;;');
if ($fieldName === '--div--') {
// tabs are not of interest here
continue;
}
if ($fieldName === '--palette--' && !empty($paletteName)) {
// showitem references to a palette field. unpack the palette and process
// label overrides that may be in there.
if (!isset($tcaForTable['palettes'][$paletteName]['showitem'])) {
// No palette with this name found? Skip it.
continue;
}
$palettesArray = GeneralUtility::trimExplode(
',',
$tcaForTable['palettes'][$paletteName]['showitem']
);
foreach ($palettesArray as $aPalettesString) {
[$fieldName, $fieldLabel] = GeneralUtility::trimExplode(';', $aPalettesString . ';;');
if (isset($tcaForTable['columns'][$fieldName])) {
$fields[$fieldName] = $this->getFinalFieldConfiguration($fieldName, $tcaForTable, $subSchemaConfig, $fieldLabel);
}
}
} elseif (isset($tcaForTable['columns'][$fieldName])) {
$fields[$fieldName] = $this->getFinalFieldConfiguration($fieldName, $tcaForTable, $subSchemaConfig, $fieldLabel);
}
}
return $fields;
}
/**
* Handle label and possible columnsOverrides
*/
private function getFinalFieldConfiguration(string $fieldName, array $schemaConfiguration, array $subSchemaConfiguration, ?string $fieldLabel): array
{
$fieldConfiguration = $schemaConfiguration['columns'][$fieldName] ?? [];
if (isset($subSchemaConfiguration['columnsOverrides'][$fieldName])) {
$fieldConfiguration = array_replace_recursive($fieldConfiguration, $subSchemaConfiguration['columnsOverrides'][$fieldName]);
}
if (!empty($fieldLabel)) {
$fieldConfiguration['label'] = $fieldLabel;
}
return $fieldConfiguration;
}
/**
* @throws UndefinedFieldException
*/
private function getOrderedWizardSteps(array $schemaDefinition, FieldCollection $fieldCollection, string $subSchemaName): array
{
if (!isset($schemaDefinition['wizardSteps'])) {
return [];
}
$wizardSteps = [];
$dependencyOrderingService = GeneralUtility::makeInstance(DependencyOrderingService::class);
$orderedWizardSteps = $dependencyOrderingService->orderByDependencies($schemaDefinition['wizardSteps']);
foreach ($orderedWizardSteps as $stepIdentifier => $wizardStep) {
$fields = $wizardStep['fields'] ?? throw new \UnexpectedValueException('Wizard step fields are missing', 1774356281);
$undefinedFields = array_diff($fields, $fieldCollection->getNames());
if ($undefinedFields !== []) {
throw new UndefinedFieldException(sprintf('Wizard step fields: "%s" are not configured in TCA schema: "%s"', implode(',', $undefinedFields), $subSchemaName), 1774355993);
}
$wizardFieldCollection = array_filter(iterator_to_array($fieldCollection), fn(FieldTypeInterface $field) => in_array($field->getName(), $fields));
$wizardSteps[$stepIdentifier] = new WizardStep($stepIdentifier, $wizardStep['title'] ?? '', new FieldCollection($wizardFieldCollection));
}
return $wizardSteps;
}
}
+117
View File
@@ -0,0 +1,117 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema;
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Cache\Event\CacheWarmupEvent;
use TYPO3\CMS\Core\Cache\Frontend\PhpFrontend;
use TYPO3\CMS\Core\Schema\Exception\UndefinedSchemaException;
/**
* This factory returns an object representation of $GLOBALS['TCA']. It is injectable and built during bootstrap.
*
* A TcaSchema contains:
* - a list of all fields as defined in [columns]
* - a list of "capabilities" (parts defined in the [ctrl] section)
* - a list of sub-schemata (if there is a [ctrl][type] definition, then sub-schemata are instances of TcaSchema itself again)
* - a list of possible relations of other schemata pointing to this schema ("Passive Relations")
*/
#[Autoconfigure(public: true, shared: true)]
class TcaSchemaFactory
{
protected SchemaCollection $schemata;
public function __construct(
protected readonly TcaSchemaBuilder $schemaBuilder,
#[Autowire(expression: 'service("package-dependent-cache-identifier").withPrefix("TcaSchema").toString()')]
protected readonly string $cacheIdentifier,
#[Autowire(service: 'cache.core')]
protected readonly PhpFrontend $cache,
) {
$this->schemata = new SchemaCollection([]);
}
/**
* Get a schema from the loaded TCA. Ensure to check for a schema with ->has() before
* calling ->get().
* @throws UndefinedSchemaException
*/
public function get(string $schemaName): TcaSchema
{
return $this->schemata->get($schemaName);
}
/**
* Checks if a schema exists, does not build the schema if not needed, thus it's very slim
* and only creates a schema if a sub-schema is requested.
*/
public function has(string $schemaName): bool
{
return $this->schemata->has($schemaName);
}
/**
* Returns all main schemata
*
* @return SchemaCollection<string, TcaSchema>
*/
public function all(): SchemaCollection
{
return $this->schemata;
}
/**
* Only used for functional tests, which override TCA on the fly for specific test cases.
* Modifying TCA other than in Configuration/TCA/Overrides must be avoided in production code.
*
* @internal only used for TYPO3 Core internally, never use it in public!
*/
public function rebuild(array $fullTca): void
{
$this->schemata = $this->schemaBuilder->buildFromStructure($fullTca);
}
/**
* Load TCA and populate all schema - throws away existing schema if $force is set.
*
* @internal only used for TYPO3 Core internally, never use it in public!
*/
public function load(array $tca, bool $force = false): void
{
if (!$force && $this->schemata->count() > 0) {
return;
}
if (!$force && $this->cache->has($this->cacheIdentifier)) {
$this->schemata = $this->cache->require($this->cacheIdentifier);
return;
}
$this->rebuild($tca);
$this->cache->set($this->cacheIdentifier, 'return ' . var_export($this->schemata, true) . ';');
}
#[AsEventListener('typo3-core/tca-schema')]
public function warmupCaches(CacheWarmupEvent $event): void
{
if ($event->hasGroup('system')) {
$this->schemata = new SchemaCollection([]);
$this->load($GLOBALS['TCA'], true);
}
}
}
@@ -0,0 +1,86 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Schema;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Domain\RecordFactory;
use TYPO3\CMS\Core\Schema\Capability\TcaSchemaCapability;
use TYPO3\CMS\Core\Schema\Field\FieldCollection;
use TYPO3\CMS\Core\Schema\Field\FieldTypeInterface;
/**
* Class that provides record type dependant fields, visible for the current user, taking language context into account
*/
readonly class VisibleSchemaFieldsCollector
{
public function __construct(
private TcaSchemaFactory $schemaFactory,
private RecordFactory $recordFactory,
) {}
public function getFields(string $schemaName, array $row, array $exlcudeFieldNames = []): FieldCollection
{
if (!$this->schemaFactory->has($schemaName)) {
return new FieldCollection();
}
$backendUser = $this->getBackendUser();
$schema = $this->schemaFactory->get($schemaName);
$fields = $schema->getFields();
$record = $this->recordFactory->createRawRecord($schemaName, $row);
if ($schema->hasSubSchema($record->getRecordType() ?? '')) {
$fields = $schema->getSubSchema($record->getRecordType())->getFields();
}
// FieldCollection is immutable - to remove fields we transform it to an array
$fields = iterator_to_array($fields);
foreach ($exlcudeFieldNames as $fieldName) {
unset($fields[$fieldName]);
}
$isOverlay = false;
if ($schema->hasCapability(TcaSchemaCapability::Language)) {
$isOverlay = (int)($record->toArray()[$schema->getCapability(TcaSchemaCapability::Language)->getTranslationOriginPointerField()->getName()] ?? 0) > 0;
}
foreach ($fields as $field) {
if (($field->supportsAccessControl() && !$backendUser->check('non_exclude_fields', $schemaName . ':' . $field->getName()))
|| ($isOverlay && empty($field->getConfiguration()['l10n_display']) && ($field->getConfiguration()['l10n_mode'] ?? '') === 'exclude')
) {
unset($fields[$field->getName()]);
}
}
return new FieldCollection($fields);
}
/**
* @return string[]
*/
public function getFieldNames(string $schemaName, array $row, array $excludeFieldNames = []): array
{
return array_map(static fn(FieldTypeInterface $field): string => $field->getName(), iterator_to_array($this->getFields($schemaName, $row, $excludeFieldNames)));
}
protected function getBackendUser(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}
}