Completed
Push — master ( e040be...e42b8e )
by Andreas
13:39
created

form::choice_widget_collapsed()   C

Complexity

Conditions 15
Paths 37

Size

Total Lines 37
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 37.1155

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 15
eloc 25
c 3
b 0
f 0
nc 37
nop 2
dl 0
loc 37
ccs 14
cts 26
cp 0.5385
crap 37.1155
rs 5.9166

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 form extends base
8
{
9 2
    private function get_view_renderer()
10
    {
11 2
        return new view($this->renderer);
12
    }
13
14 48
    public function form_start(FormView $view, array $data)
15
    {
16 48
        $attributes = $data['attr'];
17 48
        $attributes['name'] = $data['name'];
18 48
        $attributes['id'] = $data['name'];
19 48
        $attributes['method'] = strtolower($data['method']);
20 48
        $attributes['action'] = $data['action'];
21 48
        $attributes['class'] = 'datamanager2';
22
23 48
        if ($data['multipart']) {
24 10
            $attributes['enctype'] = 'multipart/form-data';
25
        }
26
27 48
        return '<form ' . $this->attributes($attributes) . '>';
28
    }
29
30 47
    public function form_errors(FormView $view, array $data)
31
    {
32 47
        $errors = [];
33 47
        foreach ($data['errors'] as $error) {
34
            $params = $error->getMessageParameters();
35
            $message = $error->getMessage();
36
            foreach ($params as $param) {
37
                if (strpos($message, $param)) {
38
                    $message = str_replace($param, $this->renderer->humanize($param), $message);
39
                }
40
            }
41
            $errors[] = '<div class="field_error">' . $this->renderer->humanize($message) . '</div>';
42
        }
43
44 47
        return implode('', $errors);
45
    }
46
47 47
    public function form_rows(FormView $view, array $data)
48
    {
49 47
        $string = '';
50 47
        foreach ($view as $child) {
51 47
            if (!empty($child->vars['hidden'])) {
52 6
                $child->setRendered();
53 6
                continue;
54
            }
55 47
            if ($child->vars['start_fieldset'] !== null) {
56 24
                if (!empty($child->vars['start_fieldset']['css_group'])) {
57 21
                    $class = $child->vars['start_fieldset']['css_group'];
58
                } else {
59 3
                    $class = $child->vars['name'];
60
                }
61 24
                $string .= '<fieldset class="fieldset ' . $class . '">';
62 24
                if (!empty($child->vars['start_fieldset']['title'])) {
63 24
                    $string .= '<legend>' . $this->renderer->humanize($child->vars['start_fieldset']['title']) . '</legend>';
64
                }
65
            }
66 47
            $string .= $this->renderer->row($child);
67 47
            if ($child->vars['end_fieldset'] !== null) {
68 27
                $end_fieldsets = max(1, (int) $child->vars['end_fieldset']);
69 47
                $string .= str_repeat('</fieldset>', $end_fieldsets);
70
            }
71
        }
72 47
        return $string;
73
    }
74
75 48
    public function form_end(FormView $view, array $data)
76
    {
77 48
        $string = '';
78 48
        if (   !isset($data['render_rest'])
79 48
            || $data['render_rest']) {
80 48
            $string .= $this->renderer->rest($view);
81
        }
82 48
        return $string . '</form>';
83
    }
84
85 46
    public function form_row(FormView $view, array $data)
86
    {
87 46
        $class = 'element element_' . $view->vars['block_prefixes'][count($view->vars['block_prefixes']) - 2];
88
89 46
        if ($view->vars['required']) {
90 27
            $class .= ' required';
91
        }
92
93 46
        if ($data['errors']->count() > 0) {
94
            $class .= ' error';
95
        }
96
97 46
        $string = '<div class="' . $class . '">';
98 46
        $string .= $this->renderer->label($view);
99 46
        $string .= '<div class="input">';
100 46
        $string .= $this->renderer->errors($view);
101 46
        $string .= $this->renderer->widget($view);
102 46
        return $string . '</div></div>';
103
    }
104
105 26
    public function autocomplete_row(FormView $view, array $data)
106
    {
107 26
        $class = 'element element_' . $view->vars['block_prefixes'][count($view->vars['block_prefixes']) - 2];
108
109 26
        if ($view->vars['required']) {
110 7
            $class .= ' required';
111
        }
112
113 26
        if ($data['errors']->count() > 0) {
114
            $class .= ' error';
115
        }
116
117 26
        $string = '<div class="' . $class . '">';
118 26
        $string .= $this->renderer->label($view);
119 26
        $string .= '<div class="input">';
120
121 26
        if ($data['errors']->count() > 0) {
122
            $string .= $this->renderer->errors($view) . '<br>';
123
        }
124 26
        $string .= $this->renderer->widget($view);
125 26
        return $string . '</div></div>';
126
    }
127
128
    public function button_row(FormView $view, array $data)
129
    {
130
        $string = '<div>';
131
        $string .= $this->renderer->widget($view);
132
        return $string . '</div>';
133
    }
134
135 16
    public function hidden_row(FormView $view, array $data)
136
    {
137 16
        return $this->renderer->widget($view);
138
    }
139
140 48
    public function toolbar_row(FormView $view, array $data)
141
    {
142 48
        $string = '<div class="form_toolbar">';
143 48
        foreach ($view as $child) {
144 48
            $string .= $this->renderer->widget($child);
145
        }
146 48
        return $string . '</div>';
147
    }
148
149 1
    public function repeated_row(FormView $view, array $data)
150
    {
151 1
        $view->children['second']->vars['label'] = $this->renderer->humanize($view->children['first']->vars['label']) . ' ' . $this->renderer->humanize($view->children['second']->vars['label']);
152 1
        $string = '';
153 1
        foreach ($view->children as $child) {
154 1
            $string .= $this->form_row($child, $data);
155
        }
156 1
        return $string;
157
    }
158
159 5
    public function attachment_row(FormView $view, array $data)
160
    {
161 5
        $string = '<fieldset ' . $this->renderer->block($view, 'widget_container_attributes') . '>';
162 5
        $string .= '<legend>';
163 5
        $string .= (!empty($data['value']['filename'])) ? $data['value']['filename'] : $this->renderer->humanize('add new file');
164 5
        $string .= '</legend>';
165
166 5
        $string .= '<div class="attachment-container">';
167 5
        $string .= '<div class="attachment-preview">';
168 5
        if (!empty($data['value']['filename'])) {
169
            $ext = pathinfo($data['value']['filename'], PATHINFO_EXTENSION);;
170
            $string .= '<a href="' . $data['value']['url'] . '" target="_blank" class="icon" title="' . $data['value']['filename'] . '">';
171
            $string .= '<i class="fa fa-file-o"></i><span class="extension">' . $ext . '</span></a>';
172
        } else {
173 5
            $string .= '<span class="icon no-file"><i class="fa fa-file-o"></i></span>';
174
        }
175
176 5
        $string .= '</div><div class="attachment-input">';
177 5
        foreach ($view->children as $child) {
178 5
            $string .= $this->renderer->row($child);
179
        }
180
181 5
        $string .= '</div></div>';
182 5
        $string .= $this->jsinit('dm_attachment_init("' . $data['form']['file']->vars['id'] . '")');
183 5
        return $string . '</fieldset>';
184
    }
185
186 4
    public function image_row(FormView $view, array $data)
187
    {
188 4
        if (!in_array('subform', $view->parent->vars['block_prefixes'])) {
189 3
            return $this->form_row($view, $data);
190
        }
191
192 1
        $string = '<fieldset ' . $this->renderer->block($view, 'widget_container_attributes') . '>';
193 1
        $string .= '<legend>';
194 1
        $string .= (!empty($data['value']['objects']['main']['filename'])) ? preg_replace('/^.+?\-/', '', $data['value']['objects']['main']['filename']) : $this->renderer->humanize('add new file');
195 1
        $string .= '</legend>';
196
197 1
        $string .= $this->renderer->widget($view);
198
199 1
        return $string . '</fieldset>';
200
    }
201
202 45
    public function form_widget_simple(FormView $view, array $data)
203
    {
204 45
        $type = $data['type'] ?? 'text';
205 45
        if ($view->vars['readonly'] && $type !== 'hidden') {
206 3
            $data['type'] = 'hidden';
207 3
            return $data['value'] . $this->renderer->block($view, 'form_widget_simple', $data);
208
        }
209
210 45
        if (empty($data['attr']['class']) && in_array($type, ['text', 'password', 'email', 'url'])) {
211 45
            $data['attr']['class'] = 'shorttext';
212
        }
213
214 45
        if (   !empty($data['value'])
215 45
            || is_numeric($data['value'])) {
216 40
            $data['attr']['value'] = $data['value'];
217
        }
218 45
        $data['attr']['type'] = $type;
219 45
        return '<input ' . $this->renderer->block($view, 'widget_attributes', $data) . ' />';
220
    }
221
222 48
    public function button_widget(FormView $view, array $data)
223
    {
224 48
        $type = $data['type'] ?? 'button';
225 48
        if (!$data['label']) {
226
            $data['label'] = $data['name'];
227
        }
228
229 48
        return '<button type="' . $type . '" ' . $this->renderer->block($view, 'button_attributes') . '>' . $this->renderer->humanize($data['label']) . '</button>';
230
    }
231
232 32
    public function hidden_widget(FormView $view, array $data)
233
    {
234 32
        return $this->renderer->block($view, 'form_widget_simple', ['type' => $data['type'] ?? "hidden"]);
235
    }
236
237 9
    public function email_widget(FormView $view, array $data)
238
    {
239 9
        return $this->renderer->block($view, 'form_widget_simple', ['type' => $data['type'] ?? "email"]);
240
    }
241
242 1
    public function password_widget(FormView $view, array $data)
243
    {
244 1
        return $this->renderer->block($view, 'form_widget_simple', ['type' => $data['type'] ?? "password"]);
245
    }
246
247 5
    public function url_widget(FormView $view, array $data)
248
    {
249 5
        return $this->renderer->block($view, 'form_widget_simple', ['type' => $data['type'] ?? "url"]);
250
    }
251
252 26
    public function autocomplete_widget(FormView $view, array $data)
253
    {
254 26
        $element_id = $view->vars['id'];
255 26
        $jsinit = 'window.' . $element_id . '_handler_options = ' . $data['handler_options'] . ";\n";
256 26
        $jsinit .= "midcom_helper_datamanager2_autocomplete.create_dm2_widget('{$element_id}_search_input', {$data['min_chars']});\n";
257
258 26
        $string = '<fieldset ' . $this->renderer->block($view, 'widget_container_attributes') . '>';
259 26
        $string .=  $this->renderer->widget($view['selection']);
260 26
        $string .= ' ' . $this->renderer->widget($view['search_input']);
261 26
        $string .= '</fieldset>';
262 26
        return $string . $this->jsinit($jsinit);
263
    }
264
265 24
    protected function prepare_widget_attributes($type, FormView $view, array &$data)
266
    {
267 24
        $data['attr']['type'] = $type;
268 24
        if (isset($data['value'])) {
269 24
            $data['attr']['value'] = $data['value'];
270
        }
271 24
        if ($data['checked']) {
272 16
            $data['attr']['checked'] = 'checked';
273
        }
274 24
    }
275
276 15
    public function radio_widget(FormView $view, array $data)
277
    {
278 15
        $this->prepare_widget_attributes('radio', $view, $data);
279 15
        if ($view->vars['readonly']) {
280
            $data['attr']['disabled'] = true;
281
        }
282
283 15
        return '<input ' . $this->renderer->block($view, 'widget_attributes', $data) . ' />';
284
    }
285
286 15
    public function checkbox_widget(FormView $view, array $data)
287
    {
288 15
        if ($view->vars['readonly']) {
289
            $string = $this->get_view_renderer()->checkbox_widget($view, $data);
290
            if ($data['checked']) {
291
                $string .= $this->renderer->block($view, 'form_widget_simple', ['type' => "hidden"]);
292
            }
293
            return $string;
294
        }
295 15
        $this->prepare_widget_attributes('checkbox', $view, $data);
296
297 15
        return '<input ' . $this->renderer->block($view, 'widget_attributes', $data) . ' />';
298
    }
299
300 27
    public function choice_widget_collapsed(FormView $view, array $data)
301
    {
302 27
        if ($view->vars['readonly'] && empty($view->vars['multiple'])) {
303
            $string = $this->get_view_renderer()->choice_widget_collapsed($view, $data);
304
            return $string . $this->renderer->block($view, 'form_widget_simple', ['type' => "hidden"]);
305
        }
306
307 27
        $string = '<select ';
308 27
        if (   $data['required']
309 27
            && null === $data['placeholder']
310 27
            && $data['placeholder_in_choices'] === false
311 27
            && $data['multiple'] === false) {
312
            $data['required'] = false;
313
        }
314
315 27
        if ($data['multiple']) {
316 4
            $data['attr']['multiple'] = 'multiple';
317
        }
318
319 27
        $string .= $this->renderer->block($view, 'widget_attributes', $data) . '>';
320 27
        if (null !== $data['placeholder']) {
321
            $string .= '<option value=""';
322
            if (   $data['required']
323
                && empty($data['value'])
324
                && "0" !== $data['value']) {
325
                $string .= ' selected="selected"';
326
            }
327
            $string .= '>' . $data['placeholder'] . '</option>';
328
        }
329 27
        if (count($data['preferred_choices']) > 0) {
330
            $string .= $this->renderer->block($view, 'choice_widget_options', ['choices' => $data['preferred_choices']]);
331
            if (count($data['choices']) > 0 && null !== $data['separator']) {
332
                $string .= '<option disabled="disabled">' . $data['separator'] . '</option>';
333
            }
334
        }
335 27
        $string .= $this->renderer->block($view, 'choice_widget_options', ['choices' => $data['choices']]);
336 27
        return $string . '</select>';
337
    }
338
339
    public function privilege_widget(FormView $view, array $data)
340
    {
341
        if (isset($view->vars['effective_value'])) {
342
            if ($view->vars['effective_value']) {
343
                $label = $this->renderer->humanize('widget privilege: allow');
344
            } else {
345
                $label = $this->renderer->humanize('widget privilege: deny');
346
            }
347
            $new_label = sprintf($this->renderer->humanize('widget privilege: inherit %s'), $label);
348
            $view->children[2]->vars['label'] = $new_label;
349
        }
350
        return $this->choice_widget_expanded($view, $data);
351
    }
352
353 1
    public function privilegeselection_widget(FormView $view, array $data)
354
    {
355 1
        $string = '<div class="holder">' . $this->choice_widget_collapsed($view, $data) . '</div>';
356 1
        return $string . $this->jsinit($view->vars['jsinit']);
357
    }
358
359 15
    public function choice_widget_expanded(FormView $view, array $data)
360
    {
361 15
        $string = '<fieldset ' . $this->renderer->block($view, 'widget_container_attributes') . '>';
362 15
        foreach ($view as $child) {
363 15
            $string .= $this->renderer->widget($child);
364 15
            $string .= '<label for="' . $child->vars['id'] . '">' . $this->renderer->humanize($child->vars['label']) . '</label>';
365
        }
366 15
        return $string . '</fieldset>';
367
    }
368
369 27
    public function choice_widget_options(FormView $view, array $data)
370
    {
371 27
        $string = '';
372 27
        foreach ($data['choices'] as $index => $choice) {
373 25
            if (is_array($choice) || $choice instanceof ChoiceGroupView) {
374
                $string .= '<optgroup label="' . $index . '">';
375
                $string .= $this->renderer->block($view, 'choice_widget_options', ['choices' => $choice]);
376
                $string .= '</optgroup>';
377
            } else {
378 25
                $choice->attr['value'] = $choice->value;
379 25
                if ($data['is_selected']($choice->value, $data['value'])) {
380 16
                    $choice->attr['selected'] = 'selected';
381
                } else {
382 25
                    unset($choice->attr['selected']);
383
                }
384
385 25
                $string .= '<option ' . $this->attributes($choice->attr);
386 25
                $string .= '>' . $this->renderer->humanize($choice->label) . '</option>';
387
            }
388
        }
389 27
        return $string;
390
    }
391
392 2
    public function other_widget(FormView $view, array $data)
393
    {
394 2
        $string = '<fieldset ' . $this->renderer->block($view, 'widget_container_attributes') . '>';
395 2
        $string .= $this->renderer->widget($view->children['select']);
396 2
        $string .= $this->renderer->humanize($view->children['other']->vars['label']) . ': ' . $this->renderer->widget($view->children['other'], ['attr' => ['class' => 'other']]);
397 2
        return $string . '</fieldset>';
398
    }
399
400
    public function captcha_widget(FormView $view, array $data)
401
    {
402
        $alt = $this->renderer->humanize('captcha image alt text');
403
        $string = '<fieldset class="captcha">';
404
        $string .= "<img src='{$view->vars['captcha_url']}' alt='{$alt}' text='{$alt}' class='captcha'><br>";
405
        $string .= $this->renderer->humanize('captcha message');
406
        $data['attr']['class'] = 'captcha';
407
        $data['value'] = '';
408
        $string .= $this->form_widget_simple($view, $data);
409
        return $string . '</fieldset>';
410
    }
411
412 3
    public function codemirror_widget(FormView $view, array $data)
413
    {
414
        // we set required to false, because codemirror doesn't play well with html5 validation..
415 3
        $data['required'] = false;
416 3
        $string = '<textarea ' . $this->renderer->block($view, 'widget_attributes', $data) . '>';
417 3
        $string .= $data['value'] . '</textarea>';
418 3
        if (!empty($data['codemirror_snippet'])) {
419 3
            $snippet = str_replace('{$id}', $data['id'], $data['codemirror_snippet']);
420 3
            $snippet = str_replace('{$read_only}', 'false', $snippet);
421 3
            $string .= $this->jsinit($snippet);
422
        }
423 3
        return $string;
424
    }
425
426 12
    public function jsdate_widget(FormView $view, array $data)
427
    {
428 12
        $string = '<fieldset ' . $this->renderer->block($view, 'widget_container_attributes') . '>';
429
430 12
        if ($view->vars['readonly']) {
431 1
            $string .= $this->get_view_renderer()->jsdate_widget($view, $data);
432 1
            $string .= $this->renderer->widget($view['date'], ['type' => 'hidden']);
433 1
            if (isset($view['time'])) {
434 1
                $string .= $this->renderer->widget($view['time'], ['type' => 'hidden']);
435
            }
436
        } else {
437 12
            $string .= $this->renderer->widget($view['date'], ['type' => 'hidden']);
438 12
            $string .= $this->renderer->widget($view['input'], ['attr' => ['class' => 'jsdate']]);
439 12
            if (isset($view['time'])) {
440 1
                $string .= ' ' . $this->renderer->widget($view['time']);
441
            }
442 12
            $string .= $data['jsinit'];
443
        }
444 12
        return $string . '</fieldset>';
445
    }
446
447 4
    public function image_widget(FormView $view, array $data)
448
    {
449 4
        $string = '<div ' . $this->renderer->block($view, 'widget_container_attributes') . '>';
450 4
        $string .= '<table class="midcom_datamanager_table_photo"><tr><td>';
451 4
        $preview = null;
452 4
        $objects = $data['value']['objects'] ?? [];
453 4
        foreach ($objects as $identifier => $info) {
454
            $preview = $info;
455
            if ($identifier == 'thumbnail') {
456
                break;
457
            }
458
        }
459 4
        if (!empty($preview)) {
460
            if ($preview['id'] === 0) {
461
                $preview['url'] = \midcom_connection::get_url('self') . 'midcom-exec-midcom.datamanager/preview-tmpfile.php?identifier=' . substr($preview['identifier'], strlen('tmpfile-'));
462
            }
463
464
            $string .= '<img src="' . $preview['url'] . '" class="preview-image">';
465
        }
466 4
        $string .= '</td><td>';
467
468 4
        if (!empty($objects)) {
469
            $string .= '<label class="midcom_datamanager_photo_label">' . $this->renderer->humanize('delete photo') . ' ' . $this->renderer->widget($data['form']['delete']) . '</label>';
470
            $string .= '<ul>';
471
            foreach ($objects as $identifier => $info) {
472
                if (   $info['size_x']
473
                    && $info['size_y']) {
474
                    $size = "{$info['size_x']}&times;{$info['size_y']}";
475
                } else {
476
                    $size = 'unknown';
477
                }
478
                $string .= "<li title=\"{$info['guid']}\">{$size}: <a href='{$info['url']}' target='_new'>{$info['formattedsize']}</a></li>";
479
            }
480
            $string .= '</ul>';
481
        }
482 4
        $string .= $this->renderer->errors($data['form']['file']);
483 4
        $string .= $this->renderer->widget($data['form']['file']);
484
485 4
        if (array_key_exists('title', $view->children)) {
486 1
            $string .= $this->renderer->widget($view->children['title'], ['attr' => ['placeholder' => $this->renderer->humanize('title')]]);
487
        }
488 4
        if (array_key_exists('description', $view->children)) {
489
            $string .= $this->renderer->widget($view->children['description'], ['attr' => ['placeholder' => $this->renderer->humanize('description')]]);
490
        }
491 4
        if (array_key_exists('score', $view->children)) {
492
            $string .= $this->renderer->widget($view->children['score']);
493
        }
494 4
        $string .= '</td></tr></table></div>';
495 4
        $string .= $this->renderer->row($data['form']['identifier']);
496
497 4
        return $string . $this->jsinit('init_image_widget("' . $view->vars['id'] .'");');
498
    }
499
500 5
    public function subform_widget(FormView $view, array $data)
501
    {
502 5
        $data['attr']['data-prototype'] = $this->escape($this->renderer->row($view->vars['prototype']));
503 5
        $data['attr']['data-max-count'] = $view->vars['max_count'];
504 5
        $string = $this->renderer->widget($data['form'], $data);
505 5
        return $string . $this->jsinit('init_subform("' . $view->vars['id'] . '", ' . $view->vars['sortable'] . ');');
506
    }
507
508 48
    public function submit_widget(FormView $view, array $data)
509
    {
510 48
        $data['type'] = $data['type'] ?? 'submit';
511 48
        return $this->renderer->block($view, 'button_widget', $data);
512
    }
513
514
    public function delete_widget(FormView $view, array $data)
515
    {
516
        $data['type'] = $data['type'] ?? 'delete';
517
        return $this->renderer->block($view, 'button_widget', $data);
518
    }
519
520 21
    public function textarea_widget(FormView $view, array $data)
521
    {
522 21
        if ($view->vars['readonly']) {
523 1
            $view->vars['output_mode'] = 'nl2br';
524 1
            $string = $this->get_view_renderer()->text_widget($view, $data);
525 1
            return $string . $this->renderer->block($view, 'form_widget_simple', ['type' => "hidden"]);
526
        }
527 20
        $data['attr']['class'] = 'longtext';
528 20
        $data['attr']['cols'] = 50;
529 20
        return '<textarea ' . $this->renderer->block($view, 'widget_attributes', $data) . '>' . $data['value'] . '</textarea>';
530
    }
531
532 11
    public function markdown_widget(FormView $view, array $data)
533
    {
534 11
        $data['required'] = false;
535 11
        $string = '<textarea ' . $this->renderer->block($view, 'widget_attributes', $data) . '>' . $data['value'] . '</textarea>';
536 11
        return $string . $this->jsinit('var simplemde = new SimpleMDE({ element: document.getElementById("' . $view->vars['id'] . '"), status: false });');
537
    }
538
539 6
    public function tinymce_widget(FormView $view, array $data)
540
    {
541 6
        if ($view->vars['readonly']) {
542
            $string = $this->get_view_renderer()->text_widget($view, $data);
543
            $data['type'] = 'hidden';
544
            return $string . $this->renderer->block($view, 'form_widget_simple', $data);
545
        }
546
        // we set required to false, because tinymce doesn't play well with html5 validation..
547 6
        $data['required'] = false;
548 6
        $string = '<textarea ' . $this->renderer->block($view, 'widget_attributes', $data) . '>' . $data['value'] . '</textarea>';
549 6
        return $string . $this->jsinit($data['tinymce_snippet']);
550
    }
551
552 47
    public function form_label(FormView $view, array $data)
553
    {
554 47
        if ($data['label'] === false) {
555
            return '';
556
        }
557 47
        if (!$data['label']) {
558 5
            $data['label'] = $data['name'];
559
        }
560 47
        $data['label'] = $this->renderer->humanize($data['label']);
561
562 47
        $label_attr = $data['label_attr'];
563 47
        if ($data['required'] && !$view->vars['readonly']) {
564 29
            $label_attr['class'] = trim(($label_attr['class'] ?? '') . ' required');
565 29
            $data['label'] .= ' <span class="field_required_start">*</span>';
566
        }
567 47
        if (!$data['compound']) {
568 47
            $label_attr['for'] = $data['id'];
569
        }
570 47
        return '<label ' . $this->attributes($label_attr) . '><span class="field_text">' . $data['label'] . '</span></label>';
571
    }
572
}
573