forked from koala-framework/koala-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Component.php
86 lines (77 loc) · 2.49 KB
/
Component.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
class Kwc_Form_Field_Abstract_Component extends Kwc_Abstract
{
private $_formField;
public static function getSettings()
{
$ret = parent::getSettings();
$ret['ownModel'] = 'Kwf_Component_FieldModel';
$ret['flags']['formField'] = true;
$ret['viewCache'] = false;
$ret['extConfig'] = 'Kwf_Component_Abstract_ExtConfig_Form';
return $ret;
}
public function getTemplateVars()
{
$ret = parent::getTemplateVars();
$form = $this->_getForm();
//initialize form, sets formName on fields
$form->getComponent()->getForm();
$postData = array();
$errors = array();
if ($form->getComponent()->isProcessed()) {
//kann nicht processed sein wenn paragraphs der form im backend bearbeitet werden
$postData = $form->getComponent()->getPostData();
$errors = $this->_getForm()->getComponent()->getErrors();
}
$fieldVars = $this->getFormField()->getTemplateVars($postData);
$dec = Kwc_Abstract::getSetting($form->componentClass, 'decorator');
if ($dec && is_string($dec)) {
$dec = new $dec();
$fieldVars = $dec->processItem($fieldVars, $errors);
}
$ret = array_merge($ret, $fieldVars);
return $ret;
}
private function _getForm()
{
$ret = $this->getData();
while ($ret && !is_instance_of($ret->componentClass, 'Kwc_Form_Dynamic_Component')) {
$ret = $ret->parent;
}
$ret = $ret->getChildComponent('-form');
return $ret;
}
/**
* @return Kwf_Form_Field_Abstract
*/
protected function _getFormField()
{
return $this->getData()->chained->getComponent()->getFormField();
}
/**
* @return Kwf_Form_Field_Abstract
*/
public final function getFormField()
{
if (!isset($this->_formField)) {
$this->_formField = $this->_getFormField();
}
return $this->_formField;
}
/**
* This function is used to return a human-readable string for this field
* depending on submited data.
* @param Kwc_Form_Dynamic_Form_MailRow $row
* @return string
*/
public function getSubmitMessage($row)
{
$message = '';
if ($this->getFormField()->getFieldLabel()) {
$message .= $this->getFormField()->getFieldLabel().': ';
}
$message .= $row->{$this->getFormField()->getName()};
return $message;
}
}