Integration
Integration with other extensions
Models of other extensions (e.g. EXT:) can be exposed in the API without changing their code:
- Create a model in your extension which extends the model of the other extension and add
@T3api\annotation to it.Api Resource - Map your model to the table of the original model with Extbase persistence configuration (
Configuration/). If your class should also be returned by the original repositories and relations, register it asExtbase/ Persistence/ Classes. php subclasses/recordas described in TYPO3 documentation.Type - Configure serialization of properties of the original class with YAML metadata - annotations can not be added to classes you do not own.
Extbase creates related objects with the classes used in the original model (e.g. categories of a news are \Georg). Declare the type of such relation with your API resource class in YAML metadata - related objects are then serialized as that API resource, including its @id:
GeorgRinger\News\Domain\Model\News:
properties:
categories:
type: 'TYPO3\CMS\Extbase\Persistence\ObjectStorage<SourceBroker\T3apinews\Domain\Model\Category>'
News extension - Example integration
Testing instance of t3api contains complete integration with EXT: - extension t3apinews (see .ddev/ in t3api repository). It is a good starting point for your own integration:
Classes/,Domain/ Model/ News. php Category.,php Tag.- API resources extendingphp EXT:models, with operations and filters.news Classes/- resource used for file upload.Domain/ Model/ File. php Configuration/- mapping of the models toExtbase/ Persistence/ Classes. php EXT:tables.news Resources/- YAML metadata with serialization groups forPrivate/ Serializer/ Georg Ringer. News/*. yml EXT:models, registered innews ext_.localconf. php
use SourceBroker\T3apinews\Domain\Model\Category;
use SourceBroker\T3apinews\Domain\Model\News;
use SourceBroker\T3apinews\Domain\Model\Tag;
return [
News::class => [
'tableName' => 'tx_news_domain_model_news',
],
Tag::class => [
'tableName' => 'tx_news_domain_model_tag',
],
Category::class => [
'tableName' => 'sys_category',
],
];
Real examples. Run "ddev restart && ddev ci 14" and try those links below.
- News, categories and tags of
EXT:exposed bynews t3apinews:
Inline output
If you would like to include API response directly in TYPO3 HTML output (e.g. to avoid waiting for initial request
to the API in your frontend application) you can use t3api: ViewHelper. It processes the request internally,
without HTTP request, and returns the same JSON which would be returned by the endpoint.
Arguments:
route(string, required) - path of the endpoint, without API base path, e.g.news/ornews news/.news/ 1 params(array) - query params, e.g. filters:{search: 'minima', order:.{title: 'asc'}} items(Per Page int) - number of items per page (sent asitemsparam).Per Page page(int) - page number (sent aspageparam).
<html xmlns:t3api="http://typo3.org/ns/SourceBroker/T3api/ViewHelpers"
data-namespace-typo3-fluid="true">
<script type="application/json" id="initial-news"></script>
</html>
Important
Output of the ViewHelper is HTML-escaped by Fluid, so wrap it in <f: when it is placed inside <script>.
items and page arguments use global names of the params (items and page). If you changed
the names for a resource, pass them in params instead. items is respected only if
pagination_ is enabled (see Pagination).