.. include:: /Includes.rst.txt .. _extending-vocabulary: ======================== Extending the vocabulary ======================== Target group: **Developers** .. contents:: Table of Contents :depth: 1 :local: Introduction ============ The TYPO3 schema extension ships :ref:`type models ` and :ref:`view helpers ` with their properties from the core vocabulary of the Schema.org definitions. However, there are several extensions, like `Health and lifesciences`_ or `Autos`_. There are also `pending types and properties`_ available that enable schema.org to introduce terms on an experimental basis. The embedding of these vocabulary extensions goes beyond the scope of this TYPO3 extension, as it will considerably increase the number of terms – while most of them are not used by the majority of users. For your convenience there are separate extensions to :ref:`extend the vocabulary ` available with the terms of the different sections. But if you only want to add only a few terms you are encouraged to add them on your own, especially pending terms. Pending terms are experimental, after a certain time a term will be incorporated into the core vocabulary or dropped. This depends on the usage, adoption and discussions. To maintain backward-compatibility and to not break any pages, pending types are also not supplied by this extension. But the vocabulary delivered with this extension can be extended according to your needs. This chapter describes the necessary steps to register additional properties to existing types or to introduce new types on your website. .. _extending-register-additional-properties: Register additional properties ============================== .. versionadded:: 1.6.0 You can use a PSR-14 event listener to add one ore more properties to one or more types. The chapter :ref:`event-register-additional-properties` describes how to register additional properties in detail. .. note:: Approximately every 3-4 months a new version of the Schema.org definition is `released`_. The extension adopts these changes in future releases. If you register a pending property for a type, this property can be included in the core vocabulary in a later version of this extension. However, it doesn't do any harm to register a property that already exists. .. _extending-adding-types: Adding types ============ .. versionadded:: 1.7.0 You can add additional types for use in the :ref:`API ` or as a :ref:`WebPage type `. As an example, in March 2020, Schema.org introduces a new `VirtualLocation`_ type related to the corona crisis, which also was also quickly adopted by Google. The type can be used as `location`_ in the `Event`_ type. So let's start with this example. .. rst-class:: bignums-xxl #. Create the type model class The model class for a type defines the available properties. The model class for the `VirtualLocation` type may look like the following:: setProperty('url', 'https://example.com/looney-tunes-webinar-12345/register'); .. important:: The class name must be named after the type name of Schema.org. In this example, the type is called `VirtualLocation`, so the class name is :php:`VirtualLocation`. #. Register the type model Now register the new type in the configuration file :file:`Configuration/TxSchema/TypeModels.php`:: `. #. Create the view helper If you have the need for a view helper with that type, you can create one easily:: ` in the page properties. Simply follow the steps in the :ref:`extending-adding-types` section. Registration of the type model is mandatory here. Then mark your class as a WebPage type with the interface :php:`Brotkrueml\Schema\Core\Model\WebPageTypeInterface`:: ` can be accessed in PHP, the use as a view helper in Fluid templates would also be nice sometimes. If you have the need for this, simply create a new view helper:: Every property name defined in the type model class is available as argument in the view helper. .. _Autos: https://schema.org/docs/automotive.html .. _Event: https://schema.org/Event .. _Health and lifesciences: https://schema.org/docs/meddocs.html .. _location: https://schema.org/location .. _MedicalWebPage: https://schema.org/MedicalWebPage .. _pending types and properties: https://pending.schema.org/docs/pending.home.html .. _released: https://schema.org/docs/releases.html .. _schema_virtuallocation: https://github.com/brotkrueml/schema-virtuallocation .. _VirtualLocation: https://schema.org/VirtualLocation