Passed
Push — master ( e9c972...8e746e )
by Nathan
02:57
created

CreateViewHelper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 68
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeArguments() 0 23 1
A render() 0 29 5
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\Definition\Tree\EventGroup\Event\EventDefinition;
20
use CuyZ\Notiz\Core\Definition\Tree\Notification\NotificationDefinition;
21
use CuyZ\Notiz\Core\Notification\Creatable;
22
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
23
24
class CreateViewHelper extends AbstractTagBasedViewHelper
25
{
26
    /**
27
     * @var string
28
     */
29
    protected $tagName = 'a';
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public function initializeArguments()
35
    {
36
        parent::initializeArguments();
37
38
        $this->registerUniversalTagAttributes();
39
40
        $this->registerArgument(
41
            'notificationDefinition',
42
            NotificationDefinition::class,
43
            '',
44
            true
45
        );
46
47
        $this->registerArgument(
48
            'eventDefinition',
49
            EventDefinition::class,
50
            ''
51
        );
52
53
        $this->registerArgument(
54
            'addUriTemplate',
55
            'bool',
56
            ''
57
        );
58
    }
59
60
    /**
61
     * @inheritdoc
62
     */
63
    public function render()
64
    {
65
        /** @var NotificationDefinition $notificationDefinition */
66
        $notificationDefinition = $this->arguments['notificationDefinition'];
67
68
        /** @var Creatable $className */
69
        $className = $notificationDefinition->getClassName();
70
71
        if (!in_array(Creatable::class, class_implements($className))
72
            || !$className::isCreatable()
73
        ) {
74
            return '';
75
        }
76
77
        if ($this->arguments['addUriTemplate']) {
78
            $this->tag->addAttribute('data-href', $className::getCreationUri('#EVENT#'));
79
        }
80
81
        /** @var EventDefinition $eventDefinition */
82
        $eventDefinition = $this->arguments['eventDefinition'];
83
84
        $selectedEvent = $eventDefinition
0 ignored issues
show
introduced by
$eventDefinition is of type CuyZ\Notiz\Core\Definiti...p\Event\EventDefinition, thus it always evaluated to true. If $eventDefinition can have other possible types, add them to Classes/ViewHelpers/CreateViewHelper.php:81
Loading history...
85
            ? $eventDefinition->getFullIdentifier()
86
            : null;
87
88
        $this->tag->addAttribute('href', $className::getCreationUri($selectedEvent));
89
        $this->tag->setContent($this->renderChildren());
90
91
        return $this->tag->render();
92
    }
93
}
94