• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

craue / CraueFormFlowBundle / 6035545729

31 Aug 2023 09:27AM UTC coverage: 99.15% (-0.3%) from 99.483%
6035545729

push

github

craue
try using `Types::TEXT` for the value column

2 of 2 new or added lines in 1 file covered. (100.0%)

700 of 706 relevant lines covered (99.15%)

464.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.67
/Twig/Extension/FormFlowExtension.php
1
<?php
2

3
namespace Craue\FormFlowBundle\Twig\Extension;
4

5
use Craue\FormFlowBundle\Form\FormFlow;
6
use Craue\FormFlowBundle\Util\FormFlowUtil;
7
use Twig\Extension\AbstractExtension;
8
use Twig\TwigFilter;
9
use Twig\TwigFunction;
10

11
/**
12
 * Twig extension for form flows.
13
 *
14
 * @author Christian Raue <christian.raue@gmail.com>
15
 * @copyright 2011-2023 Christian Raue
16
 * @license http://opensource.org/licenses/mit-license.php MIT License
17
 */
18
class FormFlowExtension extends AbstractExtension {
19

20
        /**
21
         * @var FormFlowUtil
22
         */
23
        protected $formFlowUtil;
24

25
        public function setFormFlowUtil(FormFlowUtil $formFlowUtil) {
26
                $this->formFlowUtil = $formFlowUtil;
873✔
27
        }
28

29
        /**
30
         * {@inheritDoc}
31
         */
32
        public function getName() {
33
                return 'craue_formflow';
×
34
        }
35

36
        /**
37
         * {@inheritDoc}
38
         */
39
        public function getFilters() : array {
40
                return [
78✔
41
                        new TwigFilter('craue_addDynamicStepNavigationParameters', [$this, 'addDynamicStepNavigationParameters']),
78✔
42
                        new TwigFilter('craue_removeDynamicStepNavigationParameters', [$this, 'removeDynamicStepNavigationParameters']),
78✔
43
                        // methods for BC with third-party templates (e.g. MopaBootstrapBundle)
44
                        new TwigFilter('craue_addDynamicStepNavigationParameter', [$this, 'addDynamicStepNavigationParameter']),
78✔
45
                        new TwigFilter('craue_removeDynamicStepNavigationParameter', [$this, 'removeDynamicStepNavigationParameter']),
78✔
46
                ];
78✔
47
        }
48

49
        /**
50
         * {@inheritDoc}
51
         */
52
        public function getFunctions() : array {
53
                return [
78✔
54
                        new TwigFunction('craue_isStepLinkable', [$this, 'isStepLinkable']),
78✔
55
                ];
78✔
56
        }
57

58
        /**
59
         * Adds route parameters for dynamic step navigation.
60
         * @param array $parameters Current route parameters.
61
         * @param FormFlow $flow The flow involved.
62
         * @param int $stepNumber Number of the step the link will be generated for.
63
         * @return array Route parameters plus instance and step parameter.
64
         */
65
        public function addDynamicStepNavigationParameters(array $parameters, FormFlow $flow, $stepNumber) {
66
                return $this->formFlowUtil->addRouteParameters($parameters, $flow, $stepNumber);
260✔
67
        }
68

69
        /**
70
         * Removes route parameters for dynamic step navigation.
71
         * @param array $parameters Current route parameters.
72
         * @param FormFlow $flow The flow involved.
73
         * @return array Route parameters without instance and step parameter.
74
         */
75
        public function removeDynamicStepNavigationParameters(array $parameters, FormFlow $flow) {
76
                return $this->formFlowUtil->removeRouteParameters($parameters, $flow);
280✔
77
        }
78

79
        /**
80
         * @param FormFlow $flow The flow involved.
81
         * @param int $stepNumber Number of the step the link will be generated for.
82
         * @return bool If the step can be linked to.
83
         */
84
        public function isStepLinkable(FormFlow $flow, $stepNumber) {
85
                if (!$flow->isAllowDynamicStepNavigation()
793✔
86
                                || $flow->getCurrentStepNumber() === $stepNumber
793✔
87
                                || $flow->isStepSkipped($stepNumber)) {
793✔
88
                        return false;
793✔
89
                }
90

91
                $lastStepConsecutivelyDone = 0;
260✔
92
                for ($i = $flow->getFirstStepNumber(), $lastStepNumber = $flow->getLastStepNumber(); $i < $lastStepNumber; ++$i) {
260✔
93
                        if ($flow->isStepDone($i)) {
260✔
94
                                $lastStepConsecutivelyDone = $i;
260✔
95
                        } else {
96
                                break;
260✔
97
                        }
98
                }
99

100
                $lastStepLinkable = $lastStepConsecutivelyDone + 1;
260✔
101

102
                if ($stepNumber <= $lastStepLinkable) {
260✔
103
                        return true;
260✔
104
                }
105

106
                return false;
260✔
107
        }
108

109
        // methods for BC with third-party templates (e.g. MopaBootstrapBundle)
110

111
        public function addDynamicStepNavigationParameter(array $parameters, FormFlow $flow, $stepNumber) {
112
                @trigger_error('Twig filter craue_addDynamicStepNavigationParameter is deprecated since CraueFormFlowBundle 3.0. Use filter craue_addDynamicStepNavigationParameters instead.', E_USER_DEPRECATED);
5✔
113
                return $this->addDynamicStepNavigationParameters($parameters, $flow, $stepNumber);
5✔
114
        }
115

116
        public function removeDynamicStepNavigationParameter(array $parameters, FormFlow $flow) {
117
                @trigger_error('Twig filter craue_removeDynamicStepNavigationParameter is deprecated since CraueFormFlowBundle 3.0. Use filter craue_removeDynamicStepNavigationParameters instead.', E_USER_DEPRECATED);
5✔
118
                return $this->removeDynamicStepNavigationParameters($parameters, $flow);
5✔
119
        }
120

121
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc