Completed
Push — wip/steps ( 7c3be8...c6080c )
by Romain
16:53
created

PreviousLinkViewHelper::initializeArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 5
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
/*
3
 * 2017 Romain CANON <[email protected]>
4
 *
5
 * This file is part of the TYPO3 FormZ project.
6
 * It is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License, either
8
 * version 3 of the License, or any later version.
9
 *
10
 * For the full copyright and license information, see:
11
 * http://www.gnu.org/licenses/gpl-3.0.html
12
 */
13
14
namespace Romm\Formz\ViewHelpers\Step;
15
16
use Romm\Formz\Middleware\Item\Step\Service\StepMiddlewareService;
17
use Romm\Formz\Service\ViewHelper\Form\FormViewHelperService;
18
use TYPO3\CMS\Extbase\Mvc\Web\Request;
19
use TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper;
20
21
class PreviousLinkViewHelper extends AbstractFormFieldViewHelper
22
{
23
    const PREVIOUS_LINK_PARAMETER = 'substepsPrevious';
24
25
    /**
26
     * @var string
27
     */
28
    protected $tagName = 'input';
29
30
    /**
31
     * @var FormViewHelperService
32
     */
33
    protected $formService;
34
35
    public function initializeArguments()
36
    {
37
        parent::initializeArguments();
38
        $this->registerUniversalTagAttributes();
39
    }
40
41
    public function render()
42
    {
43
        /*
44
         * First, we check if this view helper is called from within the
45
         * `FormViewHelper`, because it would not make sense anywhere else.
46
         */
47
        if (false === $this->formService->formContextExists()) {
48
            // @todo
49
//            throw ContextNotFoundException::substepViewHelperFormContextNotFound();
50
        }
51
52
        $formObject = $this->formService->getFormObject();
53
        $formDefinition = $formObject->getDefinition();
54
55
        if (false === $formDefinition->hasSteps()) {
56
            throw new \Exception('todo'); // @todo
57
        }
58
59
        /** @var Request $request */
60
        $request = $this->controllerContext->getRequest();
61
        $currentStep = $formObject->fetchCurrentStep($request)->getCurrentStep();
62
        $stepDefinition = StepMiddlewareService::get()->getStepDefinition($currentStep);
63
64
        // @todo handle previous steps depth
65
        if (!$stepDefinition->hasPreviousDefinition()
66
            && !$currentStep->hasSubsteps()
67
        ) {
68
            return null;
69
        }
70
71
        $this->tag->addAttribute('type', 'submit');
72
        $this->tag->addAttribute('value', $this->getValueAttribute());
73
        $this->tag->addAttribute('name', $this->prefixFieldName(PreviousLinkViewHelper::PREVIOUS_LINK_PARAMETER));
74
        $this->tag->addAttribute('fz-previous-link', true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
75
76
        return $this->tag->render();
77
    }
78
79
    /**
80
     * @param FormViewHelperService $service
81
     */
82
    public function injectFormService(FormViewHelperService $service)
83
    {
84
        $this->formService = $service;
85
    }
86
}
87