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

craue / CraueFormFlowBundle / 15439473581

04 Jun 2025 10:02AM UTC coverage: 98.725% (-0.8%) from 99.482%
15439473581

push

github

craue
dropped support for Symfony 4.4, 6.3, 7.0, 7.1

697 of 706 relevant lines covered (98.73%)

838.74 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-2024 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;
1,575✔
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 [
144✔
41
                        new TwigFilter('craue_addDynamicStepNavigationParameters', [$this, 'addDynamicStepNavigationParameters']),
144✔
42
                        new TwigFilter('craue_removeDynamicStepNavigationParameters', [$this, 'removeDynamicStepNavigationParameters']),
144✔
43
                        // methods for BC with third-party templates (e.g. MopaBootstrapBundle)
44
                        new TwigFilter('craue_addDynamicStepNavigationParameter', [$this, 'addDynamicStepNavigationParameter']),
144✔
45
                        new TwigFilter('craue_removeDynamicStepNavigationParameter', [$this, 'removeDynamicStepNavigationParameter']),
144✔
46
                ];
144✔
47
        }
48

49
        /**
50
         * {@inheritDoc}
51
         */
52
        public function getFunctions() : array {
53
                return [
144✔
54
                        new TwigFunction('craue_isStepLinkable', [$this, 'isStepLinkable']),
144✔
55
                ];
144✔
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);
468✔
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);
504✔
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()
1,431✔
86
                                || $flow->getCurrentStepNumber() === $stepNumber
1,431✔
87
                                || $flow->isStepSkipped($stepNumber)) {
1,431✔
88
                        return false;
1,431✔
89
                }
90

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

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

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

106
                return false;
468✔
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);
9✔
113
                return $this->addDynamicStepNavigationParameters($parameters, $flow, $stepNumber);
9✔
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);
9✔
118
                return $this->removeDynamicStepNavigationParameters($parameters, $flow);
9✔
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