TYPO3: Create repository in renderStatic ViewHelper method

raw

README.rst

Dependency injection is not possible, so we have to create the domain model repository ourselves

Search terms:

  • typo3 repository "viewhelper" "renderStatic"
  • typo3 dependency injection "viewhelper"
raw

TestViewHelper.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
namespace Vendor\Extension\ViewHelpers;
 
use Vendor\Extension\Domain\Repository\TeammemberRepository;
 
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
 
class TestViewHelper 
    extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
{
    use \TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
 
    public static function renderStatic(
        array $arguments, \Closure $renderChildrenClosure,
        RenderingContextInterface $renderingContext
    ) {
        $om = GeneralUtility::makeInstance(
            \TYPO3\CMS\Extbase\Object\ObjectManager::class
        );
        $memberRepo = $om->get(TeammemberRepository::class);
    }
}
?>
 
Christian Weiske Christian Weiske
owner

History