LinkViewHelper   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 47
c 1
b 0
f 0
dl 0
loc 88
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeArguments() 0 41 1
A render() 0 31 6
1
<?php
2
declare(strict_types=1);
3
4
/*
5
 * Copyright (C)
6
 * Nathan Boiron <[email protected]>
7
 * Romain Canon <[email protected]>
8
 *
9
 * This file is part of the TYPO3 NotiZ project.
10
 * It is free software; you can redistribute it and/or modify it
11
 * under the terms of the GNU General Public License, either
12
 * version 3 of the License, or any later version.
13
 *
14
 * For the full copyright and license information, see:
15
 * http://www.gnu.org/licenses/gpl-3.0.html
16
 */
17
18
namespace CuyZ\Notiz\ViewHelpers\Backend\Module;
19
20
use CuyZ\Notiz\Backend\Module\ModuleHandler;
21
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Fluid\Core\Vie...tractTagBasedViewHelper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
23
class LinkViewHelper extends AbstractTagBasedViewHelper
24
{
25
    /**
26
     * @var string
27
     */
28
    protected $tagName = 'a';
29
30
    /**
31
     * @inheritdoc
32
     */
33
    public function initializeArguments()
34
    {
35
        parent::initializeArguments();
36
37
        $this->registerUniversalTagAttributes();
38
39
        $this->registerArgument(
40
            'module',
41
            'string',
42
            'Name of the module, for instance Manager or Administration.',
43
            true
44
        );
45
46
        $this->registerArgument(
47
            'controller',
48
            'string',
49
            ''
50
        );
51
52
        $this->registerArgument(
53
            'action',
54
            'string',
55
            ''
56
        );
57
58
        $this->registerArgument(
59
            'arguments',
60
            'array',
61
            ''
62
        );
63
64
        $this->registerArgument(
65
            'frame',
66
            'bool',
67
            'Should the link open the TYPO3 content frame?'
68
        );
69
70
        $this->registerArgument(
71
            'parentFrame',
72
            'bool',
73
            'If this view-helper is called from inside TYPO3 module frame, this parameter must be set.'
74
        );
75
    }
76
77
    /**
78
     * @inheritdoc
79
     */
80
    public function render()
81
    {
82
        $content = $this->renderChildren();
83
84
        $moduleHandler = ModuleHandler::for($this->arguments['module']);
85
86
        if (!$moduleHandler->canBeAccessed()) {
87
            return $content;
88
        }
89
90
        $uri = $moduleHandler
91
            ->getUriBuilder()
92
            ->forController($this->arguments['controller'])
93
            ->forAction($this->arguments['action'])
94
            ->withArguments($this->arguments['arguments'] ?: [])
95
            ->build();
96
97
        $this->tag->addAttribute('href', $this->arguments['frame'] ? 'javascript:void(0);' : $uri);
98
99
        if ($this->arguments['frame']) {
100
            $onClick = "TYPO3.ModuleMenu.App.showModule('{$moduleHandler->getModuleName()}', '{$uri->getQuery()}');";
101
102
            if ($this->arguments['parentFrame']) {
103
                $onClick = 'parent.' . $onClick;
104
            }
105
            $this->tag->addAttribute('onclick', $onClick);
106
        }
107
108
        $this->tag->setContent($content);
109
110
        return $this->tag->render();
111
    }
112
}
113