This brief aims to outline an idea I had for TYPO3: an API for registering various content types that can then be used by editors. Currently we have a multitude of different ways such content types can be achieved, even with sub-types for plugins and sub-sub-types in the form of Extbase-based plugins.
It would make sense to have a common API for all this.
We should declare a convention for a new file, Configuration/ContentTypes.php
which can be placed in extensions and will
return an array (or collection object?) of content types provided by said extension.
Example:
<?php
defined('TYPO3_MODE') or die('Access denied');
return [
new StandardContentType('mytype', ...),
new ExtbasePlugin('myplugin', ...),
];
The idea being that we create (by default immutable) objects that define all the settings a certain type of content requires
to drive it - e.g. ExtbasePlugin
would require additional "allowed actions" and "uncached actions" parameters in addition
to those required by any content type.
The returned objects can then be iterated and persisted. As a first-level compatible solution this iteration and registration could be done simply by extracting the required parameters and calling whichever API we currently have, to make the actual registration of title, icon, fields to show, allowed actions and whatnot.
I would then personally also add a capability for content types that will not be written to caches in any way, e.g. by
a second configuration file UncachedContentTypes.php
- for "content types from runtime-configured extensions", but in a
way that also standard extensions can utilise it.
If we switch to this API that returns a set of objects with a strict interface, it becomes possible to make abstractions on
top of this to read content types from basically any type of source. Using Flux as an example, Flux would simply create one
or more new types of ContentTypeDefinition
interface implementations that extract the required metadata from sources like
it does currently.
It also means that we can fully validate things like Extbase plugin registrations even before they are registered and as a full unit before any part of the configuration is written to caches.
At the time of writing this, we might have:
StandardContentType
which receives the attributes you normally have to register as select option forCType
etc. and allows you some way to define TCA'sshowitem
. This would be the preferred thing to use by third parties.StandardPlugin
which is a basiclist_type
implementation that registers through our legacy plugin API.ExtbasePlugin
which extends the standard plugin and adds the controller action, vendor identity etc.
Then in addition we may want to provide new types:
FluidTemplateContent
which is likeStandardContentType
but results in aFLUIDTEMPLATE
TS object and has options for things like template file reference and default variables. Possibly later extended with a PHP-based API to register but not execute DataProcessors (in the longer term solidifying the current DataProcessor's API with proper declarations of all accepted options.
This strategy can equally well be applied to things like:
- Extension configuration currently stored in
ext_conf_template.txt
can be given a true PHP API and loaded from such a configuration file. - Equally,
ext_typoscript_setup.txt
could be handled via such a configuration file and instead of returning a TS string, might instead return an array which is then possible to modify based on things like extension settings. - Extension updates. It would be almost a no-brainer to drop the
ext_update.php
pattern in favor of letting extensions return collections of proper PHP object instances each reflecting a certain update (and then let's extend that API to make it more useful than the very manual ext update procedures we have now). - Page types (
doktype
) as PHP API for creatingPAGE
-level TS setup, with integration fortypeNum
so it becomes much easier to define things like JSON-exchanging endpoints. Perhaps even load such separately as anEndpoints.php
file? - Services. Instead of registering authentication etc. services in our
ext_localconf.php
files, we could return proper PHP instances from aServices.php
file. - If/when we some lucky day finally get a strict API for all configuration in TYPO3 - extensions to such configuration.
- In the end, basically anything we currently have to do in
ext_localconf.php
files.
For your consideration.
Hey Claus,
very nice read!
Let's split this concept up in various parts.
Part 1: Registration
I am strongly for getting rid of these "let's put everything in
ext_localconf.php
" concepts we have. The approach of creating custom registration files is like a Service Provider concept, which we could do with PSR-11.Part 2: Minimizing Efforts in TypoScript
Let's do this. Getting rid of these doktype, typeNum complexity would be useful as well.
We always need to consider that we only want to have something for a specific site and not for the whole TYPO3 instance.
Part 3: ContentType Objects
This is something I'd really love to see: Compressing the definition of the Content Type, the necessary fields / field definitions (currently TCA), the rendering for BE Fields (For FormEngine), the CType selection restriction (pageTS for new content element wizard etc), and the TemplatePath registration / resolving logic (should be discussed separately) and the current TypoScript instructions. I'm curious to see how this could look like in detail (the PHP objects), but this goes into a better "Domain Modelling" direction. I don't even know if we should make a distinction here for Plugins vs. Content Types actually, getting rid of the word "Plugin" completely.
So much for my first thoughts...
THANKS.
Benni.