in2code-de / powermail

This is the official repository of the TYPO3 extension powermail! Powermail is a well-known, editor-friendly, powerful and easy mailform extension for TYPO3
https://in2code.de
87 stars 174 forks source link

How to extend powermail data models in version 12? #996

Open kitzberger opened 6 months ago

kitzberger commented 6 months ago

I'm trying to figure out how to properly extend the data models in TYPO3 12 and EXT:powermail 12.

Since TYPO3\CMS\Extbase\Container\Container is gone with TYPO3 12 the respective section of this extensions documentation isn't working anymore: https://github.com/in2code-de/powermail/blob/master/Documentation/ForDevelopers/AddNewFieldProperties.md

Neither is the example in EXT:powermailextended. The latest PR (https://github.com/einpraegsam/powermailextended/pull/9) has never been merged and isn't not compatible with version 12 anyway.

Here's what I found out so far.

Configuration/Extbase/Persistence/Classes.php should look like this:

<?php
declare(strict_types=1);
return [
    \Me\MyExtension\Domain\Model\Page::class => [
        'tableName' => 'tx_powermail_domain_model_page',
    ],
    \Me\MyExtension\Domain\Model\Field::class => [
        'tableName' => 'tx_powermail_domain_model_field',
    ],
];

ext_localconf.php like this:

<?php
defined('TYPO3') || die('Access denied.');
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\In2code\Powermail\Domain\Model\Page::class] = [
    'className' => \Me\MyExtension\Domain\Model\Page::class,
];
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\In2code\Powermail\Domain\Model\Field::class] = [
    'className' => \Me\MyExtension\Domain\Model\Field::class,
];

Caution: in case of overwriting both Page and Field the relationship between them both needs to be tweaked too, to prevent some weird endless loop:

<?php
namespace Me\MyExtension\Domain\Model;
class Page extends \In2code\Powermail\Domain\Model\Page
{
    /**
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Me\MyExtension\Domain\Model\Field>
     */
    protected $fields = null;
}

I'd really appreciate some feedback of other developers on this matter and together find a solid solution.

olegkarun commented 4 months ago

@kitzberger

For me Configuration/Extbase/Persistence/Classes.php

`<?php declare(strict_types = 1);

return [

\In2code\Powermail\Domain\Model\Form::class => [
    'subclasses' => [           
        'formClass' => \Vendor\My\Domain\Model\Form::class,
    ]        
],

\In2code\Powermail\Domain\Model\Page::class => [
    'subclasses' => [           
        'pageClass' => \Vendor\My\Domain\Model\Page::class,
    ]        
],

\In2code\Powermail\Domain\Model\Field::class => [
    'subclasses' => [           
        'fieldClass' => \Vendor\My\Domain\Model\Field::class,
    ]        
],

\Vendor\My\Domain\Model\Form::class => [
    'tableName' => 'tx_powermail_domain_model_form'
],

\Vendor\My\Domain\Model\Page::class => [
    'tableName' => 'tx_powermail_domain_model_page'
],

\Vendor\My\Domain\Model\Field::class => [
    'tableName' => 'tx_powermail_domain_model_field'
]

]`

I see it in vendor/typo3/cms-extbase/Classes/Persistence/Generic/Mapper/DataMapFactory.php image

But I have no lunch my model also I have no variables in my Fluid. Also try setup dependencies with composer.json and ext_emconf.php

For News this approach works fine

ErHaWeb commented 2 months ago

@kitzberger Thank you, I also ran into the endless loop and was able to solve it thanks to you. In my case, I have also extended the Form model. In this case, an addition must also be made there to avoid the loop.

<?php
namespace Me\MyExtension\Domain\Model;
class Form extends \In2code\Powermail\Domain\Model\Form
{
    /**
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Me\MyExtension\Domain\Model\Page>
     */
    protected $pages;
}

Do you happen to have an explanation for how this loop comes about? I am experiencing this for the first time when I extend an Extbase model. However, this may also be due to the fact that up to now it has always been models without ObjectStorage dependencies to other extended models.

With this PR merged in February 2024, we now also have official documentation on how Extbase models are extended. Nevertheless, it should be noted that @garvinhicking's comment is taken into account in the decision to use XCLASS.

I am not a friend of XCLASSing either, but I don't see a more suitable alternative for this specific use case (adding individual fields in powermail) without introducing additional dependencies to other extensions such as EXT:extender.

As discussed in the Slack channel, have you been able to gain experience in TYPO3 v12 and powermail with EXT:extender? Would you recommend this extension for the use case mentioned here and if so, why?