• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CPS-IT / handlebars / 13561988149

27 Feb 2025 08:26AM UTC coverage: 93.023% (-0.6%) from 93.661%
13561988149

push

github

web-flow
Merge pull request #415 from CPS-IT/feature/1.x/handlebars-controller

[FEATURE] Introduce abstract `HandlebarsController` for Extbase context

18 of 28 new or added lines in 2 files covered. (64.29%)

1200 of 1290 relevant lines covered (93.02%)

4.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

56.52
/Classes/Controller/HandlebarsController.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS extension "handlebars".
7
 *
8
 * Copyright (C) 2025 Elias Häußler <e.haeussler@familie-redlich.de>
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation, either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23

24
namespace Fr\Typo3Handlebars\Controller;
25

26
use Fr\Typo3Handlebars\Exception;
27
use Fr\Typo3Handlebars\Extbase\View;
28
use Symfony\Component\DependencyInjection;
29
use TYPO3\CMS\Extbase;
30
use TYPO3Fluid\Fluid;
31

32
/**
33
 * HandlebarsController
34
 *
35
 * @author Elias Häußler <e.haeussler@familie-redlich.de>
36
 * @license GPL-2.0-or-later
37
 */
38
abstract class HandlebarsController extends Extbase\Mvc\Controller\ActionController
39
{
40
    protected View\ExtbaseHandlebarsViewResolver $viewResolver;
41

42
    public function injectViewResolver(
3✔
43
        #[DependencyInjection\Attribute\Autowire(service: View\ExtbaseHandlebarsViewResolver::class)]
44
        Extbase\Mvc\View\ViewResolverInterface $viewResolver,
45
    ): void {
46
        parent::injectViewResolver($viewResolver);
3✔
47
    }
48

49
    protected function resolveView(): Fluid\View\ViewInterface
3✔
50
    {
51
        $baseView = parent::resolveView();
3✔
52

53
        if (!($baseView instanceof Fluid\View\AbstractTemplateView)) {
3✔
54
            return $baseView;
3✔
55
        }
56

57
        /** @var View\ExtbaseHandlebarsView $view */
NEW
58
        $view = $this->viewResolver->resolve(
×
NEW
59
            $this->request->getControllerObjectName(),
×
NEW
60
            $this->request->getControllerActionName(),
×
NEW
61
            $this->request->getFormat(),
×
NEW
62
            false,
×
NEW
63
        );
×
NEW
64
        $view->assignMultiple((array)$baseView->getRenderingContext()->getVariableProvider()->getAll());
×
NEW
65
        $view->setTemplateNameFromRequest($this->request);
×
66

NEW
67
        return $view;
×
68
    }
69

70
    protected function renderView(?string $templateName = null): string
2✔
71
    {
72
        if (!($this->view instanceof View\ExtbaseHandlebarsView)) {
2✔
NEW
73
            throw new Exception\ViewIsNotSupported($this->view);
×
74
        }
75

76
        if ($templateName !== null) {
2✔
77
            $view = clone $this->view;
1✔
78
            $view->setTemplateName($templateName);
1✔
79
        } else {
80
            $view = $this->view;
1✔
81
        }
82

83
        return $view->render();
2✔
84
    }
85
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc