Using the ContentObjectRenderer 

In some cases, the presence of the current ContentObjectRenderer may be necessary in the DataProvider. For this case a CPSIT\Typo3Handlebars\ContentObjectRendererAware interface is provided, which can be used in combination with the trait CPSIT\Typo3Handlebars\Traits\ContentObjectRendererAwareTrait.

Usage 

  1. Transfer of the ContentObjectRenderer

    If the rendering process is triggered via TypoScript, the DataProcessor is automatically assigned the current instance of the ContentObjectRenderer (via the cObj property). It can then pass this to the DataProvider:

    # Classes/DataProcessing/CustomProcessor.php
    
    namespace Vendor\Extension\DataProcessing;
    
    use CPSIT\Typo3Handlebars\DataProcessing\AbstractDataProcessor;
    
    class CustomProcessor extends AbstractDataProcessor
    {
        protected function render(): string
        {
            $this->provider->setContentObjectRenderer($this->cObj);
            // ...
        }
    }
    Copied!
  2. Assure ContentObjectRenderer is available

    In the DataProvider, the existence of the ContentObjectRenderer can be easily checked if the associated trait is used:

    # Classes/Data/CustomProvider.php
    
    namespace Vendor\Extension\Data;
    
    use CPSIT\Typo3Handlebars\ContentObjectRendererAware;
    use CPSIT\Typo3Handlebars\Data\DataProvider;
    use CPSIT\Typo3Handlebars\Data\Response\ProviderResponse;
    use CPSIT\Typo3Handlebars\Traits\ContentObjectRendererAwareTrait;
    
    class CustomProvider implements DataProvider, ContentObjectRendererAware
    {
        use ContentObjectRendererAwareTrait;
    
        public function get(array $data): ProviderResponse
        {
            $this->assertContentObjectRendererIsAvailable();
            // ...
        }
    }
    Copied!
  3. Use the ContentObjectRenderer

    If successful, the ContentObjectRenderer can then be used, for example, to parse database content generated using RTE:

     # Classes/Data/CustomProvider.php
    
     namespace Vendor\Extension\Data;
    
     use CPSIT\Typo3Handlebars\ContentObjectRendererAware;
     use CPSIT\Typo3Handlebars\Data\DataProvider;
     use CPSIT\Typo3Handlebars\Data\Response\ProviderResponse;
     use CPSIT\Typo3Handlebars\Traits\ContentObjectRendererAwareTrait;
    +use Vendor\Extension\Data\Response\CustomProviderResponse;
    
     class CustomProvider implements DataProvider, ContentObjectRendererAware
     {
         use ContentObjectRendererAwareTrait;
    
         public function get(array $data): ProviderResponse
         {
             $this->assertContentObjectRendererIsAvailable();
    -        // ...
    +
    +        $text = $this->parseText($data);
    +
    +        return new CustomProviderResponse($text);
        }
    +
    +    private function parseText(string $plaintext): string
    +    {
    +        return $this->contentObjectRenderer->parseFunc($plaintext, [], '< lib.parseFunc_RTE');
    +    }
     }
    Copied!

Sources