Idea: Content Types API for TYPO3
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.
First part of solution: autoloaded configuration file returning objects
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.
<?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.
The ContentType objects' versatility
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:
StandardContentTypewhich receives the attributes you normally have to register as select option for
CTypeetc. and allows you some way to define TCA's
showitem. This would be the preferred thing to use by third parties.
StandardPluginwhich is a basic
list_typeimplementation that registers through our legacy plugin API.
ExtbasePluginwhich extends the standard plugin and adds the controller action, vendor identity etc.
Then in addition we may want to provide new types:
FluidTemplateContentwhich is like
StandardContentTypebut results in a
FLUIDTEMPLATETS 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.
Possible future uses of this strategy
This strategy can equally well be applied to things like:
- Extension configuration currently stored in
ext_conf_template.txtcan be given a true PHP API and loaded from such a configuration file.
ext_typoscript_setup.txtcould 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.phppattern 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 creating
PAGE-level TS setup, with integration for
typeNumso it becomes much easier to define things like JSON-exchanging endpoints. Perhaps even load such separately as an
- Services. Instead of registering authentication etc. services in our
ext_localconf.phpfiles, we could return proper PHP instances from a
- 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
For your consideration.