Using the ContentObjectRenderer¶
In some cases, the presence of the current ContentObjectRenderer may
be necessary in the DataProvider. For this case an interface
Fr\Typo3Handlebars\ContentObjectRendererAwareInterface is
provided, which can be used in combination with the trait
Fr\Typo3Handlebars\Traits\ContentObjectRendererAwareTrait.
Usage¶
Transfer of the
ContentObjectRendererIf the rendering process is triggered via TypoScript, the
DataProcessoris automatically assigned the current instance of theContentObjectRenderer(via thecObjproperty). It can then pass this to theDataProvider:# Classes/DataProcessing/CustomProcessor.php namespace Vendor\Extension\DataProcessing; use Fr\Typo3Handlebars\DataProcessing\AbstractDataProcessor; class CustomProcessor extends AbstractDataProcessor { protected function render(): string { $this->provider->setContentObjectRenderer($this->cObj); // ... } }
Assure
ContentObjectRendereris availableIn the
DataProvider, the existence of theContentObjectRenderercan be easily checked if the associated trait is used:# Classes/Data/CustomProvider.php namespace Vendor\Extension\Data; use Fr\Typo3Handlebars\ContentObjectRendererAwareInterface; use Fr\Typo3Handlebars\Data\DataProviderInterface; use Fr\Typo3Handlebars\Data\Response\ProviderResponseInterface; use Fr\Typo3Handlebars\Traits\ContentObjectRendererAwareTrait; class CustomProvider implements DataProviderInterface, ContentObjectRendererAwareInterface { use ContentObjectRendererAwareTrait; public function get(array $data): ProviderResponseInterface { $this->assertContentObjectRendererIsAvailable(); // ... } }
Use the
ContentObjectRendererIf successful, the
ContentObjectRenderercan then be used, for example, to parse database content generated using RTE:# Classes/Data/CustomProvider.php namespace Vendor\Extension\Data; use Fr\Typo3Handlebars\ContentObjectRendererAwareInterface; use Fr\Typo3Handlebars\Data\DataProviderInterface; use Fr\Typo3Handlebars\Data\Response\ProviderResponseInterface; use Fr\Typo3Handlebars\Traits\ContentObjectRendererAwareTrait; +use Vendor\Extension\Data\Response\CustomProviderResponse; class CustomProvider implements DataProviderInterface, ContentObjectRendererAwareInterface { use ContentObjectRendererAwareTrait; public function get(array $data): ProviderResponseInterface { $this->assertContentObjectRendererIsAvailable(); - // ... + + $text = $this->parseText($data); + + return new CustomProviderResponse($text); } + + private function parseText(string $plaintext): string + { + return $this->contentObjectRenderer->parseFunc($plaintext, [], '< lib.parseFunc_RTE'); + } }
Sources¶
See also
View the sources on GitHub: