|
1
|
|
|
<?php |
|
2
|
|
|
namespace midcom\datamanager\template; |
|
3
|
|
|
|
|
4
|
|
|
use Symfony\Component\Form\FormView; |
|
5
|
|
|
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView; |
|
6
|
|
|
|
|
7
|
|
|
class plaintext extends base |
|
8
|
|
|
{ |
|
9
|
|
|
public function form_rows(FormView $view, array $data) |
|
10
|
|
|
{ |
|
11
|
|
|
$ret = []; |
|
12
|
|
|
foreach ($view as $child) { |
|
13
|
|
|
$ret[] = $this->renderer->widget($child); |
|
14
|
|
|
} |
|
15
|
|
|
return implode(', ', array_filter($ret)); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
4 |
|
public function form_widget_simple(FormView $view, array $data) |
|
19
|
|
|
{ |
|
20
|
4 |
|
if ( !empty($data['value']) |
|
21
|
4 |
|
|| is_numeric($data['value'])) { |
|
22
|
4 |
|
return $data['value']; |
|
23
|
|
|
} |
|
24
|
4 |
|
return ''; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function form_widget_compound(FormView $view, array $data) |
|
28
|
|
|
{ |
|
29
|
|
|
return $this->renderer->block($view, 'form_rows'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function attachment_widget(FormView $view, array $data) |
|
33
|
|
|
{ |
|
34
|
|
|
if (!empty($data['value']['url'])) { |
|
35
|
|
|
return $data['value']['url']; |
|
36
|
|
|
} |
|
37
|
|
|
return ''; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function radiocheckselect_widget(FormView $view, array $data) |
|
41
|
|
|
{ |
|
42
|
|
|
$ret = []; |
|
43
|
|
|
foreach ($view->children as $child) { |
|
44
|
|
|
if ($child->vars['checked']) { |
|
45
|
|
|
$ret[] = $this->renderer->humanize($child->vars['label']); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
return implode(', ', $ret); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function image_widget(FormView $view, array $data) |
|
52
|
|
|
{ |
|
53
|
|
|
if (empty($data['value']['objects'])) { |
|
54
|
|
|
return ''; |
|
55
|
|
|
} |
|
56
|
|
|
if (array_key_exists('archival', $data['value']['objects'])) { |
|
57
|
|
|
return $data['value']['objects']['archival']['url']; |
|
58
|
|
|
} |
|
59
|
|
|
if (array_key_exists('main', $data['value']['objects'])) { |
|
60
|
|
|
return $data['value']['objects']['main']['url']; |
|
61
|
|
|
} |
|
62
|
|
|
$img = reset($data['value']['objects']); |
|
63
|
|
|
return $img['url']; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
2 |
|
public function autocomplete_widget(FormView $view, array $data) |
|
67
|
|
|
{ |
|
68
|
2 |
|
return implode(', ', $data['handler_options']['preset']); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
2 |
|
public function choice_widget_collapsed(FormView $view, array $data) |
|
72
|
|
|
{ |
|
73
|
2 |
|
if (isset($data['data'])) { |
|
74
|
2 |
|
if (!empty($data['multiple'])) { |
|
75
|
|
|
$selection = $data['data']; |
|
76
|
|
|
} else { |
|
77
|
2 |
|
$selection = (string) $data['data']; |
|
78
|
|
|
} |
|
79
|
2 |
|
foreach ($data['choices'] as $choice) { |
|
80
|
|
|
if ($choice instanceof ChoiceGroupView) { |
|
81
|
|
|
foreach ($choice->choices as $option) { |
|
82
|
|
|
if ($data['is_selected']($option->value, $selection)) { |
|
83
|
|
|
return $this->renderer->humanize($option->label); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
} elseif ($data['is_selected']($choice->value, $selection)) { |
|
87
|
|
|
return $this->renderer->humanize($choice->label); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
2 |
|
return ''; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function checkbox_widget(FormView $view, array $data) |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->renderer->humanize($data['checked'] ? 'yes' : 'no'); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function tinymce_widget(FormView $view, array $data) |
|
100
|
|
|
{ |
|
101
|
|
|
return $data['value']; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
2 |
|
public function jsdate_widget(FormView $view, array $data) |
|
105
|
|
|
{ |
|
106
|
2 |
|
if (empty($data['value']['date'])) { |
|
107
|
2 |
|
return ''; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
$formatter = \midcom::get()->i18n->get_l10n()->get_formatter(); |
|
111
|
|
|
$formatted = $formatter->date($data['value']['date']); |
|
112
|
|
|
if (isset($view['time'])) { |
|
113
|
|
|
$formatted .= ' ' . $formatter->time($data['value']['date'], (isset($data['value']['seconds'])) ? 'medium' : 'short'); |
|
114
|
|
|
} |
|
115
|
|
|
return $formatted; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|