Skip to content

Commit

Permalink
[TASK] Migrate FieldTypeRegistry to AutoWireLocator/Iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
nhovratov committed Sep 16, 2024
1 parent 5d37c15 commit 879aa3a
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 140 deletions.
6 changes: 4 additions & 2 deletions Classes/Builder/ContentBlockBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@

namespace TYPO3\CMS\ContentBlocks\Builder;

use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Attribute\AutowireLocator;
use Symfony\Component\Yaml\Yaml;
use TYPO3\CMS\ContentBlocks\Definition\ContentType\ContentType;
use TYPO3\CMS\ContentBlocks\Definition\Factory\TableDefinitionCollectionFactory;
use TYPO3\CMS\ContentBlocks\FieldType\FieldTypeRegistry;
use TYPO3\CMS\ContentBlocks\Generator\HtmlTemplateCodeGenerator;
use TYPO3\CMS\ContentBlocks\Generator\LanguageFileGenerator;
use TYPO3\CMS\ContentBlocks\Loader\LoadedContentBlock;
Expand All @@ -39,7 +40,8 @@ public function __construct(
protected readonly HtmlTemplateCodeGenerator $htmlTemplateCodeGenerator,
protected readonly LanguageFileGenerator $languageFileGenerator,
protected readonly ContentBlockRegistry $contentBlockRegistry,
protected readonly FieldTypeRegistry $fieldTypeRegistry,
#[AutowireLocator('content_blocks.field_type', defaultIndexMethod: 'getName')]
protected readonly ContainerInterface $fieldTypeRegistry,
protected readonly TableDefinitionCollectionFactory $tableDefinitionCollectionFactory,
protected readonly SimpleTcaSchemaFactory $simpleTcaSchemaFactory,
) {}
Expand Down
16 changes: 5 additions & 11 deletions Classes/Definition/Factory/ContentBlockCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace TYPO3\CMS\ContentBlocks\Definition\Factory;

use Psr\Container\ContainerInterface;
use TYPO3\CMS\ContentBlocks\Definition\Capability\LabelCapability;
use TYPO3\CMS\ContentBlocks\Definition\ContentType\ContentType;
use TYPO3\CMS\ContentBlocks\Definition\Factory\Processing\ProcessedFieldsResult;
Expand All @@ -31,7 +32,6 @@
use TYPO3\CMS\ContentBlocks\Definition\TcaFieldDefinition;
use TYPO3\CMS\ContentBlocks\FieldType\FieldType;
use TYPO3\CMS\ContentBlocks\FieldType\FieldTypeInterface;
use TYPO3\CMS\ContentBlocks\FieldType\FieldTypeRegistry;
use TYPO3\CMS\ContentBlocks\Loader\LoadedContentBlock;
use TYPO3\CMS\ContentBlocks\Registry\AutomaticLanguageKeysRegistry;
use TYPO3\CMS\ContentBlocks\Registry\AutomaticLanguageSource;
Expand Down Expand Up @@ -74,7 +74,7 @@ final class ContentBlockCompiler
{
private AutomaticLanguageKeysRegistry $automaticLanguageKeysRegistry;
private SimpleTcaSchemaFactory $simpleTcaSchemaFactory;
private FieldTypeRegistry $fieldTypeRegistry;
private ContainerInterface $fieldTypeRegistry;

/**
* This property tracks Collection foreign_table parent references.
Expand All @@ -92,7 +92,7 @@ final class ContentBlockCompiler

public function compile(
ContentBlockRegistry $contentBlockRegistry,
FieldTypeRegistry $fieldTypeRegistry,
ContainerInterface $fieldTypeRegistry,
SimpleTcaSchemaFactory $simpleTcaSchemaFactory
): CompilationResult {
$this->simpleTcaSchemaFactory = $simpleTcaSchemaFactory;
Expand Down Expand Up @@ -890,15 +890,9 @@ private function resolveType(ProcessingInput $input, array $field): FieldTypeInt
$this->assertTypeExists($field, $input);
$fieldTypeName = $field['type'];
if (!$this->fieldTypeRegistry->has($fieldTypeName)) {
$validTypesList = array_map(
fn(FieldTypeInterface $fieldType) => $fieldType::getName(),
$this->fieldTypeRegistry->getAll()
);
sort($validTypesList);
$validTypes = implode(', ', $validTypesList);
throw new \InvalidArgumentException(
'The type "' . $field['type'] . '" is not a valid type in Content Block "'
. $input->contentBlock->getName() . '". Valid types are: ' . $validTypes . '.',
'The field type "' . $field['type'] . '" is not valid. Content Block: "'
. $input->contentBlock->getName() . '".',
1697625849
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@

namespace TYPO3\CMS\ContentBlocks\Definition\Factory;

use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Attribute\AutowireLocator;
use Symfony\Component\VarExporter\VarExporter;
use TYPO3\CMS\ContentBlocks\Definition\ContentType\ContentType;
use TYPO3\CMS\ContentBlocks\Definition\TableDefinition;
use TYPO3\CMS\ContentBlocks\Definition\TableDefinitionCollection;
use TYPO3\CMS\ContentBlocks\Definition\TcaFieldDefinitionCollection;
use TYPO3\CMS\ContentBlocks\FieldType\FieldTypeRegistry;
use TYPO3\CMS\ContentBlocks\Registry\ContentBlockRegistry;
use TYPO3\CMS\ContentBlocks\Schema\SimpleTcaSchemaFactory;
use TYPO3\CMS\Core\Cache\Frontend\PhpFrontend;
Expand All @@ -41,8 +42,9 @@ public function __construct(

public function create(
ContentBlockRegistry $contentBlockRegistry,
FieldTypeRegistry $fieldTypeRegistry,
SimpleTcaSchemaFactory $simpleTcaSchemaFactory,
#[AutowireLocator('content_blocks.field_type', defaultIndexMethod: 'getName')]
ContainerInterface $fieldTypeRegistry,
): TableDefinitionCollection {
if (isset($this->tableDefinitionCollection)) {
return $this->tableDefinitionCollection;
Expand All @@ -62,7 +64,7 @@ public function create(

public function createUncached(
ContentBlockRegistry $contentBlockRegistry,
FieldTypeRegistry $fieldTypeRegistry,
ContainerInterface $fieldTypeRegistry,
SimpleTcaSchemaFactory $simpleTcaSchemaFactory
): TableDefinitionCollection {
$compiledContentBlocks = $this->contentBlockCompiler->compile($contentBlockRegistry, $fieldTypeRegistry, $simpleTcaSchemaFactory);
Expand Down
67 changes: 0 additions & 67 deletions Classes/FieldType/FieldTypeRegistry.php

This file was deleted.

6 changes: 4 additions & 2 deletions Classes/Generator/SqlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

namespace TYPO3\CMS\ContentBlocks\Generator;

use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Attribute\AutowireLocator;
use TYPO3\CMS\ContentBlocks\Definition\Factory\TableDefinitionCollectionFactory;
use TYPO3\CMS\ContentBlocks\Definition\TableDefinition;
use TYPO3\CMS\ContentBlocks\FieldType\FieldTypeRegistry;
use TYPO3\CMS\ContentBlocks\Loader\ContentBlockLoader;
use TYPO3\CMS\ContentBlocks\Schema\SimpleTcaSchemaFactory;
use TYPO3\CMS\Core\Database\Event\AlterTableDefinitionStatementsEvent;
Expand All @@ -33,7 +34,8 @@ public function __construct(
protected readonly ContentBlockLoader $contentBlockLoader,
protected readonly TableDefinitionCollectionFactory $tableDefinitionCollectionFactory,
protected readonly SimpleTcaSchemaFactory $simpleTcaSchemaFactory,
protected readonly FieldTypeRegistry $fieldTypeRegistry,
#[AutowireLocator('content_blocks.field_type', defaultIndexMethod: 'getName')]
protected readonly ContainerInterface $fieldTypeRegistry,
) {}

public function __invoke(AlterTableDefinitionStatementsEvent $event): void
Expand Down
5 changes: 3 additions & 2 deletions Classes/Schema/FieldTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@

namespace TYPO3\CMS\ContentBlocks\Schema;

use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
use TYPO3\CMS\ContentBlocks\FieldType\FieldTypeInterface;
use TYPO3\CMS\ContentBlocks\FieldType\FieldTypeRegistry;

/**
* @internal Not part of TYPO3's public API.
*/
class FieldTypeResolver
{
public function __construct(
protected FieldTypeRegistry $fieldTypeRegistry,
#[AutowireIterator('content_blocks.field_type')]
protected iterable $fieldTypeRegistry,
) {}

public function resolve(array $configuration): FieldTypeInterface
Expand Down
4 changes: 0 additions & 4 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ services:
factory:
- '@TYPO3\CMS\ContentBlocks\Definition\Factory\TableDefinitionCollectionFactory'
- 'create'
arguments:
- '@TYPO3\CMS\ContentBlocks\Registry\ContentBlockRegistry'
- '@TYPO3\CMS\ContentBlocks\FieldType\FieldTypeRegistry'
- '@TYPO3\CMS\ContentBlocks\Schema\SimpleTcaSchemaFactory'

TYPO3\CMS\ContentBlocks\Registry\AutomaticLanguageKeysRegistry:
factory:
Expand Down
Loading

0 comments on commit 879aa3a

Please sign in to comment.