Passed
Pull Request — master (#125)
by Nathan
03:17
created

ShowViewHelper::initializeArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 17
rs 9.9
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\Notification\Link;
18
19
use CuyZ\Notiz\Core\Notification\Notification;
20
use CuyZ\Notiz\Core\Notification\Viewable;
21
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
22
23
class ShowViewHelper 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
            'notification',
41
            Notification::class,
42
            '',
43
            true
44
        );
45
46
        $this->registerArgument(
47
            'graceful',
48
            'bool',
49
            'If the link can not be generated, the content will still be displayed without the link.'
50
        );
51
    }
52
53
    /**
54
     * @inheritdoc
55
     */
56
    public function render()
57
    {
58
        /** @var Notification $notification */
59
        $notification = $this->arguments['notification'];
60
61
        if (!$notification instanceof Viewable) {
62
            if ($this->arguments['graceful']) {
63
                return $this->renderChildren();
64
            } else {
65
                return '';
66
            }
67
        }
68
69
        $this->tag->addAttribute('href', $notification->getViewUri());
70
        $this->tag->setContent($this->renderChildren());
71
72
        return $this->tag->render();
73
    }
74
}
75