Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are there plans to integrate the new Core Content Blocks Registry / TcaGenerator to set TCA Felds with YAML? #546

Open
Kleini13 opened this issue Oct 30, 2024 · 11 comments

Comments

@Kleini13
Copy link

It wold be a straight forward setup if the same strategy of config.yaml for creating TCA fields in EXT:Container would be hooked in as with EXT:ContentBlocks. As these two extensions are the replacement for EXT:GridElemenzts for most people.
Are there any plans from developers in this area?
https://docs.typo3.org/p/friendsoftypo3/content-blocks/main/en-us/YamlReference/FieldTypes/Index.html#field-types

Advantages:

  • Reuse of (Content Blocks) MIxins (Basics)
  • No duplicate solutions for field creation when redundant fields are used in EXT:ContentBlocks and EXT:Containers
  • Significantly less code
  • Use of the new Core Content Block Registry / TcaGenerator (or what ever)

(I am not a TYPO3 expert, so forgive me if I have not expressed myself clearly)

@nhovratov
Copy link
Contributor

nhovratov commented Oct 30, 2024

@Kleini13 You are on the right track. And indeed, this is already possible to a certain extent.

  1. Define a Content Block for your container (ContentBlocks/ContentElements/two-column-container/config.yaml):
name: vendor/two-column-container
typeName: vendor_two_columns_container
group: container
saveAndClose: true
fields:
  - identifier: header
    useExistingField: true
  1. Register the Container Configuration (manually) -> Here EXT:container could add a helper method)
    Configuration/TCA/Overrides/*.php
<?php

use B13\Container\Backend\Preview\ContainerPreviewRenderer;
use B13\Container\Tca\ContainerConfiguration;

$containerConfiguration = new ContainerConfiguration(
    cType: 'vendor_two_columns_container',
    label: '',
    description: '',
    grid: [
        [
            ['name' => 'links', 'colPos' => 200],
            ['name' => 'rechts', 'colPos' => 201],
        ],
    ]
);
$GLOBALS['TCA']['tt_content']['containerConfiguration'][$containerConfiguration->getCType()] = $containerConfiguration->toArray();
$GLOBALS['TCA']['tt_content']['types'][$containerConfiguration->getCType()]['previewRenderer'] = ContainerPreviewRenderer::class;
  1. Add TypoScript rendering definition
tt_content.vendor_two_columns_container {
  dataProcessing {
    100 = B13\Container\DataProcessing\ContainerProcessor
  }
}
  1. Delete backend-preview.html

This way the ContainerPreviewRenderer from EXT:container will kick in and render the grids in the backend.

That's it. From here on you have full control over the Container fields. You can even define FlexForm configuration, which is oftentimes needed in YAML (No XML anymore!). Icon (no need to register it anymore) and frontend template are handled by Content Blocks in one place.

TODO: For this to work even easier, everything should be defined at one place, instead of 3. It would make sense to have it all in Content Blocks YAML. This means CB has to define a new type "Container" (special Content Element type), which holds the Container configuration. There is no API for this yet, but it's on my mental list. Could be added as an extension. On the other side, Container has to provide an API to register Container configuration without simultanously registering a new Content Element in TCA (see example above).

I hope we can work together to bring these extensions closer together (because they should!). This would even more separate concerns -> Content Blocks for Content Element definitions and Container for Configuration and backend rendering of grids.

@Kleini13
Copy link
Author

HI @nhovratov, thank you for the very quick response and explanation. I hope the API has a high priority on your mental list. If I can be of any help, tell me ;-) Until then, I'll try your 3 step solution.

@ErHaWeb
Copy link

ErHaWeb commented Oct 30, 2024

It's great to see these efforts. I have already successfully combined content blocks and containers in a similar way in a customer project without this description. I would love to be able to control the container behaviour directly in the content block yaml in the future.

@nhovratov
Copy link
Contributor

@Kleini13

If I can be of any help, tell me ;-)

Of course I am more than happy to get help. For myself I don't know when I will be working on this feature. But in case you want to kickstart it, you can contact me on Slack. I will give you the information you need.

@Kleini13
Copy link
Author

Kleini13 commented Oct 31, 2024

It works like a charm!

@nhovratov
Copy link
Contributor

It should work without the backend-preview.html. Just delete it and the preview renderer from Container will kick in.

@Kleini13
Copy link
Author

Kleini13 commented Oct 31, 2024

@nhovratov You are right. It is not taking the backend-preview.html anyways. But what do I have to do if I want to overwrite the b13/container/Resources/Private/Templates/Grid.html with my own backend preview?

@nhovratov
Copy link
Contributor

Just had a quick look: This event looks handy:

$this->eventDispatcher->dispatch($beforeContainerPreviewIsRendered);

@Kleini13
Copy link
Author

Here the code if you want to have a different "GridTemplate" via setGridTemplate:

<?php

use B13\Container\Backend\Preview\ContainerPreviewRenderer;
use B13\Container\Tca\ContainerConfiguration;

$containerConfiguration = (new ContainerConfiguration(
    cType: 'vendor_two_columns_container',
    label: '',
    description: '',
    grid: [
        [
            ['name' => 'links', 'colPos' => 200],
            ['name' => 'rechts', 'colPos' => 201],
        ],
    ]
));

    ->setGridTemplate('EXT:my_extension/Resources/Private/Templates/Container/Grid.html');

$GLOBALS['TCA']['tt_content']['containerConfiguration'][$containerConfiguration->getCType()] = $containerConfiguration->toArray();
$GLOBALS['TCA']['tt_content']['types'][$containerConfiguration->getCType()]['previewRenderer'] = ContainerPreviewRenderer::class;

@linawolf
Copy link

3,: Mmh so I leave all the typoscript rendering and Templates etc in one place then or also move them?
4.: What backend-preview.html

@nhovratov
Copy link
Contributor

3,: Mmh so I leave all the typoscript rendering and Templates etc in one place then or also move them? 4.: What backend-preview.html

3: You leave it like it used to be, with the exception that you don't need to specify any template paths anymore, as Content Blocks does this.

4: https://docs.typo3.org/p/friendsoftypo3/content-blocks/main/en-us/Definition/Templates/Index.html#backend-preview-html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants