0

Szenario: I have two extensions, which extend ext:news with some specific fields. Up to TYPO3 9 I had to configure the dependency to the news extension with the following TypoScript configuration:

config.tx_extbase {
  persistence {
    classes {
      
      GeorgRinger\News\Domain\Model\News {
        subclasses {
          GeorgRinger\News\Domain\Model\News = Vendor\Extension\Domain\Model\News
        }
      }

      Vendor\Extension\Domain\Model\News {
        mapping {
          tableName = tx_news_domain_model_news
        }
      }
        
    }
  }
}

The model Vendor\Extension\Domain\Model\News extends the model of the "base" extension:

class News extends \GeorgRinger\News\Domain\Model\News

In TYPO3 10 the TypoScript configuration was replaced with the following configuration in Configuration/Extbase/Persistence/Classes.php (Breaking: #87623):

\Vendor\Extension\Domain\Model\News::class => [
    'tableName' => 'tx_news_domain_model_news',
    'recordType' => 0,
],

This works as long, as you have just one extension which extends the news extension. If you have a second extension and enable the TYPO3 cache you will get an error, that the fields which are added in the first extension are not available in the templates of the news extension. The strange part is, that this problem only occurs, when enabling the cache!

So my question is: What is the right way to add some fields to an existing extension in TYPO3 10?

chris
  • 2,109
  • 2
  • 23
  • 33
  • Is your second extensions loaded after the first one? Please check your PackageStates.php. To enforce this you have to add a dependency in your second extension to your first one e.g. by a require in the composer.json and ext_emconf.php. – Simon Gilli Sep 30 '20 at 09:19
  • @SimonGilli Yes, it is, but this shouldn't matter since I don't try to get the data in the first extension, but in the "base" extension (templates of ext:news). – chris Sep 30 '20 at 09:21
  • @SimonGilli I do not want to add the dependency to the first extension in the second extension, since they should work without each other. Both have the dependency to `ext:news` in composer.json and ext_emconf.php. – chris Sep 30 '20 at 09:47

1 Answers1

0

As the changelog says, in TYPO3 versions below 10, your overriding configuration was located in typoscript. Since 10 LTS, it is located in a PHP class. As a consequence, the mechanism which controls loading order is no more the one for typoscript but the one for PHP.

Authoritative for the PHP loading order is the constraints section in the ext_emconf.php files of your extensions. They are parsed at first run and cached afterwards. The composer.json files do not control loading order - currently they only serve the purpose of resolving dependencies in composer itself.

In contrast to composer.json, the ext_emconf.php allows you to specify not only hard but also "soft" dependencies, which you can set using the suggests keyword. This way, you can specify loading order between extensions without them having to be installed in any case. This allows you to install each extension independently from the other, while you can still specify correct loading order in case they are both installed.

So, in your case, the second extension needs to have a soft "suggests" dependency to the first one:

constraints' => [
    'depends' => [
    ],
    'conflicts' => [
    ],
    'suggests' => [
        'news' => ''
        'first_news_extension' => ''
    ],
]

See the complete explanation of constraints in ext_emconf here.

moe2k
  • 13
  • 4
  • Thanks a lot for this detailed answer! I am aware of the `suggests` part in the `constraints` section of the `ext_emconf.php`. But as stated in the comments to my question, both extensions are meant to work completely independent of each other. So no matter if I have installed one or both, I should always get all data of the installed extensions in the templates of `ext:news`. At least, this was the case prior TYPO3 10 with the Typoscript configuration. – chris Oct 02 '20 at 08:10
  • That's exactly what the `suggest` section is designed for. Both extensions will work independently from each other, there is no hard dependency, but in case they are both installed, the correct loading Order regarding TCA is controlled. AFAIK there is no other way to do this. – moe2k Oct 10 '20 at 20:08
  • Hm, but how can I as a extension developer know, if another extension extends the extension which I am extending and add this extension to the `suggest` section? – chris Oct 11 '20 at 19:13
  • You cannot unless you know that extension, which makes sense because the ordering and whether it makes a difference depend on the features the exensions implement. In case you have multiple extensions extending the same base model using subclasses/types, you cannot use the features of all subclasses in one model, so your model can only be one of them at a time. But concerning the special case of ext:news, you can make use of its [proxy class generator](https://docs.typo3.org/p/georgringer/news/8.4/en-us/DeveloperManual/ExtendNews/ProxyClassGenerator/Index.html) circumventing this limitation. – moe2k Oct 12 '20 at 19:33