|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** Core forms view helpers */ |
|
11
|
|
|
namespace Core\Form\View\Helper; |
|
12
|
|
|
|
|
13
|
|
|
use Core\Form\ViewPartialProviderInterface; |
|
14
|
|
|
use Core\Form\ExplicitParameterProviderInterface; |
|
15
|
|
|
use Core\Form\Element\ViewHelperProviderInterface; |
|
16
|
|
|
use Core\Form\Container; |
|
17
|
|
|
use Core\Form\WizardContainer; |
|
18
|
|
|
use Zend\Form\View\Helper\AbstractHelper; |
|
19
|
|
|
use Core\Form\SummaryForm; |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Helper for rendering form wizard containers |
|
23
|
|
|
* |
|
24
|
|
|
* @author Mathias Gelhausen <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class FormWizardContainer extends AbstractHelper |
|
27
|
|
|
{ |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Invoke as function. |
|
31
|
|
|
* |
|
32
|
|
|
* Proxies to {@link render()} or returns self. |
|
33
|
|
|
* |
|
34
|
|
|
* @param null|Container $container |
|
35
|
|
|
* @param string $layout |
|
36
|
|
|
* @param array $parameter |
|
37
|
|
|
* @return FormContainer|string |
|
|
|
|
|
|
38
|
|
|
*/ |
|
39
|
|
View Code Duplication |
public function __invoke(Container $container = null, $layout = Form::LAYOUT_HORIZONTAL, $parameter = array()) |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
if (!$container) { |
|
42
|
|
|
return $this; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return $this->render($container, $layout, $parameter); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Renders the forms of a container. |
|
50
|
|
|
* |
|
51
|
|
|
* @param WizardContainer $container |
|
52
|
|
|
* @param string $layout |
|
53
|
|
|
* @param array $parameter |
|
54
|
|
|
* @return string |
|
55
|
|
|
*/ |
|
56
|
|
|
public function render(WizardContainer $container, $layout = Form::LAYOUT_HORIZONTAL, $parameter = array()) |
|
57
|
|
|
{ |
|
58
|
|
|
|
|
59
|
|
|
$content = ''; |
|
60
|
|
|
|
|
61
|
|
|
$content .= $container->renderPre($this->getView()); |
|
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
$tabsNav = ''; |
|
64
|
|
|
$tabsContent = ''; |
|
65
|
|
|
$containerParams = [ |
|
66
|
|
|
'pager' => true, |
|
67
|
|
|
'finish_label' => 'Finish', |
|
68
|
|
|
'finish_href' => 'javascript:;', |
|
69
|
|
|
'finish_enabled' => true, |
|
70
|
|
|
]; |
|
71
|
|
|
|
|
72
|
|
|
if (isset($parameter['wizard'])) { |
|
73
|
|
|
$containerParams = array_merge($containerParams, $parameter['wizard']); |
|
74
|
|
|
unset($parameter['wizard']); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$translate = $this->getView()->plugin('translate'); |
|
|
|
|
|
|
78
|
|
|
$formContainer = $this->getView()->plugin('formcontainer'); |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
if ($container instanceof ViewPartialProviderInterface) { |
|
81
|
|
|
return $this->getView()->partial($container->getViewPartial(), array('element' => $container)); |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$containerId = $container->getAttribute('id'); |
|
85
|
|
|
if (!$containerId) { |
|
86
|
|
|
$containerId = 'wizardcontainer-' . strtolower(str_replace('\\', '-', get_class($container))); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
foreach ($container as $tabElement) { |
|
90
|
|
|
$tabId = $containerId . '-' . strtolower($tabElement->getName()); |
|
91
|
|
|
$tabsNav .= '<li><a data-toggle="tab" href="#' . $tabId . '">' . $translate($tabElement->getLabel()) . '</a></li>'; |
|
92
|
|
|
$tabsContent .= '<div class="tab-pane" id="' . $tabId . '">' |
|
93
|
|
|
. $formContainer($tabElement, $layout, $parameter) |
|
94
|
|
|
. '</div>'; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
$content .= '<style type="text/css">.tab-content > div > div:first-child { margin-top: 10px; }</style><div class="wizard-container" id="' . $containerId . '">' |
|
98
|
|
|
. '<ul>' . $tabsNav . '</ul>' |
|
99
|
|
|
. '<div class="tab-content">' . $tabsContent . '</div>'; |
|
100
|
|
|
if ($containerParams['pager']) { |
|
101
|
|
|
$content .='<ul class="pager wizard">' |
|
102
|
|
|
. '<li class="previous"><a href="javascript:;">← ' . $translate('previous') . '</a></li>' |
|
103
|
|
|
. '<li class="next"><a href="javascript:;">' . $translate('Next') . ' →</a></li>' |
|
104
|
|
|
. '<li class="finish' . ($containerParams['finish_enabled'] ? '' : ' disabled') . '">' |
|
105
|
|
|
. (false !== $containerParams['finish_label'] |
|
106
|
|
|
? '<a class="pull-right" href="' . $containerParams['finish_href'] . '">' |
|
107
|
|
|
. $translate($containerParams['finish_label']) . ' •</a>' |
|
108
|
|
|
: '' |
|
109
|
|
|
) |
|
110
|
|
|
. '</li></ul>'; |
|
111
|
|
|
} |
|
112
|
|
|
$content .= '</div>'; |
|
113
|
|
|
|
|
114
|
|
|
$content .= $container->renderPost($this->getView()); |
|
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
return $content; |
|
117
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: