brotkrueml / schema

TYPO3 extension providing an API and view helpers for schema.org markup
https://extensions.typo3.org/extension/schema
GNU General Public License v2.0
32 stars 9 forks source link

Registering (additional) type properties via service container #75

Closed brotkrueml closed 11 months ago

brotkrueml commented 3 years ago

For now, default properties for a type are declared in a static protected property ($propertyNames) in the according model class (e.g. Person). For additional properties (from sections, like autos or bib, or from custom extensions) a PSR-14 event is available. At runtime, the PSR-14 events are dispatched if no cache entry for this type is available.

This has some drawbacks:

The advantages with this approach are:

The disadvantages are:

A possible solution may be to use the already existing Configuration/TxSchema folder to register additional properties, for example:

File name: Configuration/TxSchema/AdditionalProperties/Person.php Content:

<?php
return [
    'jobTitle',
    'gender',
];

where Person is the type (derived from the file name) and the returned array values jobTitle and gender are the additional properties.

The installed extensions are then scanned for the folder Configuration/TxSchema/AdditionalProperties and the found properties for available types are added to the default properties for that type and cached. The registration of new types is working this way already. These can then also registered via a service container.

With TYPO3 v12 the CacheManager is not available anymore at build time. A workaround was introduced to circumvent this problem in v12: https://github.com/brotkrueml/schema/commit/7b92e4402a272b69a4877fb09255fc43073afa48. When registering types on build time this can be streamlined and the cache avoided.