Skip to content

Commit

Permalink
Merge pull request #165 from CKussin/main
Browse files Browse the repository at this point in the history
Feature: Linebreaks can be marked as context-specific
  • Loading branch information
nhovratov authored Mar 24, 2024
2 parents 6b7e532 + eac1d12 commit 1d651ef
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Classes/Definition/Factory/ContentBlockCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ private function handleRootField(array $rootField, ProcessingInput $input, Proce
$rootFieldType = $this->resolveType($input, $rootField);
$fieldTypeEnum = FieldType::tryFrom($rootFieldType::getName());
if ($fieldTypeEnum !== null) {
if ($fieldTypeEnum === FieldType::LINEBREAK && ($rootField['ignoreIfNotInPalette'] ?? false)) {
return [];
}
$this->assertNoLinebreakOutsideOfPalette($fieldTypeEnum, $input->contentBlock);
}
$fields = match ($fieldTypeEnum) {
Expand Down
16 changes: 16 additions & 0 deletions Documentation/YamlReference/FieldTypes/Linebreak/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ linebreak. Otherwise all fields within a Palette are displayed next to each
other. Note: Contrary to all other field types, Linebreaks don't need an
:yaml:`identifier`.

Settings
========

.. confval:: ignoreIfNotInPalette
:name: ignoreIfNotInPalette

:Required: false
:Type: boolean
:Default: false

Normally, linebreaks can only be defined inside of a palette. With this flag
set to true, linebreaks can also appear outside of palettes (but do nothing).
This is especially useful in combination with
:ref:`Basics <field_type_basic>` when you want a set of fields to be used
both in palettes and on root level.

Examples
========

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use TYPO3\CMS\Core\Cache\Frontend\NullFrontend;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

final class TableDefinitionCollectionFactoryTest extends UnitTestCase
final class ContentBlockCompilerTest extends UnitTestCase
{
public static function notUniqueIdentifiersThrowAnExceptionDataProvider(): iterable
{
Expand Down Expand Up @@ -690,6 +690,64 @@ public function linebreaksAreOnlyAllowedWithinPalettes(): void
);
}

#[Test]
public function linebreaksCanBeIgnoredIfConfiguredExplicitly(): void
{
$contentBlocks = [
[
'name' => 'foo/bar',
'icon' => [
'iconPath' => '',
'iconProvider' => '',
],
'extPath' => 'EXT:example/ContentBlocks/foo',
'yaml' => [
'table' => 'tt_content',
'typeField' => 'CType',
'typeName' => 'foo_bar',
'fields' => [
[
'identifier' => 'palette_1',
'type' => 'Palette',
'fields' => [
[
'identifier' => 'field1',
'type' => 'Text',
],
[
'type' => 'Linebreak',
],
[
'identifier' => 'field2',
'type' => 'Text',
],
],
],
[
'type' => 'Linebreak',
'ignoreIfNotInPalette' => true,
],
],
],
],
];

$fieldTypeRegistry = FieldTypeRegistryTestFactory::create();
$fieldTypeResolver = new FieldTypeResolver($fieldTypeRegistry);
$simpleTcaSchemaFactory = new SimpleTcaSchemaFactory($fieldTypeResolver);
$contentBlockRegistry = new ContentBlockRegistry();
foreach ($contentBlocks as $contentBlock) {
$contentBlockRegistry->register(LoadedContentBlock::fromArray($contentBlock));
}
$contentBlockCompiler = new ContentBlockCompiler();
$tableDefinitionCollectionFactory = new TableDefinitionCollectionFactory(new NullFrontend('test'), $contentBlockCompiler);
$tableDefinitionCollectionFactory->createUncached(
$contentBlockRegistry,
$fieldTypeRegistry,
$simpleTcaSchemaFactory
);
}

#[Test]
public function linebreaksAreOnlyAllowedWithinPalettesInsideCollections(): void
{
Expand Down

0 comments on commit 1d651ef

Please sign in to comment.