|
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
|
|
|
namespace Core\Form\View\Helper; |
|
11
|
|
|
|
|
12
|
|
|
use Core\Form\CollectionContainer; |
|
13
|
|
|
use Zend\Form\View\Helper\AbstractHelper; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Helper for rendering form collection containers |
|
17
|
|
|
* |
|
18
|
|
|
* @author fedys |
|
19
|
|
|
*/ |
|
20
|
|
|
class FormCollectionContainer extends AbstractHelper |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var bool |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $displayRemoveButton = true; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Invoke as function. |
|
30
|
|
|
* |
|
31
|
|
|
* Proxies to {@link render()} or returns self. |
|
32
|
|
|
* |
|
33
|
|
|
* @param null|CollectionContainer $container |
|
34
|
|
|
* @param string $layout |
|
35
|
|
|
* @param array $parameter |
|
36
|
|
|
* @return FormCollectionContainer|string |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __invoke(CollectionContainer $container = null, $layout = Form::LAYOUT_HORIZONTAL, $parameter = []) |
|
39
|
|
|
{ |
|
40
|
|
|
if (!$container) { |
|
41
|
|
|
return $this; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
return $this->render($container, $layout, $parameter); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Renders the forms of a container. |
|
49
|
|
|
* |
|
50
|
|
|
* @param CollectionContainer $container |
|
51
|
|
|
* @param string $layout |
|
52
|
|
|
* @param array $parameter |
|
53
|
|
|
* @return string |
|
54
|
|
|
*/ |
|
55
|
|
|
public function render(CollectionContainer $container, $layout = Form::LAYOUT_HORIZONTAL, $parameter = []) |
|
56
|
|
|
{ |
|
57
|
|
|
$view = $this->getView(); |
|
58
|
|
|
$view->headscript() |
|
59
|
|
|
->appendFile($view->basePath('Core/js/jquery.formcollection-container.js')); |
|
60
|
|
|
$translator = $this->getTranslator(); |
|
61
|
|
|
$formContainerHelper = $view->formContainer(); |
|
|
|
|
|
|
62
|
|
|
$formsMarkup = ''; |
|
63
|
|
|
$formTemplateWrapper = '<div class="form-collection-container-form"> |
|
64
|
|
|
'. ($this->displayRemoveButton ? '<button type="button" class="btn btn-sm btn-danger pull-right form-collection-container-remove-button">' . $translator->translate('Remove') . '</button>' : '') . ' |
|
65
|
|
|
%s |
|
66
|
|
|
</div>'; |
|
67
|
|
|
|
|
68
|
|
|
foreach ($container as $form) /* @var $form \Zend\Form\Form */ |
|
69
|
|
|
{ |
|
70
|
|
|
$formsMarkup .= sprintf($formTemplateWrapper, $formContainerHelper->renderElement($form, $layout, $parameter)); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$templateForm = $container->getTemplateForm(); |
|
74
|
|
|
$templateMarkup = sprintf( |
|
75
|
|
|
$view->formCollection()->getTemplateWrapper(), |
|
|
|
|
|
|
76
|
|
|
$view->escapeHtmlAttr(sprintf($formTemplateWrapper, $formContainerHelper->renderElement($templateForm, $layout, $parameter))) |
|
77
|
|
|
); |
|
78
|
|
|
|
|
79
|
|
|
return sprintf('<div class="form-collection-container" data-new-entry-key="%s" data-remove-action="%s" data-remove-question="%s"> |
|
80
|
|
|
<h3>%s</h3> |
|
81
|
|
|
%s%s%s |
|
82
|
|
|
</div>', |
|
83
|
|
|
CollectionContainer::NEW_ENTRY, |
|
84
|
|
|
$container->formatAction('remove'), |
|
85
|
|
|
$translator->translate('Really remove?'), |
|
86
|
|
|
$container->getLabel(), |
|
87
|
|
|
$formsMarkup, |
|
88
|
|
|
$templateMarkup, |
|
89
|
|
|
'<div class="form-collection-container-add-wrapper"><button type="button" class="btn btn-success form-collection-container-add-button"><span class="yk-icon yk-icon-plus"></span> ' . sprintf($translator->translate('Add %s'), $container->getLabel()) . '</button></div>' |
|
90
|
|
|
); |
|
91
|
|
|
} |
|
92
|
|
|
/** |
|
93
|
|
|
* @param boolean $displayRemoveButton |
|
94
|
|
|
* @return FormCollectionContainer |
|
95
|
|
|
* @since 0.26 |
|
96
|
|
|
*/ |
|
97
|
|
|
public function setDisplayRemoveButton($displayRemoveButton) |
|
98
|
|
|
{ |
|
99
|
|
|
$this->displayRemoveButton = (bool)$displayRemoveButton; |
|
100
|
|
|
|
|
101
|
|
|
return $this; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.