Passed
Pull Request — master (#92)
by Romain
04:58
created

LinkViewHelper::render()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 13
nc 2
nop 0
dl 0
loc 19
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * Copyright (C) 2018
5
 * Nathan Boiron <[email protected]>
6
 * Romain Canon <[email protected]>
7
 *
8
 * This file is part of the TYPO3 NotiZ project.
9
 * It is free software; you can redistribute it and/or modify it
10
 * under the terms of the GNU General Public License, either
11
 * version 3 of the License, or any later version.
12
 *
13
 * For the full copyright and license information, see:
14
 * http://www.gnu.org/licenses/gpl-3.0.html
15
 */
16
17
namespace CuyZ\Notiz\ViewHelpers\Backend\Module;
18
19
use CuyZ\Notiz\Backend\Module\ModuleManager;
20
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
21
22
class LinkViewHelper extends AbstractTagBasedViewHelper
23
{
24
    /**
25
     * @var string
26
     */
27
    protected $tagName = 'a';
28
29
    /**
30
     * @inheritdoc
31
     */
32
    public function initializeArguments()
33
    {
34
        parent::initializeArguments();
35
36
        $this->registerUniversalTagAttributes();
37
38
        $this->registerArgument(
39
            'module',
40
            'string',
41
            'Name of the module, for instance Index or Administration.',
42
            true
43
        );
44
45
        $this->registerArgument(
46
            'controller',
47
            'string',
48
            ''
49
        );
50
51
        $this->registerArgument(
52
            'action',
53
            'string',
54
            ''
55
        );
56
57
        $this->registerArgument(
58
            'arguments',
59
            'array',
60
            ''
61
        );
62
63
        $this->registerArgument(
64
            'frame',
65
            'bool',
66
            'Should the link open the TYPO3 content frame?'
67
        );
68
    }
69
70
    /**
71
     * @inheritdoc
72
     */
73
    public function render()
74
    {
75
        $uri = ModuleManager::for($this->arguments['module'])
76
            ->getUriBuilder()
77
            ->forController($this->arguments['controller'])
78
            ->forAction($this->arguments['action'])
79
            ->withArguments($this->arguments['arguments'] ?: [])
80
            ->build();
81
82
        if ($this->arguments['frame']) {
83
            $this->tag->addAttribute('onclick', "TYPO3.ModuleMenu.App.openInContentFrame('$uri');");
84
            $this->tag->addAttribute('href', '#');
85
        } else {
86
            $this->tag->addAttribute('href', $uri);
87
        }
88
89
        $this->tag->setContent($this->renderChildren());
90
91
        return $this->tag->render();
92
    }
93
}
94